Closing the Cross-Dialect Gap: Query Plans as a Portable Interface in Text-to-SQL

Corentin Royer, Robin Oester, Yotam Perlitz, Yannick Metz, Andrea Giovannini, Mennatallah El-AssadyarXiv 2026

TL;DR

Most Text-to-SQL systems are brittle, performing well on SQLite but failing when deployed on PostgreSQL or MySQL. This paper proposes a "dialect-agnostic" approach: instead of asking LLMs to write SQL directly, they generate relational algebra query plans that a deterministic compiler then translates into any SQL dialect. This method restores cross-dialect portability across all model scales, often outperforming direct SQL generation once models are fine-tuned.

What Problem Does This Paper Address?

While the research community celebrates high accuracy on benchmarks like BIRD and Spider, there is a hidden catch: these benchmarks almost exclusively use SQLite. In the real world, production databases are a fragmented landscape of PostgreSQL, MySQL, ClickHouse, and others.

The authors identify a massive cross-dialect gap. Because SQL dialects differ in function signatures (e.g., strftime vs. to_char), type systems, and null-handling, a model prompted or trained for SQLite produces code that is syntactically or semantically invalid on other backends. Even the most capable frontier models see their accuracy plummet by 8–17 percentage points when switched to a different dialect. The core issue is that we are forcing LLMs to be both logicians (understanding the question) and compilers (knowing every dialect's quirks).

Methods

The authors argue that the generation target (what the LLM outputs) should be decoupled from the execution target (what the database runs).

  1. Query Plans as Intermediate Representation (IR): Instead of SQL, the LLM generates a JSON-serialized logical query plan based on Apache Calcite. This plan represents the "logical tree" of the query (scans, filters, joins, projects) without committing to a specific syntax.
  2. Deterministic Compilation: A custom compiler takes this agnostic plan and renders it into valid SQL for the target backend. This moves the burden of dialect adaptation from the probabilistic LLM to a reliable, rule-based system.
  3. DF-Match Evaluation Framework: The authors found that standard metrics like BIRD Execution Accuracy (BIRD-EA) are flawed for cross-dialect testing because they ignore row order and duplicate counts, leading to false positives and negatives. They introduced DF-Match, a question-aware comparator that uses an LLM to classify if a question requires specific ordering or row counts, ensuring a fair "apples-to-apples" comparison across different database engines.
The evaluation pipeline: LLMs emit one plan, which is compiled into four dialects and evaluated against a gold standard using DF-Match.

Datasets

The study evaluates thirteen models across three size tiers (Small, Medium, Large) using:

  • BIRD: A large-scale, complex Text-to-SQL benchmark.
  • Spider: A standard cross-domain Text-to-SQL benchmark.
  • SynSQL: A synthetic corpus of 1 million examples used for controlled fine-tuning experiments.

The authors migrated every SQLite database in BIRD and Spider to PostgreSQL, MySQL, and ClickHouse to create "dialect-parallel" evaluation environments.

Key Insights and Ideas

  • "Execution target $\neq$ Generation target": Just because a database executes SQL doesn't mean SQL is the best format for an LLM to generate. Structured query plans are more stable and portable.
  • Portability is Restored: Using query plans brings "portability" (the ratio of worst-dialect to best-dialect accuracy) to $\ge 0.96$ for all model sizes. Direct SQL generation, by contrast, remains stuck in the 0.70–0.85 range regardless of model scale.
  • The 68B Parameter Crossover: For zero-shot prompted models, there is a "capability threshold." Models smaller than ~68B parameters struggle with the complex JSON syntax of query plans. However, above this threshold, query plans match or beat SQL in lower-bound accuracy.
  • Supervision Strength: When fine-tuned on identical data, a model trained on query plans actually becomes stronger than one trained on SQL, even on its "home" dialect (SQLite). This suggests that query plans might be a more effective way to teach models relational logic.
Portability vs. Model Size: Query plans (yellow) maintain near-perfect portability across all scales, while SQL (blue) shows a persistent gap.

Key Results

  • Portability Gains: Query plans shrink the lower-bound accuracy drop from 8–17 percentage points (under SQL) to at most 2.3 percentage points.
  • Fine-tuning Success: A fine-tuned Ministral-3-8B model reached 64.5% accuracy on SQLite using query plans, compared to 61.2% when trained on SQL.
  • Error Reduction: Using query plans reduced "Ordering/Ranking" errors by 37% among the strongest models, as these concepts are explicit operators in a plan rather than easily-forgotten SQL clauses.
Lower-bound accuracy on BIRD: Query plans (yellow) rise more steeply with scale and cross the SQL baseline (blue) at approximately 68B parameters.

Limitations and Future Work

  • Backend Coverage: The study focused on four open-source backends. Extending this to cloud warehouses like Snowflake or BigQuery, which have even more divergent syntaxes, is a necessary next step.
  • Token Overhead: Query plans are more verbose than SQL. On BIRD, plans averaged 227 tokens compared to 58 for SQL (a ~3.9x increase). While this increases inference cost, the authors suggest that constrained decoding or reducing reasoning verbosity could mitigate this.
  • JSON Fragility: Small prompted models often fail due to malformed JSON. The authors propose that constrained decoding (forcing the model to follow a schema) would likely close the remaining gap for smaller models.
  • Interpretability: Because query plans are trees, they are inherently more visualizable and potentially easier for humans to debug than complex, nested SQL strings. The authors leave the study of "plan-based explainability" to future work.

Summary updated

BibTeX
@misc{royer2026closing,
  author = {Corentin Royer and Robin Oester and Yotam Perlitz and Yannick Metz and Andrea Giovannini and Mennatallah El-Assady},
  title = {{Closing the Cross-Dialect Gap: Query Plans as a Portable Interface in Text-to-SQL}},
  year = {2026},
  eprint = {2609.33670},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.33670},
}
Figure