Skip to content

LOB compression + deduplication for query stats tables (#419)#433

Merged
erikdarlingdata merged 1 commit intodevfrom
feature/lob-compression-dedup
Mar 5, 2026
Merged

LOB compression + deduplication for query stats tables (#419)#433
erikdarlingdata merged 1 commit intodevfrom
feature/lob-compression-dedup

Conversation

@erikdarlingdata
Copy link
Owner

Summary

  • COMPRESS()/DECOMPRESS() on all LOB columns (query_text, query_plan_text, query_sql_text, compilation_metrics) — 90-91% storage reduction
  • Row hash deduplication — only INSERT rows where metrics actually changed between collection cycles, with tracking tables for efficient lookups
  • Upgrade scripts — batched DELETE WITH OUTPUT migration compresses existing data in place, frees space as it goes
  • Version bump — 2.1.0 → 2.2.0 across all four projects

Storage reduction (sql2022)

Table Before After Reduction
query_stats 2,480 MB 219 MB 91%
query_store_data 2,449 MB 236 MB 90%
procedure_stats 11 MB 1 MB 91%

Test plan

  • Clean install via CLI installer (sql2016) — 51/0, all collectors healthy
  • CLI upgrade path (sql2017, sql2019) — upgrades + installs, 0 failures
  • Manual upgrade (sql2022) — primary test with most data
  • GUI upgrade path (sql2025) — 51/0
  • All 7 reporting views return readable decompressed data
  • All 3 collectors insert compressed data with valid row_hash
  • Dedup validated: second collection with no workload change = 0 rows inserted
  • MCP tool queries return readable text and valid XML plans
  • collect_query/collect_plan flags work for fresh installs
  • MERGE dedup fix prevents duplicate key errors (caught on sql2019)
  • Dashboard logs: zero errors post-deployment across all servers

🤖 Generated with Claude Code

Databases were growing to 150-200 GB in under a week on busy servers.
LOB columns (query_text, query_plan_text, query_sql_text, compilation_metrics)
were 92-94% of storage. COMPRESS()/DECOMPRESS() achieves 90-91% reduction.

Schema changes:
- query_stats, query_store_data, procedure_stats: LOB columns changed from
  nvarchar(max)/xml to varbinary(max) with COMPRESS() on write
- Dropped unused query_plan xml columns
- Added row_hash binary(32) for deduplication
- Added tracking tables (query_stats_latest_hash, procedure_stats_latest_hash,
  query_store_data_latest_hash) for efficient hash lookups

Collector changes (08, 09, 10):
- COMPRESS() on all text/plan INSERT expressions
- collect_query/collect_plan flag support added to query_stats and procedure_stats
- HASHBYTES('SHA2_256', binary_concat) dedup: only INSERT rows where metrics changed
- MERGE source deduped with ROW_NUMBER() to prevent duplicate key errors

Read-side changes:
- All reporting views (46, 47) wrap compressed columns in DECOMPRESS()
- Dashboard C# queries updated with DECOMPRESS() in SQL strings

Upgrade path:
- Batched DELETE WITH OUTPUT migration compresses existing data in place
- IDENTITY reseed preserves ID continuity
- Old tables renamed to _old for safety (manual DROP later)

Version bump: 2.1.0 → 2.2.0 across all four projects.

Tested: clean install (sql2016), CLI upgrade (sql2017, sql2019, sql2022),
GUI upgrade (sql2025). All collectors healthy, dedup validated, all views
and MCP tools return readable decompressed data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit d2500c2 into dev Mar 5, 2026
7 checks passed
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