Repository navigation
bench: plan unmarked, MATERIALIZED and NOT MATERIALIZED CTEs - #27005
Merged
Merged
Conversation
Add sql_planner cases that plan a CTE read once, read twice, and a chain of six CTEs that each read the previous one twice, for each kind of CTE, plus one query that mixes all three. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nuno-faria
approved these changes
Nov 3, 2026
Comment on lines
+1028
to
+1030
| ("unmarked", ""), | ||
| ("materialized", "MATERIALIZED "), | ||
| ("not_materialized", "NOT MATERIALIZED "), |
Contributor
There was a problem hiding this comment.
Is there a reason to test unmarked and not materialized?
Contributor
Author
There was a problem hiding this comment.
unmarked can change, e.g. postgres materializes it if it's referenced more than once. NOT MATERIALIZED is always inlined
A reviewer asked why the benchmark has both: today the planner inlines them alike. Say in the comment that the unmarked default can change, as in PostgreSQL, while NOT MATERIALIZED always inlines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Which issue does this PR close?
Rationale for this change
MATERIALIZEDCTEs (#26271) are planned differently from inlined CTEs: each body is optimized on its own before the rest of the plan. #26428 adds more work to that step. No planner benchmark plans a materialized CTE today, so there is no standard way to see what this costs, or to compare it with inlining.What changes are included in this PR?
New
sql_plannercases, which plan a query from SQL to a physical plan. The PostgreSQL dialect is used, because sqlparser only parses[NOT] MATERIALIZEDfor that dialect. For each kind of CTE (unmarked,MATERIALIZED,NOT MATERIALIZED) there are three cases:physical_cte_<kind>_one_ref: the CTE is read once.physical_cte_<kind>_two_refs: the CTE is joined with itself.physical_cte_<kind>_chain_6: six CTEs, each joining the previous one with itself.physical_cte_mixedhas one CTE of each kind, each read twice.Results on
main(Criterion means):MATERIALIZEDNOT MATERIALIZEDphysical_cte_mixedtakes 1.36 ms.An inlined chain copies the first CTE 32 times. So it takes about 9 times as long to plan as the materialized chain.
What is the testing strategy for this PR?
This PR has only benchmarks. They run with:
The
sql_plannerbenchmark needs ClickBench data. The checked-in fixture works: putdatafusion/core/tests/data/clickbench_hits_10.parquetin a directory, and setCLICKBENCH_DATA_PATHto that directory.Are there any user-facing changes?
No.
🤖 Generated with Claude Code