Skip to content

sp_QueryReproBuilder: intersect include filters; add hash/handle filters#810

Merged
erikdarlingdata merged 1 commit into
devfrom
fix/queryreprobuilder-include-filters
Jun 19, 2026
Merged

sp_QueryReproBuilder: intersect include filters; add hash/handle filters#810
erikdarlingdata merged 1 commit into
devfrom
fix/queryreprobuilder-include-filters

Conversation

@erikdarlingdata

Copy link
Copy Markdown
Owner

Summary

Fixes a filter-widening bug in sp_QueryReproBuilder and ports the identifier filters from sp_QuickieStore.

Bug fix — include filters were unioned instead of intersected

@include_plan_ids and @include_query_ids both fed a single #include_plan_ids table checked by one EXISTS, combining with OR. Passing a specific plan id alongside its query id re-added every sibling plan, erasing the plan-id filter ("uses all available"). Include filters now intersect (AND across filters, OR within a comma-separated list) via a seed-or-intersect model. Ignore filters keep union semantics, which is correct for exclusion.

New identifier filters (ported from sp_QuickieStore)

@include/@ignore × query_hashes, plan_hashes, sql_handles — hex strings parsed to binary(8)/varbinary(64). Params, NULLIF normalization, temp tables, resolution, final WHERE gates, @help, and the README are all updated. sp_QuickieStore itself is untouched. All filter resolution stays gated under @query_plan_xml IS NULL, so direct-XML mode is unaffected.

Test plan

Installed cleanly on SQL2022; verified end-to-end against StackOverflow2013 Query Store data:

  • query_id + plan_id (the reported bug) → returns only the requested plan, both parameter orders
  • query_hash → 12 plans (incl. a hash-twin query); sql_handle → 11 (exact statement, correctly more specific); plan_hash → the single plan
  • include intersections (query_hash+plan_id, query_hash+plan_hash) → narrow to one plan
  • ignore: plan_hashes drops one plan (11→10); query_hashes/sql_handles exclude the whole query (→0)

No version/date bump and no changes to the auto-generated Install-All bundle.

🤖 Generated with Claude Code

Fix include-filter widening: @include_plan_ids and @include_query_ids both
fed a single #include_plan_ids table checked by one EXISTS, so they combined
with OR. Passing a specific plan id alongside its query id re-added every
sibling plan, erasing the plan-id filter. Include filters now intersect
(AND across filters, OR within a list) via a seed-or-intersect model: the
first supplied filter seeds the set, each later filter deletes non-matching
plans. Ignore filters keep union semantics (correct for exclusion).

Port identifier filters from sp_QuickieStore: @include/@ignore_query_hashes,
_plan_hashes, and _sql_handles (hex parsed to binary(8)/varbinary(64)).
Wires through params, NULLIF normalization, temp tables, resolution, final
WHERE gates, @help, and the README. All filter resolution stays gated under
@query_plan_xml IS NULL so direct-XML mode is unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 2396e86 into dev Jun 19, 2026
5 checks passed
@erikdarlingdata erikdarlingdata deleted the fix/queryreprobuilder-include-filters branch June 19, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant