Skip to content

Tracking: remaining dialect hooks needed to drop our downstream fork #419

Backlog

Description

@alexskinner

Thanks for #418, and for taking all four review points before merging it. It removed the function-lookup override we were carrying: our downstream MySQL-compatible dialect crate now builds against main (522eb00) with its fixed-arity functions resolved by implicit cast, and 13 tests that were skipped now pass.

This issue lists everything we still carry in a downstream fork, so you can see the whole picture in one place rather than one PR at a time. For each item: what it does, why a MySQL-compatible dialect needs it, and the smallest extension point we think would cover it. The aim throughout is a hook on SqlDialect (or Storage, or the function traits) with a default that keeps today's behaviour, so the core stays dialect-neutral and the MySQL rules live in the downstream crate. These are suggestions, not designs we are attached to. Where you would rather solve something differently, or not in core at all, that is useful to know too.

Everything below was checked against main at 522eb00. Things that are already upstream, or that a dialect can now do inside SqlDialect::parse since #410 (splitting multi-table DROP, inline INDEX definitions, comma-style UPDATE t, s, rewriting LIKE without ILIKE), are left out.

Summary

# Area Item Kind Size
1 Functions Variadic / any-argument scalar functions ScalarFunctionImpl default methods S
2 Generic fix TRIM(NULL FROM s) returns s bug fix XS
3 Generic fix CAST('1.235' AS DECIMAL(10,2)) keeps scale 3 bug fix XS
4 Generic fix GROUP_CONCAT ORDER BY / SEPARATOR silently ignored AST + binder S
5 Generic fix Joined UPDATE cannot read joined columns in SET binder S
6 Generic fix GROUP BY on a primary key does not cover the other columns binder S
7 Ordering Default NULL order per dialect SqlDialect hook S
8 Typing Arithmetic and AVG result types SqlDialect hooks M
9 Transactions Statement-level atomicity inside a transaction core behaviour M
10 Diagnostics Warnings channel and per-statement evaluation policy new small module + hooks M
11 DDL Identity / auto-increment columns AST + catalog M
12 DML Upsert (ON DUPLICATE KEY UPDATE) your call after #408 M
13 Catalog Declared column type text for introspection AST + catalog M
14 Text Collation for comparisons and keys SqlDialect hook L
15 Storage SlateDB flush interval and group commit #414 open
16 Functions User-defined aggregates (optional) registry M

Functions

1. Variadic / any-argument scalar functions. GREATEST, LEAST, open-ended CONCAT, CONCAT_WS, FIELD and similar take any number of arguments of mixed types, and their result type follows the arguments (GREATEST(int, double) is a double, GREATEST(date, datetime) a datetime). #418 resolves fixed arities only, so today we register CONCAT for 1..=8 arguments and cannot express GREATEST/LEAST at all. Suggested hook: three default methods on ScalarFunctionImpl, accepts_any_args(), accepts_arity(n) and return_type_for(&[LogicalType]). Declared overloads are always tried first, so existing functions are unaffected; an any-argument function is only the fallback for its name, and its arguments are passed uncast. The same fallback would also cover numeric arguments to string functions (CONCAT('a', 1), LENGTH(int_col)) on the downstream side, without adding a numeric to VARCHAR implicit cast to core. Follow-up to #412 / #418. PR to follow, linked here.

Generic fixes (not dialect-specific)

2. TRIM(NULL FROM 'abc') returns 'abc'. It should be NULL in standard SQL, MySQL, PostgreSQL and SQLite. A one-line fix plus a test.

3. String to DECIMAL(p,s) casts ignore the target scale. CAST('1.235' AS DECIMAL(10,2)) returns 1.235, while CAST(1.235 AS DECIMAL(10,2)) already returns 1.24. The fix is to round the string path to the declared scale as the numeric path does.

4. GROUP_CONCAT(a ORDER BY b SEPARATOR '|') is accepted but the clauses are dropped. The query runs and returns the default order and ,, which is easy to miss. Options: carry order_by and separator on the AST Function and honour them in the aggregate, or reject the clauses in the parser until they are supported. Multiple value arguments (GROUP_CONCAT(a, b)) are a smaller follow-on.

