@@ -38,7 +38,7 @@ ALTER PROCEDURE dbo.sp_BlitzIndex
3838 @SortOrder NVARCHAR (50 ) = NULL , /* Only affects @Mode = 2. */
3939 @SortDirection NVARCHAR (4 ) = ' DESC' , /* Only affects @Mode = 2. */
4040 @Help TINYINT = 0 ,
41- @Debug BIT = 0 ,
41+ @Debug BIT = 0 ,
4242 @Version VARCHAR (30 ) = NULL OUTPUT ,
4343 @VersionDate DATETIME = NULL OUTPUT ,
4444 @VersionCheckMode BIT = 0
@@ -105,7 +105,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
105105OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
106106SOFTWARE.
107107' ;
108- RETURN ;
108+ return ;
109109END ; /* @Help = 1 */
110110
111111DECLARE @ScriptVersionName NVARCHAR (50 );
@@ -253,9 +253,14 @@ IF OBJECT_ID('tempdb..#CheckConstraints') IS NOT NULL
253253
254254IF OBJECT_ID (' tempdb..#FilteredIndexes' ) IS NOT NULL
255255 DROP TABLE #FilteredIndexes;
256-
256+
257257IF OBJECT_ID (' tempdb..#Ignore_Databases' ) IS NOT NULL
258258 DROP TABLE #Ignore_Databases
259+
260+ IF OBJECT_ID (' tempdb..#H' ) IS NOT NULL
261+ DROP TABLE #H
262+ IF OBJECT_ID (' tempdb..#OS' ) IS NOT NULL
263+ DROP TABLE #OS
259264
260265 RAISERROR (N ' Create temp tables.' ,0 ,1 ) WITH NOWAIT ;
261266 CREATE TABLE #BlitzIndexResults
@@ -1065,6 +1070,8 @@ FROM sys.databases
10651070-- --------------------------------------
10661071BEGIN TRY
10671072 BEGIN
1073+ declare @d varchar (19 ) = convert (varchar (19 ), getdate (), 121 );
1074+ RAISERROR (N ' starting at %s' ,0 ,1 , @d) WITH NOWAIT ;
10681075
10691076 -- Validate SQL Server Version
10701077
@@ -1160,7 +1167,7 @@ BEGIN TRY
11601167 -- insert columns for clustered indexes and heaps
11611168 -- collect info on identity columns for this one
11621169 SET @dsql = N' /* sp_BlitzIndex */
1163- SET LOCK_TIMEOUT 1000 ; /* To fix locking bug in sys.identity_columns. See Github issue #2176. */
1170+ -- SET LOCK_TIMEOUT 10000 ; /* To fix locking bug in sys.identity_columns. See Github issue #2176. */
11641171 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
11651172 SELECT ' + CAST (@DatabaseID AS NVARCHAR (16 )) + ' ,
11661173 s.name,
@@ -1435,40 +1442,100 @@ BEGIN TRY
14351442
14361443 -- NOTE: If you want to use the newer syntax for 2012+, you'll have to change 2147483647 to 11 on line ~819
14371444 -- This change was made because on a table with lots of paritions, the OUTER APPLY was crazy slow.
1438- SET @dsql = N' SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
1445+ DROP TABLE if exists #h
1446+ create table #h
1447+ (
1448+ database_id smallint not null
1449+ , object_id int not null
1450+ , sname sysname NULL
1451+ , index_id int
1452+ , partition_number int
1453+ , partition_id bigint
1454+ , row_count bigint
1455+ , reserved_MB bigint
1456+ , reserved_LOB_MB bigint
1457+ , reserved_row_overflow_MB bigint
1458+ , lock_escalation_desc varchar (1000 )/* ?*/
1459+ , data_compression_desc varchar (100 )/* ?*/
1460+ , reserved_dictionary_MB bigint
1461+ )
1462+ drop TABLE if exists #os
1463+ create table #os
1464+ (
1465+ database_id smallint not null
1466+ , object_id int not null
1467+ , index_id int
1468+ , partition_number int
1469+ , hobt_id bigint
1470+ , leaf_insert_count bigint
1471+ , leaf_delete_count bigint
1472+ , leaf_update_count bigint
1473+ , leaf_ghost_count bigint
1474+ , nonleaf_insert_count bigint
1475+ , nonleaf_delete_count bigint
1476+ , nonleaf_update_count bigint
1477+ , leaf_allocation_count bigint
1478+ , nonleaf_allocation_count bigint
1479+ , leaf_page_merge_count bigint
1480+ , nonleaf_page_merge_count bigint
1481+ , range_scan_count bigint
1482+ , singleton_lookup_count bigint
1483+ , forwarded_fetch_count bigint
1484+ , lob_fetch_in_pages bigint
1485+ , lob_fetch_in_bytes bigint
1486+ , lob_orphan_create_count bigint
1487+ , lob_orphan_insert_count bigint
1488+ , row_overflow_fetch_in_pages bigint
1489+ , row_overflow_fetch_in_bytes bigint
1490+ , column_value_push_off_row_count bigint
1491+ , column_value_pull_in_row_count bigint
1492+ , row_lock_count bigint
1493+ , row_lock_wait_count bigint
1494+ , row_lock_wait_in_ms bigint
1495+ , page_lock_count bigint
1496+ , page_lock_wait_count bigint
1497+ , page_lock_wait_in_ms bigint
1498+ , index_lock_promotion_attempt_count bigint
1499+ , index_lock_promotion_count bigint
1500+ , page_latch_wait_count bigint
1501+ , page_latch_wait_in_ms bigint
1502+ , page_io_latch_wait_count bigint
1503+ , page_io_latch_wait_in_ms bigint
1504+ , tree_page_latch_wait_count bigint
1505+ , tree_page_latch_wait_in_ms bigint
1506+ , tree_page_io_latch_wait_count bigint
1507+ , tree_page_io_latch_wait_in_ms bigint
1508+ , page_compression_attempt_count bigint
1509+ , page_compression_success_count bigint
1510+ , version_generated_inrow bigint
1511+ , version_generated_offrow bigint
1512+ , ghost_version_inrow bigint
1513+ , ghost_version_offrow bigint
1514+ , insert_over_ghost_version_inrow bigint
1515+ , insert_over_ghost_version_offrow bigint
1516+ )
1517+
1518+ SET @dsql = N'
1519+ declare @d varchar(19) = convert(varchar(19), getdate(), 121)
1520+ RAISERROR (N'' start getting data into #h at %s'' ,0,1, @d) WITH NOWAIT;
1521+ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
1522+ insert into #h
1523+ (
1524+ database_id, object_id, sname, index_id, partition_number, partition_id, row_count, reserved_MB, reserved_LOB_MB, reserved_row_overflow_MB, lock_escalation_desc, data_compression_desc, reserved_dictionary_MB
1525+ )
14391526 SELECT ' + CAST (@DatabaseID AS NVARCHAR (10 )) + N' AS database_id,
14401527 ps.object_id,
1441- s.name,
1528+ s.name as sname ,
14421529 ps.index_id,
14431530 ps.partition_number,
1531+ ps.partition_id,
14441532 ps.row_count,
14451533 ps.reserved_page_count * 8. / 1024. AS reserved_MB,
14461534 ps.lob_reserved_page_count * 8. / 1024. AS reserved_LOB_MB,
14471535 ps.row_overflow_reserved_page_count * 8. / 1024. AS reserved_row_overflow_MB,
14481536 le.lock_escalation_desc,
14491537 ' + CASE WHEN @SQLServerProductVersion NOT LIKE ' 9%' THEN N ' par.data_compression_desc ' ELSE N ' null as data_compression_desc ' END + N' ,
1450- SUM(os.leaf_insert_count),
1451- SUM(os.leaf_delete_count),
1452- SUM(os.leaf_update_count),
1453- SUM(os.range_scan_count),
1454- SUM(os.singleton_lookup_count),
1455- SUM(os.forwarded_fetch_count),
1456- SUM(os.lob_fetch_in_pages),
1457- SUM(os.lob_fetch_in_bytes),
1458- SUM(os.row_overflow_fetch_in_pages),
1459- SUM(os.row_overflow_fetch_in_bytes),
1460- SUM(os.row_lock_count),
1461- SUM(os.row_lock_wait_count),
1462- SUM(os.row_lock_wait_in_ms),
1463- SUM(os.page_lock_count),
1464- SUM(os.page_lock_wait_count),
1465- SUM(os.page_lock_wait_in_ms),
1466- SUM(os.index_lock_promotion_attempt_count),
1467- SUM(os.index_lock_promotion_count),
1468- SUM(os.page_latch_wait_count),
1469- SUM(os.page_latch_wait_in_ms),
1470- SUM(os.page_io_latch_wait_count),
1471- SUM(os.page_io_latch_wait_in_ms), ' ;
1538+ ' ;
14721539
14731540 /* Get columnstore dictionary size - more info: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/issues/2585 */
14741541 IF EXISTS (SELECT * FROM sys .all_objects WHERE name = ' column_store_dictionaries' )
@@ -1484,9 +1551,6 @@ BEGIN TRY
14841551 AND so.is_ms_shipped = 0 /*Exclude objects shipped by Microsoft*/
14851552 AND so.type <> '' TF'' /*Exclude table valued functions*/
14861553 JOIN ' + QUOTENAME (@DatabaseName) + N' .sys.schemas AS s ON s.schema_id = so.schema_id
1487- LEFT JOIN ' + QUOTENAME (@DatabaseName) + N ' .sys.dm_db_index_operational_stats('
1488- + CAST (@DatabaseID AS NVARCHAR (10 )) + N' , NULL, NULL,NULL) AS os ON
1489- ps.object_id=os.object_id and ps.index_id=os.index_id and ps.partition_number=os.partition_number
14901554 OUTER APPLY (SELECT st.lock_escalation_desc
14911555 FROM ' + QUOTENAME (@DatabaseName) + N' .sys.tables st
14921556 WHERE st.object_id = ps.object_id
@@ -1506,7 +1570,123 @@ BEGIN TRY
15061570 le.lock_escalation_desc,
15071571 ' + CASE WHEN @SQLServerProductVersion NOT LIKE ' 9%' THEN N ' par.data_compression_desc ' ELSE N ' null as data_compression_desc ' END + N'
15081572 ORDER BY ps.object_id, ps.index_id, ps.partition_number
1509- OPTION ( RECOMPILE );
1573+ /*OPTION ( RECOMPILE );*/
1574+ OPTION ( RECOMPILE , min_grant_percent = 1);
1575+
1576+ set @d = convert(varchar(19), getdate(), 121)
1577+ RAISERROR (N'' start getting data into #os at %s.'' ,0,1, @d) WITH NOWAIT;
1578+
1579+ insert into #os
1580+ (
1581+ database_id
1582+ , object_id
1583+ , index_id
1584+ , partition_number
1585+ , hobt_id
1586+ , leaf_insert_count
1587+ , leaf_delete_count
1588+ , leaf_update_count
1589+ , leaf_ghost_count
1590+ , nonleaf_insert_count
1591+ , nonleaf_delete_count
1592+ , nonleaf_update_count
1593+ , leaf_allocation_count
1594+ , nonleaf_allocation_count
1595+ , leaf_page_merge_count
1596+ , nonleaf_page_merge_count
1597+ , range_scan_count
1598+ , singleton_lookup_count
1599+ , forwarded_fetch_count
1600+ , lob_fetch_in_pages
1601+ , lob_fetch_in_bytes
1602+ , lob_orphan_create_count
1603+ , lob_orphan_insert_count
1604+ , row_overflow_fetch_in_pages
1605+ , row_overflow_fetch_in_bytes
1606+ , column_value_push_off_row_count
1607+ , column_value_pull_in_row_count
1608+ , row_lock_count
1609+ , row_lock_wait_count
1610+ , row_lock_wait_in_ms
1611+ , page_lock_count
1612+ , page_lock_wait_count
1613+ , page_lock_wait_in_ms
1614+ , index_lock_promotion_attempt_count
1615+ , index_lock_promotion_count
1616+ , page_latch_wait_count
1617+ , page_latch_wait_in_ms
1618+ , page_io_latch_wait_count
1619+ , page_io_latch_wait_in_ms
1620+ , tree_page_latch_wait_count
1621+ , tree_page_latch_wait_in_ms
1622+ , tree_page_io_latch_wait_count
1623+ , tree_page_io_latch_wait_in_ms
1624+ , page_compression_attempt_count
1625+ , page_compression_success_count
1626+ , version_generated_inrow
1627+ , version_generated_offrow
1628+ , ghost_version_inrow
1629+ , ghost_version_offrow
1630+ , insert_over_ghost_version_inrow
1631+ , insert_over_ghost_version_offrow
1632+ )
1633+
1634+ select os.database_id
1635+ , os.object_id
1636+ , os.index_id
1637+ , os.partition_number
1638+ , os.hobt_id
1639+ , os.leaf_insert_count
1640+ , os.leaf_delete_count
1641+ , os.leaf_update_count
1642+ , os.leaf_ghost_count
1643+ , os.nonleaf_insert_count
1644+ , os.nonleaf_delete_count
1645+ , os.nonleaf_update_count
1646+ , os.leaf_allocation_count
1647+ , os.nonleaf_allocation_count
1648+ , os.leaf_page_merge_count
1649+ , os.nonleaf_page_merge_count
1650+ , os.range_scan_count
1651+ , os.singleton_lookup_count
1652+ , os.forwarded_fetch_count
1653+ , os.lob_fetch_in_pages
1654+ , os.lob_fetch_in_bytes
1655+ , os.lob_orphan_create_count
1656+ , os.lob_orphan_insert_count
1657+ , os.row_overflow_fetch_in_pages
1658+ , os.row_overflow_fetch_in_bytes
1659+ , os.column_value_push_off_row_count
1660+ , os.column_value_pull_in_row_count
1661+ , os.row_lock_count
1662+ , os.row_lock_wait_count
1663+ , os.row_lock_wait_in_ms
1664+ , os.page_lock_count
1665+ , os.page_lock_wait_count
1666+ , os.page_lock_wait_in_ms
1667+ , os.index_lock_promotion_attempt_count
1668+ , os.index_lock_promotion_count
1669+ , os.page_latch_wait_count
1670+ , os.page_latch_wait_in_ms
1671+ , os.page_io_latch_wait_count
1672+ , os.page_io_latch_wait_in_ms
1673+ , os.tree_page_latch_wait_count
1674+ , os.tree_page_latch_wait_in_ms
1675+ , os.tree_page_io_latch_wait_count
1676+ , os.tree_page_io_latch_wait_in_ms
1677+ , os.page_compression_attempt_count
1678+ , os.page_compression_success_count
1679+ , os.version_generated_inrow
1680+ , os.version_generated_offrow
1681+ , os.ghost_version_inrow
1682+ , os.ghost_version_offrow
1683+ , os.insert_over_ghost_version_inrow
1684+ , os.insert_over_ghost_version_offrow
1685+ from ' + QUOTENAME (@DatabaseName) + N ' .sys.dm_db_index_operational_stats('+ CAST (@DatabaseID AS NVARCHAR (10 )) + ' , NULL, NULL,NULL) AS os
1686+ OPTION ( RECOMPILE , min_grant_percent = 1);
1687+
1688+ set @d = convert(varchar(19), getdate(), 121)
1689+ RAISERROR (N'' finished getting data into #os at %s.'' ,0,1, @d) WITH NOWAIT;
15101690 ' ;
15111691 END ;
15121692 ELSE
@@ -1605,6 +1785,7 @@ BEGIN TRY
16051785 PRINT SUBSTRING (@dsql, 32000 , 36000 );
16061786 PRINT SUBSTRING (@dsql, 36000 , 40000 );
16071787 END ;
1788+ EXEC sp_executesql @dsql;
16081789 INSERT #IndexPartitionSanity ( [database_id],
16091790 [object_id],
16101791 [schema_name],
@@ -1639,8 +1820,35 @@ BEGIN TRY
16391820 page_io_latch_wait_count,
16401821 page_io_latch_wait_in_ms,
16411822 reserved_dictionary_MB)
1642- EXEC sp_executesql @dsql;
1643-
1823+ select h .database_id , h .object_id , h .sname , h .index_id , h .partition_number , h .row_count , h .reserved_MB , h .reserved_LOB_MB , h .reserved_row_overflow_MB , h .lock_escalation_desc , h .data_compression_desc ,
1824+ SUM (os .leaf_insert_count ),
1825+ SUM (os .leaf_delete_count ),
1826+ SUM (os .leaf_update_count ),
1827+ SUM (os .range_scan_count ),
1828+ SUM (os .singleton_lookup_count ),
1829+ SUM (os .forwarded_fetch_count ),
1830+ SUM (os .lob_fetch_in_pages ),
1831+ SUM (os .lob_fetch_in_bytes ),
1832+ SUM (os .row_overflow_fetch_in_pages ),
1833+ SUM (os .row_overflow_fetch_in_bytes ),
1834+ SUM (os .row_lock_count ),
1835+ SUM (os .row_lock_wait_count ),
1836+ SUM (os .row_lock_wait_in_ms ),
1837+ SUM (os .page_lock_count ),
1838+ SUM (os .page_lock_wait_count ),
1839+ SUM (os .page_lock_wait_in_ms ),
1840+ SUM (os .index_lock_promotion_attempt_count ),
1841+ SUM (os .index_lock_promotion_count ),
1842+ SUM (os .page_latch_wait_count ),
1843+ SUM (os .page_latch_wait_in_ms ),
1844+ SUM (os .page_io_latch_wait_count ),
1845+ SUM (os .page_io_latch_wait_in_ms )
1846+ ,COALESCE ((SELECT SUM (dict .on_disk_size / 1024 .0 / 1024 ) FROM [DataWarehouse].sys .column_store_dictionaries dict WHERE dict .partition_id = h .partition_id ),0 ) AS reserved_dictionary_MB
1847+ from #h h
1848+ left JOIN #os as os ON
1849+ h .object_id = os .object_id and h .index_id = os .index_id and h .partition_number = os .partition_number
1850+ group by h .database_id , h .object_id , h .sname , h .index_id , h .partition_number , h .partition_id , h .row_count , h .reserved_MB , h .reserved_LOB_MB , h .reserved_row_overflow_MB , h .lock_escalation_desc , h .data_compression_desc
1851+
16441852 END ; -- End Check For @SkipPartitions = 0
16451853
16461854
@@ -2591,7 +2799,6 @@ SELECT
25912799FROM #IndexSanity;
25922800
25932801RAISERROR (N ' Populate #PartitionCompressionInfo.' ,0 ,1 ) WITH NOWAIT ;
2594- IF OBJECT_ID (' tempdb..#maps' ) IS NOT NULL DROP TABLE #maps;
25952802WITH maps
25962803 AS
25972804 (
@@ -2606,7 +2813,6 @@ SELECT *
26062813INTO #maps
26072814FROM maps;
26082815
2609- IF OBJECT_ID (' tempdb..#grps' ) IS NOT NULL DROP TABLE #grps;
26102816WITH grps
26112817 AS
26122818 (
@@ -6178,7 +6384,8 @@ BEGIN
61786384
61796385
61806386 END ; /* End @Mode=3 (index detail)*/
6181-
6387+ set @d = convert (varchar (19 ), getdate (), 121 );
6388+ RAISERROR (N ' finishing at %s' ,0 ,1 , @d) WITH NOWAIT ;
61826389END /* End @TableName IS NULL (mode 0/1/2/3/4) */
61836390END TRY
61846391
@@ -6197,4 +6404,3 @@ BEGIN CATCH
61976404
61986405 RETURN ;
61996406 END CATCH ;
6200- GO
0 commit comments