You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IF (EXISTS(SELECT*FROM @ActionsPreferred) OR @UpdateStatistics ISNOTNULL) AND (SYSDATETIME() <DATEADD(SECOND,@TimeLimit,@StartTime) OR @TimeLimit ISNULL)
1551
1559
BEGIN
1552
1560
SET @CurrentCommand ='SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;'
IFEXISTS(SELECT*FROM @ActionsPreferred) OR @UpdateStatistics IN('ALL','INDEX')
@@ -1592,6 +1600,7 @@ BEGIN
1592
1600
+', '+CASEWHEN @PartitionLevel ='Y'THEN'partitions.partition_id AS PartitionID'WHEN @PartitionLevel ='N'THEN'NULL AS PartitionID'END
1593
1601
+', '+CASEWHEN @PartitionLevel ='Y'THEN'partitions.partition_number AS PartitionNumber'WHEN @PartitionLevel ='N'THEN'NULL AS PartitionNumber'END
1594
1602
+', '+CASEWHEN @PartitionLevel ='Y'THEN'IndexPartitions.partition_count AS PartitionCount'WHEN @PartitionLevel ='N'THEN'NULL AS PartitionCount'END
1603
+
+', '+CASEWHEN @Version >=13THEN'CASE WHEN external_tables.name IS NULL THEN 0 ELSE 1 END 'ELSE'0 'END+'as isExternalTable '
1595
1604
+', 0 AS [Order]'
1596
1605
+', 0 AS Selected'
1597
1606
+', 0 AS Completed'
@@ -1600,6 +1609,12 @@ BEGIN
1600
1609
+' INNER JOIN sys.schemas schemas ON objects.[schema_id] = schemas.[schema_id]'
1601
1610
+' LEFT OUTER JOIN sys.tables tables ON objects.[object_id] = tables.[object_id]'
1602
1611
+' LEFT OUTER JOIN sys.stats stats ON indexes.[object_id] = stats.[object_id] AND indexes.[index_id] = stats.[stats_id]'
1612
+
1613
+
IF @Version >=13
1614
+
BEGIN
1615
+
SET @CurrentCommand +=' LEFT OUTER JOIN sys.external_tables external_tables ON objects.[object_id] = external_tables.[object_id] '
1616
+
END
1617
+
1603
1618
IF @PartitionLevel ='Y'
1604
1619
BEGIN
1605
1620
SET @CurrentCommand = @CurrentCommand +' LEFT OUTER JOIN sys.partitions partitions ON indexes.[object_id] = partitions.[object_id] AND indexes.index_id = partitions.index_id'
@@ -1643,6 +1658,7 @@ BEGIN
1643
1658
+', NULL AS PartitionID'
1644
1659
+', '+CASEWHEN @PartitionLevelStatistics =1THEN'dm_db_incremental_stats_properties.partition_number'ELSE'NULL'END+' AS PartitionNumber'
1645
1660
+', NULL AS PartitionCount'
1661
+
+', '+CASEWHEN @Version >=13THEN'CASE WHEN external_tables.name IS NULL THEN 0 ELSE 1 END 'ELSE'0 'END+'as isExternalTable '
1646
1662
+', 0 AS [Order]'
1647
1663
+', 0 AS Selected'
1648
1664
+', 0 AS Completed'
@@ -1651,6 +1667,11 @@ BEGIN
1651
1667
+' INNER JOIN sys.schemas schemas ON objects.[schema_id] = schemas.[schema_id]'
1652
1668
+' LEFT OUTER JOIN sys.tables tables ON objects.[object_id] = tables.[object_id]'
1653
1669
1670
+
IF @Version >=13
1671
+
BEGIN
1672
+
SET @CurrentCommand +=' LEFT OUTER JOIN sys.external_tables external_tables ON objects.[object_id] = external_tables.[object_id] '
1673
+
END
1674
+
1654
1675
IF @PartitionLevelStatistics =1
1655
1676
BEGIN
1656
1677
SET @CurrentCommand = @CurrentCommand +' OUTER APPLY sys.dm_db_incremental_stats_properties(stats.object_id, stats.stats_id) dm_db_incremental_stats_properties'
@@ -1661,9 +1682,16 @@ BEGIN
1661
1682
+' AND NOT EXISTS(SELECT * FROM sys.indexes indexes WHERE indexes.[object_id] = stats.[object_id] AND indexes.index_id = stats.stats_id)'
1662
1683
END
1663
1684
1664
-
SET @CurrentCommand = @CurrentCommand +') IndexesStatistics'
1685
+
SET @CurrentCommand = @CurrentCommand +') IndexesStatistics '
1686
+
SET @CurrentCommand = @CurrentCommand +'WHERE 1=1 '
1687
+
1688
+
IF @ExternalTables <>'REBUILD'OR (@ExternalTables ='REBUILD'AND @Version <13)
1689
+
BEGIN
1690
+
SET @CurrentCommand = @CurrentCommand +'AND isExternalTable=0'
SET @CurrentCommand +='DROP STATISTICS '+QUOTENAME(@CurrentSchemaName) +'.'+QUOTENAME(@CurrentObjectName) +'.'+QUOTENAME(@CurrentStatisticsName) +';'
2276
+
SET @CurrentCommand +='CREATE STATISTICS '+QUOTENAME(@CurrentStatisticsName) +' ON '+QUOTENAME(@CurrentSchemaName) +'.'+QUOTENAME(@CurrentObjectName) +'('
SET @CurrentCommand =LEFT(@CurrentCommand, LEN(@CurrentCommand)-1) +') '
2282
+
2283
+
DELETEFROM @tmpExternalTableColumnList
2284
+
2285
+
END
2286
+
2287
+
IF @CurrentMaxDOP ISNOTNULLAND ((@Version >=12.06024AND @Version <13) OR (@Version >=13.05026AND @Version <14) OR @Version >=14.030154) AND @CurrentIsExtenalTable =0
0 commit comments