Design decisions

MySQL front-end

Decisions about the MySQL connector architecture, accounts, SELECT, ALTER TABLE, transactions, indexed reads, functions and foreign keys (D52, D54 to D61, D64).

D52 MySQL compatibility is a connector, one crate per database; the core gets only what it lacks#

The direction was MySQL first, because it is the most used, and then other databases being "thin". The MySQL work lives in a separate crate and program, raftdb-mysql, which speaks the MySQL wire protocol so unmodified drivers, ORMs and tools connect, and translates SQL into requests to Raft DB's HTTP JSON API. The engine crates do not depend on it, and its modules (wire, auth, sql, expr, Raft DB client, session) are the seams for the next dialect. Only features the core database lacks are added to the core.

D53 Fatal-error reporting is in Operations and tooling.

D54 MySQL accounts and privileges#

The connector has MySQL's account model. Accounts from its configuration are bootstrap administrators; every other account is a document in a hidden Raft DB database, holding double hashes and grants, never the password. CREATE USER, ALTER USER, DROP USER, RENAME USER, SET PASSWORD, GRANT, REVOKE and SHOW GRANTS work at global, database, table and column level, and a client logs in as the stored account whose host pattern matches most specifically.

D55 MySQL level 3a: the general SELECT#

One executor runs every SELECT: inner, left, right and cross joins, derived tables, grouping and aggregates, HAVING, DISTINCT, ORDER BY, LIMIT, UNION, and scalar, IN and EXISTS subqueries (correlated or not), ONLY_FULL_GROUP_BY with MySQL's error words, and locking clauses that are accepted although there are no concurrent transactions to lock against. Tables a statement names are read first, with the part of the WHERE that can be pushed to Raft DB.

D56 MySQL level 3b: ALTER TABLE, multi-table UPDATE and DELETE, INSERT ... SELECT#

ALTER TABLE supports adding, dropping, modifying, changing and renaming columns and indexes, primary key changes, RENAME TO, AUTO_INCREMENT, and options that change nothing here, several changes in one statement. The changes are checked in order against a copy of the definition, so a mistake changes nothing, with MySQL's error numbers; rows are rewritten only when needed, all new documents computed before the first write.

D57 MySQL level 4a: transactions that are atomic, not isolated#

START TRANSACTION, COMMIT, ROLLBACK, savepoints, autocommit and the implicit commit of definition statements behave as in MySQL. Every write already leaves undo records so a failing statement is all-or-nothing; inside a transaction they are kept in the session's log and replayed backwards on rollback. The log states what it is not: there is no isolation, other sessions see an open transaction's writes at once, and @@transaction_isolation reports READ-UNCOMMITTED, the honest level.

D58 MySQL: reads use Raft DB's indexes; DECIMAL up to 65 digits, ENUM, SET, BLOB, BINARY#

The simple parts of a WHERE (column op constant, IN, BETWEEN, joined by AND) become a filter that Raft DB runs next to the data with its indexes, so the connector receives only rows that can match. The filter is always a superset and the connector re-checks the whole WHERE, because Raft DB compares text by bytes and the front-end ignores case. Short text columns are matched through a lower-case shadow field. Joins push the key values of earlier tables. The same decision adds the column types named in its title.

D59 MySQL: the function library, REGEXP, CAST, INTERVAL, IS TRUE#

The evaluator gained what WordPress and PrestaShop send: CAST and CONVERT, date and time, numeric and string functions, bit operations, INTERVAL arithmetic, IS TRUE, and REGEXP through the project's own backtracking matcher with no dependency.

D60 Each front-end shows only its own databases#

A client of the MySQL front-end sees only databases made by it. A database is marked by a definition table made at CREATE DATABASE, and databases without it (made through the JSON or binary APIs or by another dialect's front-end) are treated as not there. A name is still one namespace in Raft DB, so creating a database whose name a foreign database holds fails. The same decision keeps prefix-index lengths in the table definition and records a comparison of WordPress against real MySQL.

D61 MySQL: what applications and tools asked for, gaps closed against real MySQL 9.7#

Running PrestaShop's installer and shop (and SQLyog by hand) against the connector and against a real MySQL showed differences, and each was fixed: bit operators, non-strict sql_mode with warnings, SET var = (SELECT ...), an auto-increment column leading a composite key, reserved words after a dot, NATURAL joins, SHOW statements the tools use, and more. The method (compare against MySQL, fix every difference) is the decision.

D64 MySQL: foreign keys with enforcement, BIT, fractional seconds, DISABLE KEYS#

A 15 MB application dump of 130 tables failed to load with errors of five kinds, and all five were removed, each against real MySQL 9.7. Foreign keys are kept in the table definition and enforced: a child row must refer to an existing parent row, RESTRICT and NO ACTION refuse a parent change, CASCADE follows to referring rows and SET NULL clears them. BIT, fractional seconds and DISABLE KEYS are added, and the dump loads and round-trips.