diff --git a/install/02_create_tables.sql b/install/02_create_tables.sql index d4e7562..83fd676 100644 --- a/install/02_create_tables.sql +++ b/install/02_create_tables.sql @@ -119,18 +119,18 @@ BEGIN max_rows bigint NOT NULL, statement_sql_handle varbinary(64) NULL, statement_context_id bigint NULL, - min_dop smallint NOT NULL, - max_dop smallint NOT NULL, + min_dop bigint NOT NULL, + max_dop bigint NOT NULL, min_grant_kb bigint NOT NULL, max_grant_kb bigint NOT NULL, min_used_grant_kb bigint NOT NULL, max_used_grant_kb bigint NOT NULL, min_ideal_grant_kb bigint NOT NULL, max_ideal_grant_kb bigint NOT NULL, - min_reserved_threads integer NOT NULL, - max_reserved_threads integer NOT NULL, - min_used_threads integer NOT NULL, - max_used_threads integer NOT NULL, + min_reserved_threads bigint NOT NULL, + max_reserved_threads bigint NOT NULL, + min_used_threads bigint NOT NULL, + max_used_threads bigint NOT NULL, total_spills bigint NOT NULL, min_spills bigint NOT NULL, max_spills bigint NOT NULL, diff --git a/install/08_collect_query_stats.sql b/install/08_collect_query_stats.sql index 98ee876..f866749 100644 --- a/install/08_collect_query_stats.sql +++ b/install/08_collect_query_stats.sql @@ -202,18 +202,18 @@ BEGIN max_rows bigint NOT NULL, statement_sql_handle varbinary(64) NULL, statement_context_id bigint NULL, - min_dop smallint NOT NULL, - max_dop smallint NOT NULL, + min_dop bigint NOT NULL, + max_dop bigint NOT NULL, min_grant_kb bigint NOT NULL, max_grant_kb bigint NOT NULL, min_used_grant_kb bigint NOT NULL, max_used_grant_kb bigint NOT NULL, min_ideal_grant_kb bigint NOT NULL, max_ideal_grant_kb bigint NOT NULL, - min_reserved_threads integer NOT NULL, - max_reserved_threads integer NOT NULL, - min_used_threads integer NOT NULL, - max_used_threads integer NOT NULL, + min_reserved_threads bigint NOT NULL, + max_reserved_threads bigint NOT NULL, + min_used_threads bigint NOT NULL, + max_used_threads bigint NOT NULL, total_spills bigint NOT NULL, min_spills bigint NOT NULL, max_spills bigint NOT NULL, diff --git a/upgrades/2.2.0-to-2.3.0/01_widen_query_stats_columns.sql b/upgrades/2.2.0-to-2.3.0/01_widen_query_stats_columns.sql new file mode 100644 index 0000000..4053e23 --- /dev/null +++ b/upgrades/2.2.0-to-2.3.0/01_widen_query_stats_columns.sql @@ -0,0 +1,71 @@ +/* +Copyright 2026 Darling Data, LLC +https://www.erikdarling.com/ + +Upgrade from 2.2.0 to 2.3.0 +Widens query_stats columns to match sys.dm_exec_query_stats DMV types: + - min_dop, max_dop: smallint -> bigint + - min_reserved_threads, max_reserved_threads: integer -> bigint + - min_used_threads, max_used_threads: integer -> bigint +Fixes arithmetic overflow error on INSERT (#547) +*/ + +SET ANSI_NULLS ON; +SET ANSI_PADDING ON; +SET ANSI_WARNINGS ON; +SET ARITHABORT ON; +SET CONCAT_NULL_YIELDS_NULL ON; +SET QUOTED_IDENTIFIER ON; +SET NUMERIC_ROUNDABORT OFF; +SET IMPLICIT_TRANSACTIONS OFF; +SET STATISTICS TIME, IO OFF; +GO + +USE PerformanceMonitor; +GO + +IF OBJECT_ID(N'collect.query_stats', N'U') IS NOT NULL +BEGIN + PRINT 'Widening collect.query_stats columns to match DMV types...'; + + IF EXISTS + ( + SELECT + 1/0 + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = N'collect' + AND TABLE_NAME = N'query_stats' + AND COLUMN_NAME = N'min_dop' + AND DATA_TYPE = N'smallint' + ) + BEGIN + ALTER TABLE collect.query_stats ALTER COLUMN min_dop bigint NOT NULL; + ALTER TABLE collect.query_stats ALTER COLUMN max_dop bigint NOT NULL; + PRINT ' min_dop, max_dop: smallint -> bigint'; + END; + + IF EXISTS + ( + SELECT + 1/0 + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = N'collect' + AND TABLE_NAME = N'query_stats' + AND COLUMN_NAME = N'min_reserved_threads' + AND DATA_TYPE = N'int' + ) + BEGIN + ALTER TABLE collect.query_stats ALTER COLUMN min_reserved_threads bigint NOT NULL; + ALTER TABLE collect.query_stats ALTER COLUMN max_reserved_threads bigint NOT NULL; + ALTER TABLE collect.query_stats ALTER COLUMN min_used_threads bigint NOT NULL; + ALTER TABLE collect.query_stats ALTER COLUMN max_used_threads bigint NOT NULL; + PRINT ' min/max_reserved_threads, min/max_used_threads: int -> bigint'; + END; + + PRINT 'Column widening complete.'; +END; +ELSE +BEGIN + PRINT 'Table collect.query_stats does not exist, skipping.'; +END; +GO diff --git a/upgrades/2.2.0-to-2.3.0/upgrade.txt b/upgrades/2.2.0-to-2.3.0/upgrade.txt new file mode 100644 index 0000000..f5596a0 --- /dev/null +++ b/upgrades/2.2.0-to-2.3.0/upgrade.txt @@ -0,0 +1 @@ +01_widen_query_stats_columns.sql