Repository navigation
Add skip indices to query log - #87862
grantholly-clickhouse merged 66 commits into
Conversation
…xes used during execution
…cessInfo in the Context file
|
Workflow [PR], commit [b235a3b] Summary: ✅ AI Review1) SummaryThis PR adds 2) Missing context (if any)
3) Findings (by severity)Blockers
Majors
4) Tests & Evidence
5) ClickHouse Compliance Checklist (Yes/No + short note)
6) Performance & Safety NotesThe extra query-log collection is low overhead ( 7) User-Lens ReviewThe feature is useful and intuitive for observability, but users may be misled by incorrect naming/usage semantics in 8) Final Verdict
|
|
As of now, this PR will record any skip indexes picked in Here's an example of how it works While there are cases where a skip index could be selected as useful by this point and yet not filter any granules or ranges, I think I want to soften my original goal and intent of only reporting skip indexes that actually filtered ranges or granules. I think this makes more sense to the user if a skip index is shown in Here's that scenario I think it would be more appropriate to have skip index utilization broken down by granules dropped or ranges added as metrics with their own counters. |
changing indexes to indices Co-authored-by: Azat Khuzhin <[email protected]>
making argument name more descriptive Co-authored-by: Azat Khuzhin <[email protected]>
…updating SQL query test
There was a problem hiding this comment.
In general looks ok, I've adjusted title and description and wrote couple of comments, PTAL
Also, it will be nice to support amount of filtered out granules, but this has some complexity due to recently added use_skip_indexes_on_data_read (though it should not be hard to do), what do you think?
Also, maybe we need to add Co-authored-by for the author from #79635, to give him credits?
Co-authored-by: Azat Khuzhin <[email protected]>
after `useful_indices` has been built. I've added some checks make sure we have a valid query context
I think it would be great to add that to ensure the original contributor gets credit. Do we add the contributor's name to a git commit? How do we do this? |
|
Mention in the changelog entry, e.g., "Original author: @..." |
Co-authored-by: Azat Khuzhin <[email protected]>
|
Hi @grantholly-clickhouse, |
| throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have query access info"); | ||
|
|
||
| std::lock_guard lock(query_access_info->mutex); | ||
| query_access_info->skip_indices.emplace(full_table_name + "." + skip_index_name); |
There was a problem hiding this comment.
addSkipIndexAccessInfo concatenates <db.table>. and skip_index_name without quoting. For quoted index identifiers (for example names with dots or reserved words), system.query_log.skip_indices can become ambiguous or incorrect. Please use backQuoteIfNeed(skip_index_name) here, consistent with other query access info fields.
| if (!skip_indexes.useful_indices.empty() && context->hasQueryContext()) | ||
| { | ||
| auto query_context = context->getQueryContext(); | ||
| for (const auto & idx : skip_indexes.useful_indices) |
There was a problem hiding this comment.
This logs every entry from skip_indexes.useful_indices before per-part checks. Some of these can be skipped for all parts by can_use_index/short-circuiting, so query_log.skip_indices may report an index as used even when it filtered nothing. Please log only indices actually applied (for example, based on skip_index_used_in_part or final per-index stats).
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 92.31% (72/78) |
ecac6cc
Changelog category (leave one):
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 @pheepaDocumentation 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
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.
Note
Medium Risk
Adds a new
system.query_logcolumn and populates it from MergeTree skip-index filtering, which changes query log schema and touches MergeTree index analysis paths. Risk is mostly around correctness/compatibility of log output and potential overhead when collecting index names.Overview
Adds a new
skip_indicesArray(LowCardinality(String)) column tosystem.query_logand documents it inquery_log.md.Plumbs skip-index usage through
Context::QueryAccessInfoandQueryLogElement, and records fully-qualified skip index names when MergeTree skip indexes are actually used to filter ranges (MergeTreeDataSelectExecutor). Includes a new stateless test validatingskip_indicesoutput for simple filters and JOIN scenarios.Written by Cursor Bugbot for commit b235a3b. This will update automatically on new commits. Configure here.