Design decisions

MariaDB and dialects

Decisions that made the front-end program answer as MySQL or as MariaDB, and the compatibility steps that followed (D79 to D88).

D79 One front-end program, two dialects: MySQL and MariaDB#

It was requested that Raft DB accept and process statements like MySQL and MariaDB. The raftdb-mysql program answers as MySQL 8 or as MariaDB 11 by the dialect setting; one process is one dialect, and a MariaDB endpoint is another process on another port, as a MariaDB server is another server. What depends on the dialect is gathered in one module: version string, default authentication plugin, default sql_mode, default collation, handshake collation byte, and the table that marks a database as the front-end's, so each front-end lists only the databases it made.

D80 MariaDB program, first results: connectors, error wording, big integers, exact decimals#

MariaDB Connector/J connects to Raft DB as MariaDB and runs a probe covering DDL, prepared statements, transactions and metadata. It needed character sets inside SET lists, character set introducers such as _binary, and the binary character set for binary column types. Error wording differs by dialect (for example Unknown column 'x' in 'SELECT' for MariaDB where MySQL says field list), and big integers and exact decimals were aligned with MySQL and MariaDB.

D81 MariaDB program, second step: system variables, SQL-level PREPARE, OR REPLACE, RETURNING, sequences, expression defaults#

Every system variable of MySQL and MariaDB, with its default, is built into the front-end from files generated from MySQL and MariaDB servers, so a session starts with them. SET GLOBAL is kept for the whole front-end. SQL-level PREPARE, EXECUTE and DEALLOCATE, and MariaDB's EXECUTE IMMEDIATE, are added, together with CREATE OR REPLACE, IF [NOT] EXISTS forms, RETURNING, sequences and expression defaults.

D82 MariaDB program, third step: type names, UUID / INET4 / INET6, more functions, JSON functions, more aggregates#

MariaDB's alternative type names are read as the type they stand for, SERIAL is its defined expansion, and UUID, INET4 and INET6 are real types that keep one canonical form and refuse malformed values. About 60 more functions, the JSON functions and more aggregates are added. Not done, as the log lists: ZEROFILL (accepted, ignored), VECTOR, ROW, TYPE OF.

D83 Table maintenance statements and the regular-expression functions#

ANALYZE, OPTIMIZE, CHECK and REPAIR TABLE answer as a healthy InnoDB table does. The regular-expression matcher now numbers groups and supports back-references, look-ahead and look-behind, and REGEXP_REPLACE, REGEXP_SUBSTR and REGEXP_INSTR follow each dialect's own forms. Each is checked by a script that gives identical results on MySQL and MariaDB.

D84 GROUP BY ... WITH ROLLUP, the JSON operators -> and ->> and MEMBER OF#

WITH ROLLUP adds totals rows after each leading part of the grouping key and a grand total, with the differences between the dialects kept (MariaDB refuses ORDER BY with it; MySQL allows it). The JSON operators and MEMBER OF are MySQL-only. Still missing, per the log: GROUPING(), CUBE, JSON_TABLE, JSON_PRETTY, JSON_OBJECTAGG.

D85 Row comparisons, ANY / SOME / ALL, standard SUBSTRING and FETCH forms, X'..', names that start with digits#

A statement-level coverage run against MariaDB's documentation showed hundreds of refused statements. The parser now turns row constructors into the comparisons of their parts, handles ANY, SOME and ALL subqueries with three-valued logic, and accepts the standard SUBSTRING ... FROM ... FOR form, INTERVAL(), hexadecimal literals, VALUES lists and more.

D86 The old gaps: any table name, MySQL's JSON error words, real character sets and collations, a stale table binding#

A database or table may be called anything MySQL allows (spaces, accents, $, up to 64 characters), because Raft DB stores such a name in an encoded form; only the connector's own hidden tables are refused as user names. Bad JSON gets MySQL's error words and position, the real lists of character sets and collations are used, and a stale table binding was fixed.

D87 Stored procedures and functions, several result sets in one answer#

A reply can now carry several answers one after another, flagged with "more results", in the text and the binary protocol. Procedures and functions are stored as documents in a hidden table of the database, parsed when made and each time they run, and include BEGIN ... END blocks with labels. Their definitions can be listed through SHOW statements and information_schema.ROUTINES.

D88 Triggers#

CREATE TRIGGER with BEFORE or AFTER and INSERT, UPDATE or DELETE, FOR EACH ROW, FOLLOWS and PRECEDES, plus DROP TRIGGER, SHOW CREATE TRIGGER, SHOW TRIGGERS and information_schema.TRIGGERS. Definitions are documents of a hidden table and go with the table when it is dropped.

D100 Temporal tables: system versioning and application-time periods#

MariaDB keeps the past of a table in two ways, and the MariaDB dialect has both (MySQL has neither, so the syntax stays an error there). A system-versioned table keeps only its current rows, with two TIMESTAMP(6) columns row_start and row_end; every UPDATE, DELETE, REPLACE and ON DUPLICATE KEY UPDATE first copies the old row, ended at the statement's time, into a hidden table of the same database (__h_<table>: the same columns, a hidden row id, no key). A plain query reads the table as before and costs nothing more; FOR SYSTEM_TIME is rewritten into a union of the table and its history filtered by the two columns. The copies are undo records of the statement, so a failed statement, a rollback and a savepoint take history back with the change. The statement time has microseconds and is fixed for a session with SET timestamp, which also makes the tests repeatable. Application-time periods are two date columns marked PERIOD FOR p, checked start < end; FOR PORTION OF changes the part of a row inside a range and leaves the rest as new rows; a key WITHOUT OVERLAPS compares periods instead of values (and, unlike an ordinary unique key, keeps no claim, so two sessions racing can both succeed). Five test scripts are identical to a real MariaDB 11.4; what stays different (the transaction-id form, partition rotation, a DELETE HISTORY privilege of its own) is listed in D100 and on the temporal tables page. The body is the language of routines (D87); NEW.col and OLD.col are the trigger's variables, and SET NEW.col in a BEFORE trigger changes the row. Triggers run for INSERT, UPDATE, DELETE, REPLACE and INSERT ... ON DUPLICATE KEY UPDATE.