SQL Server 2017 升級2019 后部分語句變慢解決方法 QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_140


先記錄下,回頭再補內容

legacy CE off 的時候,不同的兼容級別SQL優化器的表現不一樣,而且在測試中確實執行時間差別很大

https://support.microsoft.com/en-us/topic/kb4342424-improvement-update-to-support-query-optimizer-compatibility-level-n-in-use-hint-option-in-sql-server-2017-b326790c-9a0e-b76b-0b52-aa30f2f79f91

legacy CE on的時候,不同的兼容級別也會對優化器有影響,同樣的legacy CE on,在2019使用140和150的兼容級別,某些SQL執行時間差別也很大
升級后數據庫使用的compatibility level從140變成150, 部分語句變慢,添加查詢提示 OPTION (USE HINT('QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_140')) 強制使用140的優化器,問題得到解決

參考鏈接
https://support.microsoft.com/en-us/topic/kb4342424-improvement-update-to-support-query-optimizer-compatibility-level-n-in-use-hint-option-in-sql-server-2017-b326790c-9a0e-b76b-0b52-aa30f2f79f91

不改CE設置,改優化器行為的方法:
In SQL Server 2014 and later versions, you can use trace flag 9476 to force the New CE to use the Simple Containment assumption instead of the default Base Containment assumption.
https://docs.microsoft.com/en-us/troubleshoot/sql/performance/cardinality-estimator-degrades-query-performance


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM