Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Execution Plans in practice - how to make SQL Server queries faster - Damian Widera

1,373 views

Published on

If you ever wanted to speed up your queries than you would have to know how to read and analyze query execution plans. Let’s do it together during the session because I am going to show you how to be better developer just by reading what’s inside the query plan. Come and see how simple that could be.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Execution Plans in practice - how to make SQL Server queries faster - Damian Widera

  1. 1. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Execution plans in practice – how to make SQL Server queries faster Damian Widera Microsoft Data Platform MVP EUVIC @damianwidera http://sqlblog.com/blogs/damian_widera/default.aspx
  2. 2. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Many thanks to our sponsors & partners! GOLD SILVER PARTNERS PLATINUM POWERED BY
  3. 3. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Come to Poland on October 1st!
  4. 4. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Damian Widera
  5. 5. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals EUVIC PALO ALTO NOWY JORK WARSZAWA KATOWICE GLIWICE BIELSKO BIAŁA WROCŁAW CZĘSTOCHOWA GDYNIA KRAKÓW BYDGOSZCZ WIEDEŃ BIAŁYSTOK
  6. 6. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Customers…
  7. 7. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals • What is bad in terms of query execution • What was bad in previous examples is not always bad… • SQL Server 2016 – how could it help? Today I am going to tell about….
  8. 8. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals SQL Server School of Art
  9. 9. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals • A query takes long time to execute • A query consumes too much resources • Then we have: –Reduced concurency –More locks that should be • Locks contentions, waits, etc… What is bad in terms of query execution
  10. 10. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals • A query (logical) is parsed and optimized based on all available information (cost optimization) • Estimation != Guestimation • Plan(s) is (are) produced How it works
  11. 11. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Bad row estimates can impact a variety of decisions including: • index selection seek vs. scan operations, • parallel versus serial execution, • join algorithm selection, • inner vs. outer physical join selection (e.g. build vs. probe), • spool generation, • bookmark lookups vs. full clustered or heap table access, • stream or hash aggregate selection Why it is so important?
  12. 12. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals • Index or table scans (*): May indicate a need for better or additional indexes (*) – THIS IS NOT ALWAYS WRONG!!!! • Bookmark Lookups: Consider changing the current clustered index, consider using a covering index, limit the number of columns in the SELECT statement. • Filter: Remove any functions in the WHERE clause, don’t include views in your Transact-SQL code, may need additional indexes. What to look for…
  13. 13. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals • Sort: Does the data really need to be sorted? Can an index be used to avoid sorting? Can sorting be done at the client more efficiently? „Hidden” sort. Nonlinear operation • Spool. Used as a cache in the QP. Reason – lack of indexes or uniqueness. Implemented as a hidden tables in tempdb • Hash. Used for joins and aggregations. Builds a hashtable in memory (or in tempdb). Means there is no good index. What to look for…
  14. 14. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals
  15. 15. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals • When index scan is the best option –Two examples • High density -> Seek • Low density -> Scan • When cursor can be the best option (especially for SQL Server 2008 R2 and older) –Running total What was bad in previous example is not always bad…
  16. 16. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals
  17. 17. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals New functionality that makes DBAs’ happy - Query Store will be available in all editions SQL Server 2016 – how could it help?
  18. 18. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Query data store Durability latency controlled by DB option DATA_FLUSH_INTERNAL_SECONDS Compile Execute Plan store Runtime stats Query Store schema Collects query texts (plus all relevant properties) Stores all plan choices and performance metrics Works across restarts / upgrades / recompiles Dramatically lowers the bar for performance troubleshooting New Views Intuitive and easy plan forcing
  19. 19. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Query Store schema explained
  20. 20. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Query Store Dashboard
  21. 21. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals
  22. 22. @ITCAMPRO #ITCAMP16Community Conference for IT Professionals Q & A

×