SQL Server Compatibility Issue During Application Upgrade

Vinodkumar Kamurukuru 0 Reputation points
2024-08-07T11:47:57.64+00:00

Dear Microsoft Support Team,

We are encountering a significant performance issue related to SQL Server compatibility during an upgrade of one of our applications. Below are the details of the problem:

Issue Summary: While upgrading our application, the SQL Server compatibility level was updated from SQL Server 2016 (130) to SQL Server 2017 (140) (SSMS 2019 Version). We have observed a substantial increase in query execution time for a specific Cognos report dataset query.

Detailed Description:

  • Problem: A SQL query that previously executed within 10 minutes on SQL Server 2016 (130) now takes 5-7 hours to complete on SQL Server 2017 (140).
  • Observations: Execution Plan Analysis:
       - **SQL-2016:** WaitTimeMs = 336, WaitCount = 175,051
    
             - **SQL-2017:** WaitTimeMs = 16,561, WaitCount = 6,357,099
    
                   - **Analysis:** SQL-2016 shows significantly lower wait times and counts, indicating better memory management.
    
                      **ASYNC_NETWORK_IO:**
    
                            - **SQL-2016:** WaitTimeMs = 4,255, WaitCount = 207
    
                                  - **SQL-2017:** WaitTimeMs = 4,283, WaitCount = 141
    
                                        - **Analysis:** Both sets are similar, but SQL-2016 is marginally better due to slightly lower wait times.
    
                                           **RESERVED_MEMORY_ALLOCATION_EXT:**
    
                                                 - **SQL-2016:** WaitTimeMs = 2,226, WaitCount = 1,018,040
    
                                                       - **SQL-2017:** WaitTimeMs = 3,429, WaitCount = 1,353,109
    
                                                             - **Analysis:** SQL-2016 shows better performance in memory reservation management.
    
                                                                **PAGEIOLATCH_SH:**
    
                                                                      - **SQL-2016:** WaitTimeMs = 388, WaitCount = 553
    
                                                                            - **SQL-2017:** WaitTimeMs = 836, WaitCount = 928
    
                                                                                  - **Analysis:** SQL-2016 performs better for shared page I/O latches.
    
                                                                                     **Additional Waits in SQL-2017:**
    
                                                                                           - **LOGMGR_FLUSH:** WaitTimeMs = 88, WaitCount = 219
    
                                                                                                 - **PAGEIOLATCH_UP:** WaitTimeMs = 4, WaitCount = 15
    
                                                                                                       - **Impact:** These waits are minimal and do not significantly affect overall performance in SQL-2017.
    

Steps Taken So Far:

  1. Increased both physical memory and cache size to address memory wait times.
  2. Verified and compared execution plans between SQL Server 2016 and SQL Server 2017.

Despite these measures, we have not observed any improvement in the query execution time.

Request: As this query is generated by Cognos and cannot be altered, we seek guidance on database settings or configurations that could optimize performance for this query on SQL Server 2017 (140) compatibility level. Your assistance in identifying and implementing a solution to ensure the query runs efficiently in the upgraded environment would be greatly appreciated.

Thank you for your prompt attention to this matter.

Best regards,Dear Microsoft Support Team,

I hope this message finds you well.

We are encountering a significant performance issue related to SQL Server compatibility during an upgrade of one of our applications. Below are the details of the problem:

Issue Summary: While upgrading our application, the SQL Server compatibility level was updated from SQL Server 2016 (130) to SQL Server 2017 (140) (SSMS 2019 Version). We have observed a substantial increase in query execution time for a specific Cognos report dataset query.

