Skip to content

Fix arithmetic overflow in query_stats collector#548

Merged
erikdarlingdata merged 2 commits intodevfrom
fix/issue-547-smallint-overflow
Mar 13, 2026
Merged

Fix arithmetic overflow in query_stats collector#548
erikdarlingdata merged 2 commits intodevfrom
fix/issue-547-smallint-overflow

Conversation

@erikdarlingdata
Copy link
Owner

Summary

  • [BUG] Arithmetic Overflow Error #547: collect.query_stats collector fails with "Arithmetic overflow error converting expression to data type smallint" because min_dop/max_dop are smallint in our schema but bigint in sys.dm_exec_query_stats
  • Also widened min/max_reserved_threads and min/max_used_threads from integer to bigint to match the DMV

Changes

  • install/02_create_tables.sql: Widened 6 columns in collect.query_stats from smallint/integer to bigint
  • install/08_collect_query_stats.sql: Same fix in the #query_stats_staging temp table
  • upgrades/2.2.0-to-2.3.0/01_widen_query_stats_columns.sql: Idempotent ALTER TABLE upgrade for existing installations

Test plan

  • Fresh install creates table with bigint columns
  • Upgrade script runs cleanly on existing 2.2.0 database
  • Query stats collector runs without overflow on SQL Server 2016 SP2

Closes #547

🤖 Generated with Claude Code

erikdarlingdata and others added 2 commits March 13, 2026 16:55
DMV sys.dm_exec_query_stats returns min_dop, max_dop, and thread
columns as bigint, but our temp table and permanent table used
smallint/integer — causing overflow on INSERT.

Widened to match actual DMV types:
- min_dop, max_dop: smallint -> bigint
- min/max_reserved_threads, min/max_used_threads: integer -> bigint

Includes upgrade script for existing 2.2.0 installations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The publish/ directory is gitignored; the type fix was already
applied to install/02_create_tables.sql (the source of truth).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 5c94d66 into dev Mar 13, 2026
7 checks passed
@erikdarlingdata erikdarlingdata deleted the fix/issue-547-smallint-overflow branch March 13, 2026 21: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