Repository navigation
Conversation
DataFusion plans a CTE or view in full at every place a query reads it, so a model whose layers each read the one before several times expands into a tree many times the size of the model. Context.prepare now splits such a query, with sqlparser in the native module, into a step for each CTE or view read more than once, whose rows are stored as a table that the later steps read, and writes each call's rows into it in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #287. Merge that first; this PR's base is
prepared-queries.Why
DataFusion inlines a CTE or a view at every place a query reads it. A model whose layers each read the layer before more than once grows with every layer. The one-layer GPT in the ML demos plans its loss as 9,882 operators, which are repeats of only 87 distinct subplans. One 233-operator subtree appears 40 times, and its joins output 9.1 million rows per call. DataFusion's
CommonSubexprEliminatemerges repeated expressions within one node, but never repeated subplans.How
src/share.rs(sqlparser 0.62, with itsvisitorfeature):share(query, views, prefix).None, and the query is planned as written, forWITH RECURSIVE, aMATERIALIZEDCTE, a subquery with CTEs of its own, a view with a column list, more than one statement, or SQL it can't parse.Context.prepare(xarray_sql/sql.py):information_schema.views._xql_<uuid>_name.Performance
The GPT demo's training step, on an Intel i7-8700, DataFusion 55.2.0, best of 3 rounds:
ctx.sql)prepare(#287)preparewith shared CTEsMost of what's left is ddx's gradient step (xqlsystems/ddx#213).
Tests
tests/test_prepare.pychecks that each call returns the rows that planning the query again returns, for:Writing stale rows, or skipping the fallback when a write fails, makes the matching tests fail.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h