Querying in ClickHouse CloudThe data in this system table is held locally on each node in ClickHouse Cloud. Obtaining a complete view of all data, therefore, requires the
clusterAllReplicas function. See here for further details.Description
Contains sampled selectivity statistics collected while reading fromMergeTree tables. The table is populated only when predicate_statistics_sample_rate is greater than 0.
Availability
system.predicate_statistics_log is created only when the server configuration contains a predicate_statistics_log section. After creating the log, set predicate_statistics_sample_rate to a value greater than 0 to collect rows. Without the log section, queries against the table fail with UNKNOWN_TABLE.
Row shapes
A single query can produce two kinds of rows insystem.predicate_statistics_log:
- Filter rows, emitted per prewhere/filter step in
MergeTreeSelectProcessor. They populatepredicate_expression,input_rows,passed_rows,filter_selectivity, and the whole-predicate columnstotal_input_rows,total_passed_rows,total_selectivity. Index-related columns are empty. - Index rows, emitted per read step in
ReadFromMergeTree. They populate theindex_names,index_types,total_granules,granules_after, andindex_selectivitiesarrays, one entry per index stage (primary key, partition, skip indexes). Predicate-related columns are empty.
query_id and table, so they can be joined when both are needed.
Sampling and overhead
Sampling is controlled bypredicate_statistics_sample_rate:
0disables collection.1samples every query.N > 1samples approximately1 / Nof queries, hashed byquery_id.
SYSTEM FLUSH LOGS if you need rows to appear immediately.
It is safe to truncate or drop this table at any time.
Columns
hostname(LowCardinality(String)) — Hostname of the server executing the query.clickhouse_version(LowCardinality(String)) — Version of the ClickHouse server that produced the row.system_processor(LowCardinality(String)) — CPU architecture of the ClickHouse server that produced the row.event_date(Date) — Event date.event_time(DateTime) — Timestamp when this log entry was written.database(LowCardinality(String)) — Database name of the target table.table(LowCardinality(String)) — Table name of the target table.query_id(String) — Query ID for linking back to query_log.predicate_expression(String) — Whole filter expression handled by this prewhere/filter step (ActionsDAG dump).input_rows(UInt64) — Rows entering this prewhere/filter step.passed_rows(UInt64) — Rows surviving this prewhere/filter step.filter_selectivity(Float64) — Selectivity of this step: passed_rows / input_rows.total_input_rows(UInt64) — Rows entering the first prewhere step (total rows read from granules).total_passed_rows(UInt64) — Rows surviving all prewhere steps (rows delivered to the query).total_selectivity(Float64) — Selectivity of the whole predicate: total_passed_rows / total_input_rows.index_names(Array(LowCardinality(String))) — Names of indexes applied, e.g. [‘PrimaryKey’, ‘idx_bf_status’] (index rows only).index_types(Array(LowCardinality(String))) — Types of indexes applied: PrimaryKey, Skip, MinMax, Partition (index rows only).total_granules(Array(UInt64)) — Granules entering each index stage (index rows only).granules_after(Array(UInt64)) — Granules remaining after each index stage (index rows only).index_selectivities(Array(Float64)) — Per-index selectivity: granules_after / total_granules (index rows only).