Collation and case sensitivity
Raft DB compares text without regard to case, like the default collation of both servers; the collations and character sets it lists, and what COLLATE does and does not do.
How text is compared#
Every text in Raft DB is utf8mb4. The default collation of the MySQL dialect is utf8mb4_0900_ai_ci and of the MariaDB dialect utf8mb4_uca1400_ai_ci (the connection collation utf8mb4_general_ci). Both are case-insensitive, and Raft DB's evaluator has one comparison of text: without regard to case.
This holds everywhere a text is compared:
| Place | Case-insensitive |
|---|---|
=, <>, <, >, <=, >=, <=>, BETWEEN, IN | yes |
ORDER BY, MIN, MAX, GREATEST, LEAST, STRCMP | yes |
GROUP BY, DISTINCT, unique keys and primary keys | yes: 'Apple' and 'APPLE' are the same key (a second insert fails with error 1062) |
LIKE, REGEXP, FIELD, FIND_IN_SET, INSTR, LOCATE | yes |
REPLACE | no: it is case-sensitive, as in MySQL |
| Column names | yes |
| Database and table names | no: they are looked up as written (see Identifiers) |
For example SELECT w FROM words WHERE w = 'APPLE' finds Apple, 'a' = 'A' is 1, and inserting 'APPLE' after 'Apple' into a primary key column fails.
The order is that of the code points of the lower-cased text, not the order of the collation's tables: letters with accents sort after z, and the language rules of utf8mb4_0900_ai_ci are not applied.
The comparison is by case, not by accent: the ai in the collation name (accent-insensitive) is not implemented: 'e' = 'é' is 0.
COLLATE#
expr COLLATE collation_name
col VARCHAR(10) COLLATE utf8mb4_general_ci- A case-insensitive collation after an expression, a column type or
CREATE TABLE ... COLLATEis read and changes nothing. - A binary or case-sensitive collation (a name that ends in
_binor_cs, orbinary) in an expression is refused as not supported, rather than silently ignored. CHARACTER SET x,CHARSET xandCOLLATE xafter a text column type are accepted and ignored.BINARY expris accepted and ignored; the comparison stays case-insensitive. (Real MySQL gives 0 forBINARY 'a' = 'A'.)SHOW CREATE TABLEshows the default collation of the dialect.
Character sets and collations#
SHOW CHARACTER SET [LIKE 'pattern' | WHERE expr];
SHOW COLLATION [LIKE 'pattern' | WHERE expr];
SELECT ... FROM information_schema.CHARACTER_SETS;
SELECT ... FROM information_schema.COLLATIONS;They answer with the real lists of each server: 41 character sets and 286 collations for MySQL 9.7, 40 and 550 for MariaDB 11.4 (made from MySQL and MariaDB servers). The lists show what the servers have; Raft DB stores and compares text as utf8mb4 whatever the list says. The output is identical to both servers.
SHOW CHARACTER SET WHERE Charset = 'latin1';
SHOW COLLATION LIKE 'utf8mb4_unicode%';
SELECT CHARACTER_SET_NAME, DEFAULT_COLLATE_NAME, MAXLEN FROM information_schema.CHARACTER_SETS WHERE CHARACTER_SET_NAME IN ('utf8mb4', 'latin1', 'binary');Remarks#
CHARSET(x)andCOLLATION(x)reportutf8mb4and the dialect's connection collation for text andbinaryfor other values.- Indexes on text. An index of a
CHAR/VARCHARcolumn up to 255 characters uses a shadow field that holds the value in lower case, so an index lookup agrees with the case-insensitive comparison. - Not supported yet: case-sensitive and accent-sensitive comparison, per-column collations that change the comparison.
expr COLLATE x_bin(or_cs,binary) compares, orders (ORDER BY), groups (GROUP BY) and de-duplicates (DISTINCT) by bytes.WEIGHT_STRING(x [AS CHAR(n) | AS BINARY(n)])works for printable ASCII in MySQL and for any text in MariaDB (LEVEL ...is MariaDB's).