Repository navigation
Predicate statistics log (selectivity collection) - #98727
Conversation
|
Workflow [PR], commit [efc1cdd] Summary: ❌
AI ReviewSummaryThis PR introduces Missing context
Findings
ClickHouse Rules
Performance & Safety
Final Verdict
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a new system.predicate_statistics_log system table and adds optional collection of predicate selectivity statistics during query execution (in FilterTransform), intended to support workload-driven index/projection suggestions.
Changes:
- Add
PredicateStatisticsLogsystem log (schema + registration) and apredicate_statistics_sample_rateserver setting to control collection. - Extend
FilterTransformto extract predicate “atoms” from the filter DAG and emit selectivity stats into the new system log. - Add unit/stateless tests plus test/server config to enable the log and sampling.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/Processors/Transforms/FilterTransform.h |
Adds members and header dependency to support predicate stats collection. |
src/Processors/Transforms/FilterTransform.cpp |
Implements sampling, atom extraction hookup, and log emission from FilterTransform. |
src/Interpreters/PredicateAtomExtractor.h |
Declares predicate atom extraction/classification utilities. |
src/Interpreters/PredicateAtomExtractor.cpp |
Implements atom extraction from ActionsDAG and function-name classification. |
src/Interpreters/PredicateStatisticsLog.h |
Declares the new system log element and log type. |
src/Interpreters/PredicateStatisticsLog.cpp |
Defines the system table schema and block append logic. |
src/Interpreters/SystemLog.h |
Registers predicate_statistics_log in the system logs list. |
src/Interpreters/SystemLog.cpp |
Includes the new log header so it can be instantiated. |
src/Interpreters/Context.h |
Adds getPredicateStatisticsLog() accessor. |
src/Interpreters/Context.cpp |
Implements getPredicateStatisticsLog(). |
src/Common/SystemLogBase.h |
Adds the new log element to the system log element registry. |
src/Common/SystemLogBase.cpp |
Includes the new log implementation header. |
src/Core/ServerSettings.cpp |
Adds predicate_statistics_sample_rate server setting. |
programs/server/config.d/predicate_statistics_log.xml |
Adds default server config for the new system log + sampling setting. |
tests/config/config.d/predicate_statistics_log.xml |
Adds test config for the log + sampling setting. |
tests/config/install.sh |
Installs the new test config file into the test server config.d. |
tests/queries/0_stateless/04011_predicate_statistics_log.sql |
Adds a stateless test validating log population. |
tests/queries/0_stateless/04011_predicate_statistics_log.reference |
Reference output for the new stateless test. |
src/Interpreters/tests/gtest_predicate_atom_extractor.cpp |
Adds unit tests for predicate function classification and null handling. |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…hub.com/ClickHouse/ClickHouse into yarik/predicate-statistics-system-table
| const auto & counters = read_steps_performance_counters.getCounters(); | ||
| std::vector<size_t> all_filter_indices; | ||
| std::vector<size_t> filter_step_indices; | ||
| for (size_t i = 0; i < prewhere_actions.steps.size(); ++i) | ||
| { | ||
| const auto & step = prewhere_actions.steps[i]; | ||
| if (step->type == PrewhereExprStep::Filter) | ||
| { | ||
| all_filter_indices.push_back(i); | ||
| if (!step->predicate_expression.empty()) | ||
| filter_step_indices.push_back(i); | ||
| } | ||
| } |
There was a problem hiding this comment.
this is something strange - why not just do the same iteration like being done in dumpStatistics?
…hub.com/ClickHouse/ClickHouse into yarik/predicate-statistics-system-table
LLVM Coverage Report
Changed lines: 94.18% (275/292) | lost baseline coverage: 7 line(s) · Uncovered code |
PR ClickHouse#101267 removed the 15-iteration retry loop with the claim that the new caching-based sampling ensures a single pass produces all expected trace-log rows. After the PR was merged to master, the test began failing on both master (`Integration tests (amd_binary_excluded_from_llvm)`) and several unrelated in-flight PRs (ClickHouse#98727, ClickHouse#101434, ClickHouse#103307), each at different assertion lines in the single-pass test: - `get_trace_events('Unknown', 'Global', 'JemallocSample') > 0` - `get_trace_events('Unknown', 'Max', 'MemorySample', query_id) > 0` - `get_trace_events('Global', 'Max', 'Memory'/'MemoryPeak') > 0` The reason these events are not guaranteed in a single pass — even with fully-propagated `sample_probability` — is that two of the trace types are genuinely probabilistic relative to this test's workload: - `JemallocSample` is emitted by `jemalloc`'s own profile sampler (`lg_prof_sample=20` ≈ one sample per 1 MiB). Ten `logTrace('foo')` calls plus a `SELECT * FROM numbers(100000) ORDER BY number` are not guaranteed to allocate enough `jemalloc`-tracked memory to trigger a sample inside a `MemoryTrackerBlockerInThread(Global)` scope. - `Memory`/`MemoryPeak` with `memory_context = 'Global'` are only emitted when `total_memory_tracker` crosses its `total_memory_profiler_step` watermark (4 MiB default). Whether this happens inside a given test query depends on cumulative server-wide allocations including background activity, not just the query's own allocations. The retry loop bounds the test runtime at ~15 s while letting these events accumulate reliably. Restore it, and add a comment explaining why it is required so it is not dropped again. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=fa205863ba68f05b529e2073defb5cf5df7cc832&name_0=MasterCI&name_1=Integration%20tests%20%28amd_binary_excluded_from_llvm%29 Session: cron:clickhouse-ci-task-worker:20260421-224500 Co-Authored-By: Claude Opus 4.7 <[email protected]>
Adds system.predicate_statistics_log — a new system log that records sampled filter selectivity and MergeTree index-granule reduction during query execution. Motivation: the upcoming physical-design advisor needs workload-driven signal on how selective real predicates are and which indexes actually prune granules, to recommend indexes and projections.
Controlled by a new server setting
predicate_statistics_sample_rate(default 0 = disabled; 1 = every query; N > 1 = roughly 1/N of queries, hashed by query_id)Two row shapes share the table and link via query_id:
Example:
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added
system.predicate_statistics_log, a new sampled log of predicate filter selectivity and MergeTree index-granule pruning per query. Disabled by default; enable via thepredicate_statistics_sample_rateserver setting. Needed for automatic index and projection recommendationsDocumentation entry for user-facing changes
Note
Medium Risk
Adds new logging in hot query-execution paths (
FilterTransformandReadFromMergeTree) controlled by a new server setting; while default-disabled, enabling it could add CPU/memory overhead and increase system log write volume.Overview
Introduces a new system log table,
system.predicate_statistics_log, to record sampled selectivity data for query predicates and MergeTree index stages.Adds server setting
predicate_statistics_sample_rate(default0/disabled) plus config stanzas to create/flush the new log, wires the log intoSystemLog/Context, and implements collection inFilterTransform(per-predicate chunk selectivity via a newPredicateAtomExtractor) andReadFromMergeTree(per-index granule selectivity arrays). Includes a stateless test that enables the setting via config reload and validates log output.Written by Cursor Bugbot for commit 2cc7db6. This will update automatically on new commits. Configure here.
Version info
26.5.1.31