Repository navigation
Hypothetical (WHAT-IF) indexes - #104608
Conversation
|
Workflow [PR], commit [11b78f5] Summary: ✅
AI ReviewSummaryThis PR adds session-scoped hypothetical skip indexes through Findings❌ Blockers
Final Verdict❌ Changes requested. The estimator should be fixed before merge so |
|
This was fixed by #105146. Let's update the branch. |
| index_columns, | ||
| std::nullopt, | ||
| std::make_shared<std::atomic<size_t>>(0), | ||
| false, |
There was a problem hiding this comment.
EXPLAIN WHATIF should build the empirical candidate over the same row set that the SELECT would read, but this call hard-disables the lightweight-delete mask. The normal MergeTree read path uses apply_deleted_mask (true by default) to add the _row_exists filter when a part or patch has deleted rows; here those deleted rows remain in the block used by the hypothetical index aggregator. For example, after DELETE FROM t WHERE b = 42, a candidate on b can still see 42 from rows that are no longer visible to the query and report a different skip ratio/mark count than the real read contract. Please pass the effective apply_deleted_mask setting through to this source (or mark such parts unsupported) so the estimate does not depend on deleted rows.
| result.index_name = index_desc.name; | ||
| result.index_type = index_desc.type; | ||
| result.total_parts = data.getActivePartsCount(); | ||
| result.total_marks = data.getTotalMarksCount(); |
There was a problem hiding this comment.
total_marks is paired with sampled_marks in the output as sampled_marks: <baseline> / <total>, but this denominator comes from MergeTreeData::getTotalMarksCount, which iterates data_parts_by_info and includes non-active parts. After merges or mutations leave outdated parts in memory, the numerator is computed from the query's active snapshot while the denominator can include inactive marks, so the reported sampled fraction is wrong.
Please derive this from the same active/query-visible parts snapshot as the baseline analysis, or add an active-only marks helper so sampled_marks and sampled_parts use consistent denominators.
|
📊 Cloud Performance Report ✅ AI verdict: This PR is purely additive: it introduces a new EXPLAIN WHATIF variant plus CREATE/DROP HYPOTHETICAL INDEX statements, backed by a new session-scoped store and a separate estimator, alongside documentation. None of this touches the execution path that a normal ClickBench SELECT runs, so neither the flagged improvements (Q4 -18%, Q15 -13.5%) nor the flagged regressions (Q13 +12.6%, Q18 +6.2%) can plausibly be attributed to the change. All four flags have been downgraded to inconclusive as run-to-run variance. No action needed. clickbenchFlagged queries (4 of 43)
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
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 675/865 (78.03%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 4 line(s) · Uncovered code |
Adds hypothetical (what-if) indexes: virtual, session-scoped skip indexes you can attach to a
MergeTreetable to see how a real skip index would affect a query, without actually building it on disk.EXPLAIN WHATIFruns the index over the baseline-pruned granules in memory and reports the exact skip ratio plus estimated marks and bytes. If empirical is disabled (empirical = 0) or can't produce a result, the estimator falls back to column statistics; if neither is available it reports an applicability-only summary.Defined indexes are inspectable through the new
system.hypothetical_indexestable and discarded when the session ends. Existing queries against the table are unaffected.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added hypothetical (what-if) skip indexes. Use
CREATE HYPOTHETICAL INDEX ... ON t (expr) TYPE ...to define a session-scoped virtual skip index, thenEXPLAIN WHATIF SELECT ...to estimate its skip ratio and cost without materializing it. Defined indexes are visible in the newsystem.hypothetical_indexestable.Documentation entry for user-facing changes
Version info
26.6.1.1139