Repository navigation
Fix SQL Server profiler row counts, system objects and procedure names - #2686
Merged
Merged
Conversation
* table_sizes: count rows from the heap or clustered index only (index_id 0 or 1). Summing every index multiplied RowCount by the number of indexes; a table with a clustered key and 9 nonclustered indexes reported 705,100 rows instead of 70,510. * tables, views, columns, routines and table_sizes (single and multi database): exclude system objects (is_ms_shipped) and the sys and cdc schemas, such as change data capture and change tracking tables and, on Azure SQL Database, sys.database_firewall_rules. * proc_stats: drop rows from the hidden Resource database (database_id 32767). They are SQL Server's own procedures, and their names never resolve. * docs: the on-premises grants are VIEW ANY DEFINITION at server level plus a user in each profiled database. With only a database-level VIEW DEFINITION, procedure names from other databases come back NULL. * tests: static guards for the three rules. Verified against SQL Server 2022, including a case-sensitive database with change data capture and change tracking, and against SQL Server 2017. Co-authored-by: Isaac <no-reply@databricks.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2686 +/- ##
=======================================
Coverage 71.40% 71.40%
=======================================
Files 109 109
Lines 10024 10024
Branches 1093 1093
=======================================
Hits 7158 7158
Misses 2648 2648
Partials 218 218 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
✅ 179/179 passed, 8 flaky, 2 skipped, 1h31m2s total Flaky tests:
Running from acceptance #5539 |
* On-premises: replace the server-wide VIEW ANY DEFINITION with VIEW DEFINITION granted in each profiled database, next to the database user the login needs anyway. Databases that aren't profiled stay out of reach. * Explain that VIEW SERVER STATE also gives the database-level VIEW DATABASE STATE that sys.dm_db_partition_stats needs, and that on SQL Server 2022 and later these grants cover the finer-grained permissions. * Drop GRANT SELECT ON SCHEMA::INFORMATION_SCHEMA from both the on-premises and Azure SQL Database recipes: every user can already query those views, and what they return depends on VIEW DEFINITION. Verified on SQL Server 2022 and 2017 with a login holding only VIEW SERVER STATE plus a user with VIEW DEFINITION in two databases: every profiler query, single and multi database, returns the same rows as sa, including procedure names. Without VIEW DEFINITION the inventory and table sizes are empty and procedure names are NULL. Co-authored-by: Isaac <no-reply@databricks.com>
gueniai
approved these changes
Oct 23, 2026
Co-authored-by: Isaac <no-reply@databricks.com>
m-abulazm
enabled auto-merge
October 23, 2026 14:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
What does this PR do?
Fixes three problems in the SQL Server profiler extract:
table_sizes.RowCountwas multiplied by the number of indexes. A table with a clustered key and 9 nonclustered indexes reported 705,100 rows instead of 70,510.sys.database_firewall_ruleson Azure SQL Database.proc_stats.OBJECT_NAMEwas empty for most rows.Relevant implementation details
table_sizescounts rows from the heap or clustered index only (index_id0 or 1). Page and size columns were already correct.tables,views,columns,routinesandtable_sizesexcludeis_ms_shippedobjects and thesysandcdcschemas. Thecdcschema is excluded too because the per-table functions change data capture generates aren't flagged as system objects.proc_statsdrops rows from the hidden Resource database (database_id32767). These are SQL Server's own procedures, whose names never resolve.VIEW SERVER STATEat server level, then a user withVIEW DEFINITIONin each profiled database. The redundantINFORMATION_SCHEMAgrant is removed from both the on-premises and Azure SQL Database recipes.Caveats/things to watch out for when reviewing:
tables,columnsandroutinesrows on databases that use change data capture or change tracking. The removed rows are all system objects.table_sizesgroups by schema but doesn't output it, so same-named tables in different schemas look like duplicates. Fixing that changes the table definition, so it's left for a separate PR.Linked issues
None.
Functionality
databricks labs lakebridge execute-database-profilerTests
Manually tested on SQL Server 2022, including a case-sensitive database with change data capture and change tracking enabled, and on SQL Server 2017. A login with only the documented grants returns the same rows as
safor every profiler query, single and multi database, on both versions. Every row the fix removes is a system object, and the row counts match the actual tables. New static checks intest_mssql_sql_rules.pyfail onmainand pass here.make testpasses.This pull request and its description were written by Isaac.