The document discusses a presentation by Damian Widera on making SQL Server queries faster. It covers topics like what can make query execution bad, such as full table scans instead of index seeks. It also discusses how to identify issues like unnecessary sorting, hashing, or spools, and when scans may be preferable to seeks. The presentation notes that SQL Server 2016 introduces Query Store, which collects runtime statistics to help troubleshoot performance issues.
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Execution Plans in practice - how to make SQL Server queries faster - Damian Widera
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
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
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….
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. @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. @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. @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. @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…
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…
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. @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