5. Joined UPDATE cannot read the joined table in SET. UPDATE t JOIN s ON t.id = s.id SET b = s.x fails with "joined UPDATE SET expressions can only reference target table columns". Copying values from a joined table is the main reason to write a joined update (PostgreSQL's UPDATE .. FROM is the same idea), and the rows written still belong to the target table only.

6. Columns functionally dependent on a GROUP BY primary key. SELECT id, a FROM t GROUP BY id with id as the primary key is valid in SQL:2003, MySQL and PostgreSQL, but is rejected today. The binder would treat the other columns of that table as grouped when the whole primary key is in GROUP BY.

Ordering and typing

7. Default NULL order. When an ORDER BY key has no NULLS FIRST/LAST, NULLs sort last in both directions. MySQL and SQLite put them first ascending and last descending; PostgreSQL does the reverse. Suggested hook: SqlDialect::nulls_first(asc: bool) -> bool, defaulting to today's behaviour. A dialect can already approximate this in parse by writing an explicit nulls_first on every key, so this is low priority; the hook would mainly keep that out of every dialect and let the built-in SQLite dialect match SQLite.

8. Arithmetic and AVG result types. MySQL computes + - * / % on exact values in DECIMAL with fixed scale rules (7 / 2 = 3.5000, 0.1 + 0.2 = 0.3 exactly) and types AVG over integers and decimals as DECIMAL. Today 1/3 is 0, 0.1 + 0.2 is a double, and AVG(int) is a double. Exact literals can already be produced in parse as a CAST to DECIMAL(p,s), so only two hooks are needed: arithmetic_return_type(op, left, right) -> Option<LogicalType> and avg_return_type(arg) -> Option<LogicalType>. None keeps the engine's type; when a hook returns DECIMAL, the operation is computed in DECIMAL and rounded to that scale.

Transactions and diagnostics

9. Statement-level atomicity inside a transaction. Session documents that a failed statement leaves the transaction open with whatever it wrote, so a multi-row INSERT that fails on its third row keeps the first two. MySQL, PostgreSQL (with savepoints) and SQLite undo just that statement. Our fork keeps a small per-statement undo log for explicit transactions only (autocommit is already atomic), replayed in reverse when the statement fails. Options: that undo log, or a statement savepoint on the storage transaction if you prefer to build it there. It is generic, not MySQL-specific.

10. Warnings and evaluation policy. MySQL turns some errors into warnings depending on the mode: division by zero gives NULL plus warning 1365, and a malformed numeric string in an expression is truncated with a warning. Suggested shape: a statement-scoped list of diagnostics (Database::take_diagnostics() after a statement), a SqlDialect::statement_policy(&Statement) returning which cases are warnings rather than errors (the default keeps every case an error), and SqlDialect::map_diagnostic so the dialect can attach its own codes and wording. Nothing changes for a dialect that does not opt in.

DDL and catalog

11. Identity / auto-increment columns. AUTO_INCREMENT, SERIAL and LAST_INSERT_ID() need a column that generates the next value when the insert gives NULL (or, in MySQL, 0), with the counter kept in the catalog so it survives restarts and does not reuse values. Suggested shape: a generic identity column option on ColumnDef (a dialect maps AUTO_INCREMENT or GENERATED .. AS IDENTITY to it), the last generated value exposed per session, and SqlDialect::identity_zero_generates() -> bool for the MySQL zero rule.

12. Upsert. You closed #408 because it added too much to Insert::next_tuple, and said you would reimplement it or provide a way for users to build it themselves. Whichever you prefer works for us. The parts the dialect needs are: on a unique or primary key conflict, update the existing row with expressions that can read the incoming row; and the affected-rows count, which MySQL reports as 1 for an insert, 2 for a changed row and 0 for an unchanged one (a SqlDialect::upsert_affected_rows(inserted, updated) -> u64 hook, defaulting to 1). A generic ON CONFLICT (..) DO UPDATE that the MySQL dialect maps onto would suit us, and the SQLite dialect could use it too.

13. Declared column type text. ColumnDef.data_type is a LogicalType, so TINYTEXT, BIT(1), SERIAL or INT(11) come back from DESCRIBE as the mapped engine type. Clients that introspect the schema (ORMs, migration tools) compare against the declared type. Suggested shape: an optional display string on the column, set by the dialect in parse and stored with the column, without affecting typing.

Text

14. Collation. MySQL's default collation compares text case- and accent-insensitively ('a' = 'A', 'e' = 'e-acute'), and that has to hold for =, ORDER BY, GROUP BY, DISTINCT and unique keys, not just in expressions. A rewrite to LOWER() cannot reach keys. Our fork's approach: SqlDialect::text_collation() -> Option<TextCollation>, where TextCollation maps a string to a sort key that is stored in primary keys and indexes, plus is_binary_collation(name) for columns declared case-sensitive. Tables record the collation they were created with. This is the largest item and probably wants a design discussion before any code; we would suggest leaving it until last.

Storage

15. SlateDB flush interval and group commit. Already open as #414, with the measurements in the thread. We are happy to adapt it (for example to a lock-free deferred commit) whenever you have time.

Optional

16. User-defined aggregates. Scalar and table functions can be registered from outside; aggregates cannot. Our fork has a small aggregate registry with an accumulator trait. Nothing we ship depends on it today, so it is listed only for completeness.

Proposed order

We would send these one at a time, smallest and least controversial first, and adapt each one to your feedback before starting the next:

  1. Variadic / any-argument scalar functions (1)
  2. TRIM with a NULL trim character (2) and string to DECIMAL scale (3)
  3. GROUP_CONCAT ORDER BY / SEPARATOR (4)
  4. Joined UPDATE reading joined columns (5)
  5. Functional dependency on a GROUP BY primary key (6)
  6. Default NULL order hook (7)
  7. Arithmetic and AVG typing hooks (8)
  8. Statement-level atomicity (9)
  9. Warnings and evaluation policy (10)
  10. Identity columns (11)
  11. Declared column type text (13)
  12. Upsert (12), in whatever form you choose
  13. Collation (14), after a design discussion
  14. feat: add configurable SlateDB flush interval and group commit hook #414 whenever suits you, and aggregates (16) only if they are wanted

If you would rather some of these stay downstream, or would like a different order, just say and we will adjust. No rush on any of it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions