sp_QueryReproBuilder: intersect include filters; add hash/handle filters#810
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a filter-widening bug in
sp_QueryReproBuilderand ports the identifier filters fromsp_QuickieStore.Bug fix — include filters were unioned instead of intersected
@include_plan_idsand@include_query_idsboth fed a single#include_plan_idstable checked by oneEXISTS, 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 tobinary(8)/varbinary(64). Params,NULLIFnormalization, temp tables, resolution, finalWHEREgates,@help, and the README are all updated.sp_QuickieStoreitself 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 ordersquery_hash→ 12 plans (incl. a hash-twin query);sql_handle→ 11 (exact statement, correctly more specific);plan_hash→ the single planquery_hash+plan_id,query_hash+plan_hash) → narrow to one planplan_hashesdrops one plan (11→10);query_hashes/sql_handlesexclude the whole query (→0)No version/date bump and no changes to the auto-generated
Install-Allbundle.🤖 Generated with Claude Code