Repository navigation
feat: execute and re-write plain CTEs - #1985
Merged
Merged
Conversation
jkaczman
force-pushed
the
jk-subqueries-plain-ctes
branch
from
November 9, 2026 21:34
58eac5b to
b999cd9
Compare
Contributor
|
Metal bench (arm64) passed. All 475 measures within bounds.
Counters per txn
Microbench: all 462 measures within bounds. Hot code per txn
pooler:
sharding-w2:
Logslb, microbench, pooler, sharding-w2, sharding-w8, verdict.json |
Contributor
|
Metal bench (x86) failed. 1 of 475 measures outside bounds.
Counters per txn
Microbench: 461 of 462 measures within bounds. Microbench latency: 1 benches changed more than 3%
Hot code per txn
pooler:
sharding-w2:
Logslb, microbench, pooler, sharding-w2, sharding-w8, verdict.json |
jkaczman
force-pushed
the
jk-subqueries-plain-ctes
branch
from
November 9, 2026 21:46
b999cd9 to
d5c85c6
Compare
jkaczman
marked this pull request as ready for review
November 9, 2026 21:55
jkaczman
force-pushed
the
jk-subqueries-plain-ctes
branch
from
November 9, 2026 21:55
46c1469 to
ba27030
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Building off of #1922, this PR now executes and re-writes plain CTEs (specifically, WITH queries that aren't recursive and don't modify rows) as part of the on-going support for cross-shard subqueries (#381) and cross-shard CTEs (#380).
If we receive a CTE that references a sharded table, we now evaluate the CTE separately, and then re-write the CTE within the outer statement to use the rows it returned from the separate evaluation.
E.g., if we have a statement such as
If we sent the statement to all of our shards as-is, Shard A would only join the rows of subusers on Shard A, and Shard B would only join the rows of subusers on Shard B.
Now, we first execute the query of the CTE on all shards. Then we re-write the CTE as explicit VALUES with the rows that the shards return:
Since the statement now doesn't read any tables, it'll be sent round robin and return the correct answer now (as the CTE values are inlined).
Very similar handling to what's done for derived tables in #1922.
Some other cases are handled: