Repository navigation
Explain analyze estimate and actual cost - #114792
Conversation
Split out the in-development work-intervals collection (collect_work_intervals / WorkInterval / work_intervals) from the Join statistics work so it can live in its own branch/PR. This feature is not yet wired to a setting or an output consumer. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…o explain-analyze-parallelism-global
…o explain-analyze-parallelism-global
… explain-analyze-parallelism-global
…al' into explain-analyze-estimate-cost
… explain-analyze-parallelism-global
…n-analyze-parallelism-global
…n-analyze-estimate-cost
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [3bc3004] Summary: ✅
AI ReviewSummaryThis PR wires join-order estimates and actual join metrics into Findings
Tests
Final VerdictLLVM Coverage ReportMeasured on commit 3bc3004.
Changed lines: Changed C/C++ lines covered: 486/506 (96.05%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes125 object files changed (+257.34 KiB total), 2 added.
717 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units799 translation units recompiled, 6538 s compile time in total, 797 of them have a recent master baseline. |
This reverts commit 90c3703.
…n-analyze-estimate-cost
|
@m-selmi thank you for the review! I was thinking on whether is should add your suggestion about |
|
|
||
| MetricGroup output{MetricGroupKey::Output, {}}; | ||
| output.metrics.emplace_back(MetricKey::Estimated, optionalQuantity(estimation.output_rows)); | ||
| output.metrics.emplace_back(MetricKey::Actual, context.io.output_rows); |
There was a problem hiding this comment.
context.io.output_rows is the step-level port counter, not "rows produced by the main join stream". collectIOStats sums every output port that crosses a step boundary, and hash-join pipelines install a separate JoiningTransform on the totals stream (QueryPipelineBuilder::joinPipelinesRightLeft, lines 724-733). On that path JoiningTransform::transform emits joinTotals rows without calling join->joinBlock, so the per-side matched-row report stays on main-stream semantics while this Actual row count grows by the totals row.
That also leaks into q-error below, and into Cost: actual because computeJoinBranchCosts feeds the same io_stats.output_rows into joinMatchedOutputRows. As soon as the join step propagates totals (for example from a joined subquery with WITH TOTALS), the new estimate-vs-actual metrics are wrong by one. Please either exclude the totals port from this accounting or derive the "actual output rows" from the same matched/unpaired counters used for the join-side metrics.
… join, changed implementaiton of selectivity for semi and anti joins
| fraction over the join conditions is used. | ||
| - `Output rows` — the estimated number of rows the join produces: | ||
| `<selectivity> * <left_rows> * <right_rows>` for an inner join, floored at `<left_rows>` for | ||
| `LEFT`, at `<right_rows>` for `RIGHT`, and at `<left_rows> + <right_rows>` for `FULL`, because an |
There was a problem hiding this comment.
FULL join output rows are not floored at left_rows + right_rows. When rows match, one left row and one right row collapse into the same output row, so a perfectly matching FULL JOIN between two 100-row inputs can legitimately produce 100 rows, not 200. This text now codifies the estimator's current behavior, so after this PR EXPLAIN PLAN / EXPLAIN ANALYZE will expose a systematically too-large Output rows estimate and q-error for fully matching FULL joins. Please floor FULL joins at max(left_rows, right_rows) and keep this explanation in sync.
|
@groeneai please analyze the error from the failed test https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114792&sha=3bc30044f91346dc18368904aaafb35e98843c14&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 Provide information if there are any fixes for this issue already, and if not -- create one. |
|
The failure is a master regression, not from your diff.
at It comes from #114817, merged to master 2026-09-09 08:56 UTC. Your head predates that: Mechanism: A fix is already open, #119106, so there is nothing to create and nothing to change on your side. It re-establishes the alias at the rebuild site. It also carries a deterministic reproducer on default settings if you want to confirm independently: SELECT deleted, b, c
FROM (SELECT 'v' AS b, toNullable('x') AS a, 1 AS deleted) AS q
INNER JOIN (SELECT 'x' AS a, 'w' AS c) AS s ON q.a = s.a
WHERE deleted AND (c != b); |
| case MetricKey::Actual: return "actual"; | ||
| case MetricKey::EstimatedNDV: return "estimated (NDV)"; | ||
| case MetricKey::ActualCartesian: return "actual (cartesian)"; | ||
| case MetricKey::QError: return "q-error"; |
There was a problem hiding this comment.
nice to see that we now have q-error, which is the only relevant error metric in DMBS.
Related: #110839
Related: #110668
Related: #110892
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
EXPLAIN ANALYZEnow shows more information about estimation for joins.Workflow [PR]
Sync PR [sync-upstream/pr/114792]
Version info
26.9.1.1130(included in26.9and later)