Detailed Description:

  • Problem: A SQL query that previously executed within 10 minutes on SQL Server 2016 (130) now takes 5-7 hours to complete on SQL Server 2017 (140).
  • Observations: Execution Plan Analysis:
       - **SQL-2016:** WaitTimeMs = 336, WaitCount = 175,051
    
             - **SQL-2017:** WaitTimeMs = 16,561, WaitCount = 6,357,099
    
                   - **Analysis:** SQL-2016 shows significantly lower wait times and counts, indicating better memory management.
    
                      **ASYNC_NETWORK_IO:**
    
                            - **SQL-2016:** WaitTimeMs = 4,255, WaitCount = 207
    
                                  - **SQL-2017:** WaitTimeMs = 4,283, WaitCount = 141
    
                                        - **Analysis:** Both sets are similar, but SQL-2016 is marginally better due to slightly lower wait times.
    
                                           **RESERVED_MEMORY_ALLOCATION_EXT:**
    
                                                 - **SQL-2016:** WaitTimeMs = 2,226, WaitCount = 1,018,040
    
                                                       - **SQL-2017:** WaitTimeMs = 3,429, WaitCount = 1,353,109
    
                                                             - **Analysis:** SQL-2016 shows better performance in memory reservation management.
    
                                                                **PAGEIOLATCH_SH:**
    
                                                                      - **SQL-2016:** WaitTimeMs = 388, WaitCount = 553
    
                                                                            - **SQL-2017:** WaitTimeMs = 836, WaitCount = 928
    
                                                                                  - **Analysis:** SQL-2016 performs better for shared page I/O latches.
    
                                                                                     **Additional Waits in SQL-2017:**
    
                                                                                           - **LOGMGR_FLUSH:** WaitTimeMs = 88, WaitCount = 219
    
                                                                                                 - **PAGEIOLATCH_UP:** WaitTimeMs = 4, WaitCount = 15
    
                                                                                                       - **Impact:** These waits are minimal and do not significantly affect overall performance in SQL-2017.
    

Steps Taken So Far:

  1. Increased both physical memory and cache size to address memory wait times.
  2. Verified and compared execution plans between SQL Server 2016 and SQL Server 2017.

Despite these measures, we have not observed any improvement in the query execution time.

Request: As this query is generated by Cognos and cannot be altered, we seek guidance on database settings or configurations that could optimize performance for this query on SQL Server 2017 (140) compatibility level. Your assistance in identifying and implementing a solution to ensure the query runs efficiently in the upgraded environment would be greatly appreciated.

Thank you for your prompt attention to this matter.

Best regards,

SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. MikeyQiaoMSFT-0444 3,300 Reputation points
    2024-08-08T08:35:25.4033333+00:00

    Hi,Vinodkumar Kamurukuru

    The following link reveals some differences in compatibility between the two.

    Differences between compatibility level 130 and level 140

    As Erland mentioned, using Query Store can temporarily mitigate compatibility issues.

    Keep performance stability during the upgrade to newer SQL Server

    It is recommended to upgrade SQL Server to the latest version and re-optimize the queries. Additionally, SQL Server 2017 introduced MAXDOP (Maximum Degree of Parallelism). Set the number of processors to the maximum and see if it helps with the existing queries."

    SELECT 
        cpu_count AS LogicalProcessors
    FROM 
        sys.dm_os_sys_info;
    
    
    
    EXEC sp_configure 'show advanced options', 1; RECONFIGURE; 
    EXEC sp_configure 'max degree of parallelism', [your_value];RECONFIGURE;
    

    Best Regards,

    Mikey Qiao


    If you're satisfied with the answer, don't forget to "Accept it," as this will help others who have similar questions to yours.

    1 person found this answer helpful.
    0 comments No comments

  2. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2024-08-07T21:50:01.49+00:00

    This is not the Microsoft Support Team but a peer-to-peer forum. To talk with the support staff, you need to open a support case. However, both your versions are out of mainstream support, so if the issue is due a bug, you will not get a fix.

    And, by the way, why are you upgrading to a version that is out of the support? SQL 2019 is still in mainstream support but only for a few more months. The only reasonable version to upgrade to is SQL 2022.

    That is not to say that would not face the same problem if you upgraded to SQL 2022. It is certainly not unheard of that you face performance regressions when you move from one compatibility level to another. Microsoft always make changes in the optimizer. They are intended to be improvement, but there are always individual cases when these changes backfire. Often this occurs with queries that have some "problems". That could be poor query constructs on improper indexes. But you were lucky on the old version and did not have to bother, but when you upgraded you ran out of luck.

    A good way to deal with this situation is to have Query Store enabled. When you get regressions like this, you can force the old plan through Query Store, at least as a temporary measure until you have the time to make a closer analysis.

    If you don't have Query Store enabled for your database, enabled it lower the compat level to 130 and keep it in 130 for a week or two. Then you can switch to 140 and deal with the regressions.

    I was not really able to understand that wait-type analysis, but if you are implying that ASYNC_NETWORK_IO is the top wait on SQL 2017, this suggest that this is not a query-execution problem at all. This wait is due to one of two things:

    1. Slow network to connection to the client.
    2. Client is slow to consume the data.

    In neither case, SQL Server is the culprit.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.