bench: add projection_subquery SQL benchmark suite - #25346
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #25346 +/- ##
==========================================
- Coverage 82.33% 82.33% -0.01%
==========================================
Files 1137 1137
Lines 432498 432498
Branches 432498 432498
==========================================
- Hits 356116 356107 -9
- Misses 54843 54851 +8
- Partials 21539 21540 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds a SQL benchmark suite for IN, NOT IN and EXISTS subqueries that sit in the SELECT list instead of a filter. A projected IN must return NULL, and not false, when there is no match and the inner side holds a NULL, so the decorrelation turns one projected IN into more than one mark join. A mark join with no hashable join predicate runs as a nested-loop join, and the cost then grows with the outer row count times the inner row count. See apache#25341. The suite has seven queries, one per shape: bare uncorrelated IN, the same IN wrapped in COALESCE, IN correlated on an equality, two independent IN subqueries in one SELECT list, NOT IN, correlated EXISTS, and IN correlated on a less-than. The last one has no equality to hash on, so it keeps the nested-loop plan. It is the control: its time must not change when the hashable shapes get faster. Every query aggregates the projected boolean, so the result is two numbers and the measured cost is the plan and not the size of the output. The counts are checked in under results/, so --result-mode validate also proves that a change to the decorrelation still returns the same rows. The two tables are built inline by the suite load SQL, so there is no data step. PSQ_ROWS sets the row count in each table. The default is 30000, which keeps the nested-loop plans at a few hundred milliseconds. The checked-in result files hold the counts for that default. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
adriangb
force-pushed
the
bench-projection-subquery
branch
from
September 17, 2026 23:17
387c726 to
85da22e
Compare
AdamGS
approved these changes
Sep 18, 2026
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
An
IN,NOT INorEXISTSsubquery in theSELECTlist is much slower than the same subquery in aWHEREclause.A projected
INmust returnNULL, and notfalse, when there is no match and the inner side holds aNULL.The decorrelation therefore turns one projected
INinto more than one mark join.A mark join with no hashable join predicate runs as a nested-loop join, so the cost grows with the outer row count times the inner row count.
There is no benchmark suite that measures this shape today.
The benchmark bot compares a pull request against its merge base.
It can only report a change if the suite is present on both sides.
The suite must therefore land on
mainfirst, before the fix is measured with it.What changes are included in this PR?
projection_subquery, with seven queries. Each query is one shape:q01_in_bare: bare uncorrelatedIN.q02_in_coalesce: the sameINwrapped inCOALESCE, which is the common way to use the result.q03_in_correlated_eq:INcorrelated on an equality.q04_in_two_columns: two independentINsubqueries in oneSELECTlist.q05_not_in_bare:NOT IN.q06_exists_correlated: correlatedEXISTS, which has noNULLresult and needs only one mark join.q07_in_correlated_residual:INcorrelated on<. There is no equality to hash on, so this query keeps the nested-loop plan. It is the control: its time must not change when the hashable shapes get faster.NULL, which keeps three-valued logic in play. SetPSQ_ROWSto change the row count in each table. The default is 30000.--result-mode validatealso proves that a change to the decorrelation still returns the same rows. The counts hold for the defaultPSQ_ROWS.bench.shwiring:./benchmarks/bench.sh data projection_subqueryreports that there is no external data, and./benchmarks/bench.sh run projection_subqueryruns the suite.benchmarks/README.mdand in the suite table ofbenchmarks/sql_benchmarks/README.md.What is the testing strategy for this PR?
This PR adds no product code, so there are no unit tests. It was verified by running the suite.
./benchmarks/bench.sh data projection_subqueryprints the no-data message../benchmarks/bench.sh run projection_subquerybuildscargo bench --bench sqland completes with a time for each of the seven queries.--result-mode validatepasses onmainand on the branch of #25338, which shows that both sides return the same rows.Median of five iterations at the default
PSQ_ROWSof 30000, on one machine:q01_in_bareq02_in_coalesceq03_in_correlated_eqq04_in_two_columnsq05_not_in_bareq06_exists_correlatedq07_in_correlated_residual(control)The control query is unchanged, as expected, because it has no equality to hash on.
Are there any user-facing changes?
No. This PR adds benchmarks only.
🤖 Generated with Claude Code