Performance degraded under 2000 records in SQL Server 2022 compare to SQL Server 2019

Badhe, Ganesh 60 Reputation points
2024-09-13T13:10:00.5833333+00:00

Hi,

I have observed that bulk delete operation is having poor performance SQL Server 2022

SQL Server 2019

Number of records - array:10000000

Operation - DELETE Operation

Delete Operation taken time is : 34703 ms

SQL Server 2022

Number of records - array:10000000

Operation - DELETE Operation

Delete Operation taken time is : 59620 ms

Note : All configuration are same, Same JDBC code we are using in both SQL Server versions.

We observed that performance issue on SQL Server 2022 compare to 2019. Even this issue we observed on 2000 objects as well.

Suggest if any observation and fixes.

Regards,

Ganesh

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,865 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 111.8K Reputation points MVP
    2024-09-15T19:03:19.7066667+00:00

    So you are deleting all rows in the table?

    If there no table referencing this table with foreign-key constraint, you could use TRUNCATE TABLE instead. This is a lot more efficient. Note that TRUNCATE TABLE requires an elevated permission on the table, to wit ALTER permission.

    If there are referencing foreign keys, TRUNCATE TABLE will error out. One option is to drop the FKs and then restore them.

    If you don't want to use TRUNCATE TABLE, you can still look at the indexes on the table. Disable all non-clustered indexes before you start, and re-enable them after the operation with ALTER INDEX REBUILD. This can improve the speed considerably.

    As for why the DELETE operation are running slower, do you have SQL 2019 and SQL 2022 on the same hardware? It's quite common to move to new hardware (or a new VM) when upgrading, and it is more likely that there are difference in hardware configuration that matters than the SQL Server version.


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.