Skip to content

Commit 7108a96

Browse files
sp_QuickieStore: fix plan/object IDs leaking into query_id_list in @find_high_impact
INSERT...EXEC captures all result sets, not just the first. The batch had three SELECTs (queries, plans, objects) so plan_ids and object_ids were concatenated into #hi_id_staging_queries. Removed the extra two SELECTs since they are already executed separately below. Tested on SQL2022 against PerformanceMonitor and hammerdb_tpcc. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6bfb95a commit 7108a96

1 file changed

Lines changed: 1 addition & 23 deletions

File tree

sp_QuickieStore/sp_QuickieStore.sql

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4756,25 +4756,6 @@ SELECT DISTINCT
47564756
FROM ' + @database_name_quoted + N'.sys.query_store_query AS qsq
47574757
JOIN #hi_interesting AS i
47584758
ON qsq.query_hash = i.query_hash
4759-
OPTION(RECOMPILE);
4760-
4761-
SELECT DISTINCT
4762-
qsq.query_hash,
4763-
qsp.plan_id
4764-
FROM ' + @database_name_quoted + N'.sys.query_store_query AS qsq
4765-
JOIN ' + @database_name_quoted + N'.sys.query_store_plan AS qsp
4766-
ON qsq.query_id = qsp.query_id
4767-
JOIN #hi_interesting AS i
4768-
ON qsq.query_hash = i.query_hash
4769-
OPTION(RECOMPILE);
4770-
4771-
SELECT DISTINCT
4772-
qsq.query_hash,
4773-
qsq.object_id
4774-
FROM ' + @database_name_quoted + N'.sys.query_store_query AS qsq
4775-
JOIN #hi_interesting AS i
4776-
ON qsq.query_hash = i.query_hash
4777-
WHERE qsq.object_id > 0
47784759
OPTION(RECOMPILE);' + @nc10;
47794760

47804761
IF @debug = 1
@@ -4809,10 +4790,7 @@ OPTION(RECOMPILE);' + @nc10;
48094790
@current_table;
48104791
END;
48114792

4812-
/*
4813-
The multi-result-set approach above only inserts the first result.
4814-
Run the plan and object queries separately.
4815-
*/
4793+
/*Insert plan and object IDs separately*/
48164794
SELECT
48174795
@sql = @isolation_level;
48184796

0 commit comments

Comments
 (0)