Repository navigation
Cache the parameterized view query hash in TableNode - #119517
Conversation
`TableNode::isEqualImpl` and `TableNode::updateTreeHashImpl` traversed the whole substituted inner query of a parameterized view on every call. The tree hash of every expression that references a column of the view descends into its `TableNode`, so analysis of large parameterized view trees became several times slower after #105170. Compute the hash once per node instead. Closes: #118736 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [c461959] Summary: ❌
AI ReviewSummaryCaches the substituted parameterized-view inner-query hash on Findings
Final Verdict
LLVM Coverage ReportMeasured on commit c461959.
Changed lines: Changed C/C++ lines covered: 26/30 (86.67%) · Uncovered code |
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is clear. Maybe add a perf test?
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Added a performance test, |
|
📊 Cloud Performance Report ✅ AI verdict: This PR narrows the analyzer cost of parameterized views: it caches the substituted inner-query hash on the TableNode instead of re-traversing the (potentially large) inner query on every isEqual/tree-hash call. That path is exercised only by parameterized-view analysis (covered by the new perf test), not by standard ClickBench SELECTs. The flagged ClickBench deltas (Q5 -12.8%, Q28, Q33, Q34) all sit on queries that use no parameterized views, so Q5's flagged improvement is downgraded to not_sure as run-to-run variance, and the Q33/Q34 envelope-suppressed no_change verdicts are correct and left untouched. No real per-query regression or improvement on the standard benchmarks is attributable to this change. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Build profile diff (arm_release)Comparing commit See the job log for details. |
perf.py expands {name} in every query as a substitution placeholder, so
{ts:DateTime64(3)} failed with KeyError: 'ts' in substitute_parameters and
the test errored out on both shards (8 errors in amd_release 4/6 and
arm_release 2/6). Double the braces so the parameterized-view syntax
reaches the server verbatim.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119517&sha=b6fefdfb9112f36b080856ec9c58b4f4d4d67452&name_0=PR
PR: #119517
A performance test that uses literal braces in SQL (e.g. a parameterized
view parameter like {ts:DateTime64(3)}) failed in substitute_parameters
with a bare KeyError: 'ts' traceback, which does not explain that {name}
is expanded as a <substitution> placeholder or that the braces must be
doubled. Wrap the per-template substitution and rethrow with the failing
template, the available parameters and the {{...}} escaping hint,
keeping the original exception as the cause.
Seen in ClickHouse#119517:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119517&sha=b6fefdfb9112f36b080856ec9c58b4f4d4d67452&name_0=PR
Backport #119517 to 26.8: Cache the parameterized view query hash in TableNode
TableNode::isEqualImplandTableNode::updateTreeHashImpltraversed the whole substituted inner query of a parameterized view on every call (introduced by #105170 to tell apart two calls of the same view with different argument values). The tree hash of every expression that references a column of the view descends into itsTableNode, and the analyzer computes such hashes hundreds of times while resolving a query, so planning of a large parameterized view tree became several times slower. The hash of the inner query is now computed once perTableNode(and copied on clone), so the equality check and the tree hash are O(1) again.Measured on the fixture from the issue (
clickhouse local, min of 5 alternating rounds, with the parameterized-view call resolved through aTableNodeas in 26.5-26.7):EXPLAIN SELECT * FROM synth_treatment...SELECT * FROM synth_treatment...(empty tables)EXPLAIN SELECT * FROM synth_control...A performance test,
tests/performance/parameterized_view_analysis.xml, models the shape of the issue: a parameterized view with a large body, called three times from an outer parameterized view, joined on several columns and filtered by a long AND chain of comparisons over empty tables. With the 26.6-style resolution the first query takes about 1.3 s before and 0.75 s after this change; on master (where a call is aTableFunctionNode) it takes about 1.1 s in both cases, so the test guards the analysis cost of such trees rather than this particular path.Note that on master a parameterized-view call is resolved as a
TableFunctionNodesince #68978 (26.8), so the slow path is reached there only when aTableNodewraps a parameterized view through other routes; the regression as reported is present in 26.6 and 26.7, where the call still becomes aTableNode. This change is needed on those release branches.Closes: #118736
Related: #105170
Related: #68978
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a slowdown of query analysis for large parameterized views: the substituted view query was re-hashed on every comparison of the query tree. Closes #118736.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119517]
Version info
26.9.1.1559(included in26.9and later)26.8.6.5