In our latest article at Database Journal we talk about Character Sets in MySQL. What are they? How do they affect searching? How do they affect data that is inserted or updated? How can I set and control the for an application or globally in my database? And what pre-tell is collation? We answer all these questions and more.
We have written before about the importance of using numeric types as keys, but maybe you've inherited a schema that you can't change or have chosen string types as keys for a specific reason. Either way, the character sets used on joined columns can have a significant impact on the performance of your queries.
Take the following example, using the InnoDB storage engine:
PLAIN TEXT SQL:
- CREATE TABLE `t1` (
- `char_id` char(6) NOT NULL,
- `v` varchar(128) NOT NULL,
- PRIMARY KEY (`char_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- CREATE TABLE `t2` (
- `id` int UNSIGNED NOT NULL AUTO_INCREMENT, …