olahallengren / sql-server-maintenance-solution

SQL Server Maintenance Solution
https://ola.hallengren.com
MIT License
2.91k stars 756 forks source link

Indexoptimize procedure fails when updating statistics on partitioned tables #828

Open BernaLudo opened 3 weeks ago

BernaLudo commented 3 weeks ago

wrong order options in statement

SQL Server version and edition Execute SELECT @@VERSION Microsoft SQL Server 2022(RTM-CU9) (KB5030731) - 16.0.4085.2 (x64)

Version of the script Check the header of the stored procedure

--// Source: https://ola.hallengren.com //-- --// License: https://ola.hallengren.com/license.html //-- --// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //-- --// Version: 2024-10-27 11:48:54 //--

What command are you executing? EXECUTE dbo.IndexOptimize @Databases='SentryOne', @FragmentationLow = NULL, @FragmentationMedium = NULL, @FragmentationHigh = NULL, @UpdateStatistics = 'ALL', @OnlyModifiedStatistics = 'Y'

What output are you getting? Date and time: 2024-10-30 09:47:51 Database context: [SentryOne] Command: UPDATE STATISTICS [dbo].[PerformanceAnalysisDataRollup12] [_WA_Sys_00000007_79A8DF5A] WITH RESAMPLE, NORECOMPUTE ON PARTITIONS(1) Comment: ObjectType: Table, IndexType: Column, Incremental: Y, RowCount: 2146316, ModificationCounter: 39551883679863 Msg 50000, Level 16, State 1, Procedure dbo.CommandExecute, Line 234 [Batch Start Line 0] Msg 155, 'NORECOMPUTE' is not a recognized UPDATE STATISTICS option. Outcome: Failed Duration: 00:00:00 Date and time: 2024-10-30 09:47:51

The order of the options in the UPDATE STATISTICS command is wrong. If the command would be like this, it would be working: UPDATE STATISTICS [dbo].[PerformanceAnalysisDataRollup12] [_WA_Sys_00000007_79A8DF5A] WITH RESAMPLE, NORECOMPUTE ON PARTITIONS(1)

griffitmatt commented 3 weeks ago

Hi Bernaludo

I have been able to reproduce the error as well.

Changing the order of the command will resolve the issue. ie norecompute first followed by recompile.

UPDATE STATISTICS [dbo].[PerformanceAnalysisDataRollup12] [_WA_Sys_00000007_79A8DF5A] WITH NORECOMPUTE,RESAMPLE, ON PARTITIONS(1)

Have a look here for the workaround. - https://github.com/olahallengren/sql-server-maintenance-solution/issues/285