@@ -1643,24 +1643,40 @@ BEGIN TRY
16431643 AND ColumnNamesWithDataTypes.IndexColumnType = '' Included''
16441644 ) AS included_columns_with_data_type '
16451645
1646- /* Github #2780 BGO Removing SQL Server 2019's new missing index sample plan because it doesn't work yet:
1647- IF NOT EXISTS (SELECT * FROM sys.all_objects WHERE name = 'dm_db_missing_index_group_stats_query')
1648- */
1649- SET @dsql = @dsql + N ' , NULL AS sample_query_plan '
1650- /* Github #2780 BGO Removing SQL Server 2019's new missing index sample plan because it doesn't work yet:
1646+ /* Github #2780 BGO Removing SQL Server 2019's new missing index sample plan because it doesn't work yet:*/
1647+ IF NOT EXISTS
1648+ (
1649+ SELECT
1650+ 1 / 0
1651+ FROM sys .all_objects AS o
1652+ WHERE o .name = ' dm_db_missing_index_group_stats_query'
1653+ )
1654+ SELECT
1655+ @dsql + = N ' , NULL AS sample_query_plan '
1656+ /* Github #2780 BGO Removing SQL Server 2019's new missing index sample plan because it doesn't work yet:*/
16511657 ELSE
16521658 BEGIN
1653- SET @dsql = @dsql + N' , sample_query_plan = (SELECT TOP 1 p.query_plan
1654- FROM sys.dm_db_missing_index_group_stats gs
1655- CROSS APPLY (SELECT TOP 1 s.plan_handle
1656- FROM sys.dm_db_missing_index_group_stats_query q
1657- INNER JOIN sys.dm_exec_query_stats s ON q.query_plan_hash = s.query_plan_hash
1658- WHERE gs.group_handle = q.group_handle
1659- ORDER BY (q.user_seeks + q.user_scans) DESC, s.total_logical_reads DESC) q2
1660- CROSS APPLY sys.dm_exec_query_plan(q2.plan_handle) p
1661- WHERE gs.group_handle = gs.group_handle) '
1659+ SELECT
1660+ @dsql + = N'
1661+ , sample_query_plan =
1662+ (
1663+ SELECT TOP (1)
1664+ p.query_plan
1665+ FROM sys.dm_db_missing_index_group_stats gs
1666+ CROSS APPLY
1667+ (
1668+ SELECT TOP (1)
1669+ s.plan_handle
1670+ FROM sys.dm_db_missing_index_group_stats_query q
1671+ INNER JOIN sys.dm_exec_query_stats s
1672+ ON q.query_plan_hash = s.query_plan_hash
1673+ WHERE gs.group_handle = q.group_handle
1674+ ORDER BY (q.user_seeks + q.user_scans) DESC, s.total_logical_reads DESC
1675+ ) q2
1676+ CROSS APPLY sys.dm_exec_query_plan(q2.plan_handle) p
1677+ ) '
16621678 END
1663- */
1679+
16641680
16651681
16661682 SET @dsql = @dsql + N ' FROM ' + QUOTENAME (@DatabaseName) + N' .sys.dm_db_missing_index_groups ig
0 commit comments