@@ -168,10 +168,11 @@ BEGIN
168168 total_worker_time_delta /
169169 NULLIF (sample_interval_seconds, 0 ) / 1000 .
170170 ),
171- /* Query text and execution plan*/
172- query_text nvarchar (MAX ) NULL ,
173- query_plan_text nvarchar (MAX ) NULL ,
174- query_plan xml NULL ,
171+ /* Query text and execution plan (compressed with COMPRESS/DECOMPRESS)*/
172+ query_text varbinary (max ) NULL ,
173+ query_plan_text varbinary (max ) NULL ,
174+ /* Deduplication hash for skipping unchanged rows*/
175+ row_hash binary (32 ) NULL ,
175176 CONSTRAINT
176177 PK_query_stats
177178 PRIMARY KEY CLUSTERED
@@ -183,6 +184,34 @@ BEGIN
183184 PRINT ' Created collect.query_stats table' ;
184185END ;
185186
187+ /*
188+ 2b. Query Stats Dedup Tracking
189+ One row per natural key, updated on each collection cycle
190+ */
191+ IF OBJECT_ID (N ' collect.query_stats_latest_hash' , N ' U' ) IS NULL
192+ BEGIN
193+ CREATE TABLE
194+ collect .query_stats_latest_hash
195+ (
196+ sql_handle varbinary (64 ) NOT NULL ,
197+ statement_start_offset integer NOT NULL ,
198+ statement_end_offset integer NOT NULL ,
199+ plan_handle varbinary (64 ) NOT NULL ,
200+ row_hash binary (32 ) NOT NULL ,
201+ last_seen datetime2 (7 ) NOT NULL
202+ DEFAULT SYSDATETIME (),
203+ CONSTRAINT
204+ PK_query_stats_latest_hash
205+ PRIMARY KEY CLUSTERED
206+ (sql_handle , statement_start_offset,
207+ statement_end_offset, plan_handle)
208+ WITH
209+ (DATA_COMPRESSION = PAGE )
210+ );
211+
212+ PRINT ' Created collect.query_stats_latest_hash table' ;
213+ END ;
214+
186215/*
1872163. Memory Pressure
188217*/
@@ -429,9 +458,10 @@ BEGIN
429458 total_worker_time_delta /
430459 NULLIF (sample_interval_seconds, 0 ) / 1000 .
431460 ),
432- /* Execution plan*/
433- query_plan_text nvarchar (max ) NULL ,
434- query_plan xml NULL ,
461+ /* Execution plan (compressed with COMPRESS/DECOMPRESS)*/
462+ query_plan_text varbinary (max ) NULL ,
463+ /* Deduplication hash for skipping unchanged rows*/
464+ row_hash binary (32 ) NULL ,
435465 CONSTRAINT
436466 PK_procedure_stats
437467 PRIMARY KEY CLUSTERED
@@ -443,6 +473,32 @@ BEGIN
443473 PRINT ' Created collect.procedure_stats table' ;
444474END ;
445475
476+ /*
477+ 9b. Procedure Stats Dedup Tracking
478+ One row per natural key, updated on each collection cycle
479+ */
480+ IF OBJECT_ID (N ' collect.procedure_stats_latest_hash' , N ' U' ) IS NULL
481+ BEGIN
482+ CREATE TABLE
483+ collect .procedure_stats_latest_hash
484+ (
485+ database_name sysname NOT NULL ,
486+ object_id integer NOT NULL ,
487+ plan_handle varbinary (64 ) NOT NULL ,
488+ row_hash binary (32 ) NOT NULL ,
489+ last_seen datetime2 (7 ) NOT NULL
490+ DEFAULT SYSDATETIME (),
491+ CONSTRAINT
492+ PK_procedure_stats_latest_hash
493+ PRIMARY KEY CLUSTERED
494+ (database_name , object_id , plan_handle)
495+ WITH
496+ (DATA_COMPRESSION = PAGE )
497+ );
498+
499+ PRINT ' Created collect.procedure_stats_latest_hash table' ;
500+ END ;
501+
446502/*
44750310. Currently Executing Query Snapshots
448504Table is created dynamically by sp_WhoIsActive on first collection
@@ -473,7 +529,7 @@ BEGIN
473529 server_first_execution_time datetime2 (7 ) NOT NULL ,
474530 server_last_execution_time datetime2 (7 ) NOT NULL ,
475531 module_name nvarchar (261 ) NULL ,
476- query_sql_text nvarchar (max ) NULL ,
532+ query_sql_text varbinary (max ) NULL ,
477533 query_hash binary (8 ) NULL ,
478534 /* Execution count*/
479535 count_executions bigint NOT NULL ,
@@ -531,9 +587,11 @@ BEGIN
531587 last_force_failure_reason_desc nvarchar (128 ) NULL ,
532588 plan_forcing_type nvarchar (60 ) NULL ,
533589 compatibility_level smallint NULL ,
534- query_plan_text nvarchar (max ) NULL ,
535- compilation_metrics xml NULL ,
590+ query_plan_text varbinary (max ) NULL ,
591+ compilation_metrics varbinary ( max ) NULL ,
536592 query_plan_hash binary (8 ) NULL ,
593+ /* Deduplication hash for skipping unchanged rows*/
594+ row_hash binary (32 ) NULL ,
537595 CONSTRAINT
538596 PK_query_store_data
539597 PRIMARY KEY CLUSTERED
@@ -545,6 +603,32 @@ BEGIN
545603 PRINT ' Created collect.query_store_data table' ;
546604END ;
547605
606+ /*
607+ 11b. Query Store Data Dedup Tracking
608+ One row per natural key, updated on each collection cycle
609+ */
610+ IF OBJECT_ID (N ' collect.query_store_data_latest_hash' , N ' U' ) IS NULL
611+ BEGIN
612+ CREATE TABLE
613+ collect .query_store_data_latest_hash
614+ (
615+ database_name sysname NOT NULL ,
616+ query_id bigint NOT NULL ,
617+ plan_id bigint NOT NULL ,
618+ row_hash binary (32 ) NOT NULL ,
619+ last_seen datetime2 (7 ) NOT NULL
620+ DEFAULT SYSDATETIME (),
621+ CONSTRAINT
622+ PK_query_store_data_latest_hash
623+ PRIMARY KEY CLUSTERED
624+ (database_name , query_id, plan_id)
625+ WITH
626+ (DATA_COMPRESSION = PAGE )
627+ );
628+
629+ PRINT ' Created collect.query_store_data_latest_hash table' ;
630+ END ;
631+
548632/*
549633Trace analysis table - stores processed trace file data
550634*/
0 commit comments