Repository navigation
Description
Summary
I'd like to propose a small, generic extension point in KiteSQL that lets a separate crate supply SQL dialect behaviour (parsing, type mapping, coercion rules and so on). Core then stays dialect-neutral, and its default behaviour doesn't change.
I've built this on my fork (alexskinner/KiteSQL) and used it to implement a MySQL dialect as a separate crate, KiteSQL-MySQL. I'm not proposing that crate for upstream. The only things I'd like to upstream are the generic hooks it needs.
What has already landed
Thanks to @kould for #402, which cherry-picked the SQL correctness fixes from the fork review into main (ungrouped-column rejection, composite UNIQUE with SQLite NULL semantics, UPDATE null validation and duplicate INSERT targets, UTF-8 SUBSTRING/POSITION, defaults after PRIMARY KEY, function defaults on reload, ANALYZE on small histograms, and rejecting unsupported INSERT clauses), and for the 0.7.1 release. I'm merging main (0.7.1) back into the fork, so none of that needs to be proposed again. What's left is the dialect extension point itself.
Motivation
I'm embedding KiteSQL behind an application layer that expects MySQL-style SQL. Without hooks, the only options are a hard fork or dialect-specific branches throughout core. Neither is good for KiteSQL. A dialect trait keeps those rules out of core, and other dialects (PostgreSQL-flavoured, SQLite-flavoured) could use the same route.
Proposed design
- A
SqlDialecttrait insrc/dialect/mod.rs. Every method has a default that reproduces current KiteSQL behaviour exactly, soGenericSqlDialectis a no-op. - A
DialectRegistryheld by the database, withregister,set_defaultandget. Generic is the default. - Hook methods are added only where a real dialect needed them. The first PR adds just the basics:
nameandparser_dialectrewrite, an AST rewrite pass run on each parsed statement before bindingmap_data_type(types in expressions such asCAST) andmap_column_type(types in column definitions)
- Later PRs would add, one concern each: comparison coercion and boolean-text rules;
ON DUPLICATE KEY UPDATEgating and affected-rows counting; transaction-semantics hooks (whetherBEGINcommits an open transaction,SET autocommit); and index prefix lengths. - Core tests use only the generic dialect plus small test-only dialects that switch individual hooks on. Core has no dependency on any real dialect crate.
Compatibility
- No behaviour change for existing users. The existing suite (unit tests, sqllogictest, the SQLite corpus) passes unchanged with the generic dialect.
- No new dependencies.
Proposed PR sequence
- The
SqlDialecttrait andDialectRegistry, with generic defaults - Comparison coercion and boolean-text hooks
ON DUPLICATE KEY UPDATEgating and the affected-rows hook- Transaction-semantics hooks
- The index prefix-length hook
I also have a couple of small fixes for panics the fuzz job found, which I'll send separately once they're ready.
Each PR will link back here. I'm happy to change the shape, naming or order based on your feedback before going further, and if you'd prefer a different approach entirely, let me know.
Activity
KKould commentedon Nov 21, 2026
I’m very glad to see your work on multi-dialect compatibility for KiteSQL; in fact, I had already noticed your fork and incorporated some of your bug fixes into version 0.7.1.
Ensuring broad compatibility with various SQL dialects—as well as with different parsers themselves—is a crucial undertaking. In my previous performance comparison between KiteSQL and SQLite, I discovered that the
sqlparser-rslibrary currently in use performs significantly worse than SQLite. Consequently, I had intended to explore support for multiple parsers, with plans to integratelemon-rsas an additional option. I am very glad to see that you have taken on this work.alexskinner commentedon Nov 21, 2026
Thanks a lot for the kind words, and for pulling those fixes into 0.7.1 already. Good to hear the fork was useful.
Multi-parser support sounds great to me. I'd be glad to see lemon-rs next to sqlparser-rs, especially given the gap you measured against SQLite. I'd like the dialect work to make that easier. Right now a dialect hands back a sqlparser dialect, so that part is tied to sqlparser-rs. I'm happy to move parser choice behind the dialect, so each dialect says which frontend it parses with and the rest of the engine doesn't care. If you have a rough idea of how you'd like the lemon-rs frontend to plug in, let me know and I'll shape the trait around it.