Slide 1

Slide 1 text

Rails 6 MySQLͷutf8mb4 ରԠͱ͸ԿͰ͋ͬͯԿͰ͸ ͳ͍ͷ͔ RejectKaigi 2019 @yahonda

Slide 2

Slide 2 text

Rails, not Ruby?

Slide 3

Slide 3 text

"Your proposal for RailsConf 2019 has not been accepted"

Slide 4

Slide 4 text

Rails 6 RC1 is coming

Slide 5

Slide 5 text

utf8mb4ͰͰ͖Δ͜ͱ

Slide 6

Slide 6 text

Emoji

Slide 7

Slide 7 text

[Railsdm 2018: Day3 ಛผߨԋ] Rails 6 ʹ޲͚ ͨ ActiveRecord ͷվળ

Slide 8

Slide 8 text

yahonda “MySQLͷDEFAULT CHARACTER SETΛɺutf8mb4 ʹ͢Δͷ͸͍͍ΞΠσΟΞͩͱ ࢥΘΕ·͢Ͱ͠ΐ͏͔ɻ"

Slide 9

Slide 9 text

kamipo “(σϑΥϧτΛutf8mb4ʹ͢Δͷ ͸)͜Ε͸ݫ͍͠" "key prefix lengthͷ໰୊ΛϢʔβʔʹԡ ͚͍͍ͭͯ͠ΜͩͬͨΒ(utf8mb4͕)σ ϑΥϧτʹͳΔ(Մೳੑ͕͋Δ)"

Slide 10

Slide 10 text

"MySQL schema/ migration should default to CHARSET=utf8mb4” by DHH rails/rails#33596

Slide 11

Slide 11 text

"Use utf8mb4 character set by default for MySQL database #33608” by yahonda rails/rails#33608

Slide 12

Slide 12 text

Key prefix lengthͷ໰୊ͱ͸ • "ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes" • Rails string type is mapped to MySQL varchar(255) • 255(characters) x 4(bytes) = 1020 > 767

Slide 13

Slide 13 text

Key prefix length໰୊͸ Ͳ͏΍ͬͯղܾ͞Ε͔ͨ

Slide 14

Slide 14 text

5.7 and 8.0 • innodb_default_row_format ͕༗ޮͳͷͰͦͷ··

Slide 15

Slide 15 text

5.5 and 5.6 • Add ROW_FORMAT=DYNAMIC option if innodb_file_per_table = 1 AND innodb_file_format = 'Barracuda' • https://github.com/rails/rails/pull/34742

Slide 16

Slide 16 text

Priority • ࠷༏ઌ • database.yml default value: encoding: utf8mb4 • σϑΥϧτͷdatabase.ymlΛฤूͨ͠৔߹ • options[:collation] • options[:charset] (options[:encoding] ͱಉ͡ҙຯ) • optionsͷࢦఆ͕ͳ͍ & MySQL 5.7.9Ҏ্ • utf8mb4 • optionsͷࢦఆ͕ͳ͍ & MySQL 5.6ҎԼ • "Configure a supported :charset and ensure innodb prefix is enabled to support indexes on varchar(255) string columns."

Slide 17

Slide 17 text

What about collation?

Slide 18

Slide 18 text

Rails 6 does not have any “default collation”

Slide 19

Slide 19 text

https://github.com/ rails/rails/issues/ 33596

Slide 20

Slide 20 text

Since proper collation is language dependent (that is the reason that Unicode provide multi level comparison), I personally would not like to provide any collation by default.

Slide 21

Slide 21 text

I basically answer "Please consider using default collation (utf8mb4_general_ci in MySQL 5.7 case). If it has any issue for your use case (Sushi-Beer issue, etc), using utf8mb4_bin might avoid that issue.".

Slide 22

Slide 22 text

Enjoy Rails 6!