Repository navigation
TopN dynamic filtering for the Memory engine - #123787
Conversation
`ReadFromMemoryStorageStep` now implements `supportsTopKDynamicFilter` and `setTopKFilter`, so `tryOptimizeTopK` arms it for `ORDER BY ... LIMIT n` like it does for Parquet files. The source evaluates `__topKFilter` as the first of its in-source filter steps: for a table with `compress = true`, a block where no row is within the running threshold is skipped after decompressing only the sort column, and the other columns are read only for the remaining rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [d570173] Summary: ✅
AI ReviewSummaryThis PR adds source-side TopN dynamic filtering for the Final Verdict
LLVM Coverage ReportMeasured on commit d570173.
Changed lines: Changed C/C++ lines covered: 34/39 (87.18%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds TopN dynamic filtering only to reads from Memory-engine tables (ReadFromMemoryStorageStep). ClickBench and TPC-H read MergeTree tables, so none of the benchmark queries run the new code. The three flagged ClickBench improvements (Q11 -15.2%, Q30 -15.5%, Q31 -15.0%) are almost the same size, and each lands just below master's normal range. That pattern fits a quieter benchmark run, not an effect of the PR, so all three are downgraded to not sure. No regressions were flagged. clickbenchFlagged queries (3 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
|
…eadFromMemoryStorage` The materialized CTE is read from a `Memory` table, which now supports TopN dynamic filtering, so `EXPLAIN` shows `TopN filter column` for the `ORDER BY c DESC LIMIT 1` branch. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123787&sha=latest&name_0=PR&name_1=Fast%20test PR: #123787 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units10 translation units recompiled, 48 s compile time in total, 10 of them have a recent master baseline. |
…th a `DEFAULT` expression Blocks written before `ALTER TABLE ... ADD COLUMN` expose the default of the type inside the source, while the query sees the `DEFAULT` expression evaluated above it, so the threshold filter could drop rows that belong to the top-K. Gate such columns the same way as `StorageMemory::supportedPrewhereColumns`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e_top_k_dynamic_filtering` https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123787&sha=f8abd618830af46494dd5840d71535df8f2a02fa&name_0=PR #123787 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fy the comment Co-Authored-By: Claude Opus 5.5 <[email protected]>
TopN dynamic filtering (
use_top_k_dynamic_filtering) for theMemoryengine.ReadFromMemoryStorageStepimplementssupportsTopKDynamicFilterandsetTopKFilter, the generic interface thattryOptimizeTopKalready uses for Parquet files. The source evaluates__topKFilteras the first of its in-source filter steps (before the row policy and thePREWHEREsteps). Withcompress = true, a block where no row is within the running threshold is skipped after only the sort column is decompressed. The other columns are read only for the remaining rows.The motivation is ClickBench Q24–Q27 (
... ORDER BY EventTime LIMIT 10) on theclickhouse-memoryentry (ClickHouse/ClickBench#1590). On a local 10M-row subset ofhits(Memory SETTINGS compress = true), Q24SELECT * FROM hits WHERE URL LIKE '%google%' ORDER BY EventTime LIMIT 10takes 0.318 s → 0.152 s withmax_threads = 8, and 0.152 s → 0.107 s withmax_threads = 24. The filter only helps once a thread has read its first block and a threshold exists, so the gain grows with the number of blocks per thread. The 100M-row benchmark table has about 1200 blocks.The source also re-checks that the
PREWHEREand the row policy do not depend on the set of rows they see (rowNumberInBlock,rand, ...).optimizePrewherecan move such a condition intoPREWHEREaftertryOptimizeTopKhas checked the plan.EXPLAIN actions = 1showsTopN filter column: ...on theReadFromMemoryStoragestep.Related: ClickHouse/ClickBench#1590
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Queries with
ORDER BY ... LIMIT noverMemorytables use TopN dynamic filtering: rows that cannot get into the result are dropped while reading, before the other columns are read (or decompressed, withcompress = true).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123787]
Version info
26.10.1.1720-master(included in26.10and later)