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.

Geek Sync | Secrets of the Plan Cache

72 views

Published on

You can watch the replay for this Geek Sync webcast, Secrets of the Plan Cache, in the IDERA Resource Center, http://ow.ly/tPjR50A4pZ5.

You have heard of a query plan, right? Perhaps even looked at one somewhere along the way. Have you ever wondered what information might be buried in the plan cache, the courses of action having that additional information might lead you to? Perhaps you have wondered what plans in the cache would benefit from those missing indexes or contemplated your cost threshold of parallelism, among other questions.

This session is designed to answer your questions about query plans. We will look at query plans without the pretty node icons and from there we will interrogate the plan cache thus putting its secrets to work for us.

Speaker: Peter Shore is a seasoned IT professional with over 25 years of experience. He took the accidentally intentional DBA plunge in 2013 and has discovered that he loves to find the stories the data has to tell. Peter is comfortable working with both physical and virtual servers, where he tries to apply best practices to attain performance improvements. He is also adept at bridging the gap between technical and business language in order to bring technology solutions to business needs.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Geek Sync | Secrets of the Plan Cache

  1. 1. Secrets of the Plan Cache
  2. 2. About Me • SQL Server Database Administrator – Chipotle Mexican Grill • Intentionally Accidental DBA • Over 25 years IT experience – Server Engineer – Desktop Engineer – Network Infrastructure – Desk side support • President CBusPASS • Co-Organizer SQL Saturday Columbus • How to find me – Twitter: @pshore73 – E-mail: pshore73@outlook.com
  3. 3. Secrets of the Plan Cache
  4. 4. Secrets of the Plan Cache • There are no secrets in the plan cache – Nothing obfuscated – Nothing intentionally hidden – No hex editors – No debugger
  5. 5. Birth of the Plan • Query Parser – Checks for syntactical correctness – Does not confirm existence of referenced columns or tables • Query Binding – Confirms tables and columns exist – Builds the query process tree • Query Optimizer – Builds the query plan – Goal to execute query in minimum amount of time – Limited time to build the plan
  6. 6. Caching the Plan • What is the Plan Cache? – Subset of the buffer pool – Holds each query plan • Single run ad hoc queries, if optimize for ad hoc is true • Plans can be flushed – DBCC FREEPROCCACHE/DBCC FREEPROCCACHE (<plan handle>) – DBCC FREESYSTEMCACHE – Statistics update – Index maintenance – Memory pressure
  7. 7. Look! A query plan!
  8. 8. A Little XQuery • Xquery is a language used to find and extract, both elements and attributes from XML documents. • XQuery is not specific to TSQL or SQL Server. • Compatible with – XML – Namespaces – XSLT – XPath – XML Schema
  9. 9. A Little XQuery • WITH XMLNAMESPACES – Defines the specifications of the XML namespace being used within TSQL – http://schemas.microsoft.com/sqlserver/2004/07/showplan • Allows XML document to be called in FROM
  10. 10. Sample Plan Cache Queries
  11. 11. Missing Indexes
  12. 12. Specific Index Use
  13. 13. Key Lookups
  14. 14. Cost Threshold of Parallelism
  15. 15. Cost Threshold of Parallelism
  16. 16. Other Secrets to be Revealed • Implicit Conversions • Scans • Specific Operators • Table usage • Really, anything that can be extracted from the XML
  17. 17. Summary • Query Plans are XML Files • Query them using XQuery • Drive configuration and tuning decisions
  18. 18. Questions?
  19. 19. More Information • https://www.sqlskills.com/blogs/jonathan/finding-what-queries-in-the-plan- cache-use-a-specific-index/ • https://www.sqlskills.com/blogs/jonathan/implicit-conversions-that-cause-index- scans/ • https://www.sqlskills.com/blogs/jonathan/tuning-cost-threshold-for-parallelism- from-the-plan-cache/ • https://www.sqlskills.com/blogs/jonathan/finding-key-lookups-inside-the-plan- cache/

×