Skip to content

Log skip index use in query log - #99793

Merged
alexey-milovidov merged 17 commits into
ClickHouse:masterfrom
grantholly-clickhouse:log_skip_index_use_in_query_log
Mar 28, 2026
Merged

alexey-milovidov merged 17 commits into
ClickHouse:masterfrom
grantholly-clickhouse:log_skip_index_use_in_query_log

Conversation

@grantholly-clickhouse

@grantholly-clickhouse grantholly-clickhouse commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

We now track any data skipping indices that were used during query execution in the query_log table in a new column named skip_indices. Fixes #78676. Original author @pheepa

Documentation entry for user-facing changes

Adds a new Array[String] column to system.query_log for any data skipping indexes used during query execution

###Details

This PR reintroduces #87862

Here I am trying to add the list of skip indexes used during execution to the query_log table. I want to add the skip index to the QueryAccessInfo if we actually used the skip index to further filter down granules. I don't want to add the skip index if it is only considered during planning. The new query_log table should have an array column where we keep all the skip indexes that were used during the query. I'm grabbing the index name from the index condition type, and I hope, because I'm not sure, that this should match the name we use for the data_skipping_indexes.name column.

I borrowed heavily from the way that we track projections and views, hence the new method, and array type column.

My hope is that this will provide another way to troubleshoot ClickHouse queries and index utilization.

Version info

  • Merged into: 26.4.1.346

@clickhouse-gh

clickhouse-gh Bot commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [52e269e]

Summary: ✅


AI Review

Summary

This PR adds query_log.skip_indices and wires skip-index usage tracking from MergeTree index analysis into system.query_log, with docs and stateless tests (including quoted identifier coverage). I found one blocker: with use_skip_indexes_on_data_read=1, the new logging gate can silently drop all skip_indices entries even when skip indexes are actually used, so logged behavior is incorrect in an important execution mode.

Findings

❌ Blockers

  • [src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:927-947, 1107-1111] index_dropped_granules is only incremented inside the filterMarksUsingIndex path. But when use_skip_indexes_on_data_read=1, that path is skipped (is_index_supported_on_data_read returns true), so dropped remains zero and the final index_dropped_granules[idx] > 0 check suppresses logging. Result: query_log.skip_indices can be empty despite real skip-index usage in the data-read path.
    Suggested fix: keep prior behavior for read-time mode (log useful_indices when use_skip_indexes_on_data_read=1) or plumb true per-index drop counters from the runtime skip-index reader and gate on those.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ⚠️ Incorrect skip_indices reporting in use_skip_indexes_on_data_read mode blocks safe rollout.
Compilation time ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Fix skip_indices logging for use_skip_indexes_on_data_read=1 so actually used skip indexes are recorded reliably in system.query_log.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 17, 2026
Comment thread src/Interpreters/QueryLog.cpp Resolved
@grantholly-clickhouse
grantholly-clickhouse marked this pull request as ready for review March 19, 2026 18:47
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 20, 2026
@alexey-milovidov alexey-milovidov self-assigned this Mar 20, 2026
@alexey-milovidov
alexey-milovidov removed this pull request from the merge queue due to a manual request Mar 20, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add at least one test with unusual table and index names, something with spaces hello, world and dots like my.favorite.index, and check that they are correctly quoted in the query_log.

…st place and index granule filtering initializing counters
@clickhouse-gh

clickhouse-gh Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.20% +0.10%
Functions 24.40% 24.50% +0.10%
Branches 76.70% 76.80% +0.10%

Changed lines: 94.74% (90/95) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 28, 2026
Merged via the queue into ClickHouse:master with commit 14b1544 Mar 28, 2026
149 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 28, 2026
alexey-milovidov added a commit that referenced this pull request Mar 28, 2026
…_index_use_in_query_log"

This reverts commit 14b1544, reversing
changes made to 953fd8d.
@rschu1ze

rschu1ze commented Apr 2, 2026

Copy link
Copy Markdown
Member

@grantholly-clickhouse Since this PR was reverted (I couldn't figure out why) - do you like to give it another try?

@grantholly-clickhouse

Copy link
Copy Markdown
Contributor Author

I will try to resubmit later

@alexey-milovidov

Copy link
Copy Markdown
Member

@grantholly-clickhouse, later means when?

aminparsa18 added a commit to aminparsa18/Flare.Net that referenced this pull request Sep 6, 2026
…ch (#194)

Answers the open question the earlier deferred-shipping pass left behind:
is there a version- or config-gated ClickHouse mechanism that would make a
real, retrospective skip-index-effectiveness signal for the Indexing page
honest, rather than invented?

Findings: the exact feature was requested upstream
(ClickHouse/ClickHouse#78676) and briefly shipped
(ClickHouse/ClickHouse#99793, a system.query_log skip_indices column) but
was merged and reverted the same day (~2026-03-28) over a correctness bug
under use_skip_indexes_on_data_read=1 (the current default) - confirmed
against current master source, not just changelog prose. Dormant upstream
since a 2026-04-29 maintainer nudge with no follow-up located.

No code changes - this is upstream-research documentation only, already
referenced by docs-internal/planning/roadmap.md's existing "Research: a
real skip-index effectiveness signal" bullet.

Co-authored-by: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

system.query_log should record if the query used skip indexes

4 participants