sqlschool.gr logo

articles

Articles of SQLschool.gr Team

The sys.dm_exec_query_optimizer_info DMV

Antonios Chatzipavlis
Saturday 02 January 2016

Θα ξεκινήσω την νέα αυτή χρονιά με ένα απλό και μικρό άρθρο αλλά που απαιτεί πολύ τριβή, διάβασμα και όρεξη να βουτήξει κανείς σε βαθιά και πολλές φορές αχαρτογράφητα ύδατα.

Είμαι σχεδόν σίγουρος ότι αν έκανα μια δημοσκόπηση με το ερώτημα αν κάποιος γνωρίζει το DMV που αναφέρω στον τίτλο του άρθρου αυτού το αποτέλεσμα θα ήταν συντριπτικά υπερ του όχι.

Το DMV αυτό σου δίνει μια πλειάδα από χρήσιμες πληροφορίες τις οποίες μπορείς να αξιοποιήσεις στην διερεύνηση θεμάτων που αφορούν απόδοση queries και το σημαντικότερο από όλα είναι ότι είναι πλήρως τεκμηριωμένο στα BOL.

Η χρηστικότητα του συγκεκριμένου DMV είναι διπλή.

Μπορεί να χρησιμοποιηθεί σε ένα παραγωγικό περιβάλλον σαν εργαλείο στατιστικής μέσα από το οποίο μπορούμε να δούμε στοιχεία όπως πόσα queries χρησιμοποιούν indexed views ή query hints ή περιέχουν subqueries ή κάνουν χρήση views ή κάνουν χρήση cursors και πολλά ακόμα.

Μπορεί όμως να χρησιμοποιηθεί και σαν εργαλείο για την βελτιστοποίηση ενός συγκεκριμένου query ή script. Σε αυτή όμως την περίπτωση θα πρέπει να χρησιμοποιηθεί σε ένα SQL Server instance που δεν έχει φόρτο (ιδανικά να είμαστε μόνοι μας) με τον εξής τρόπο

  1. Εκτελούμε το DMV και τα στοιχεία του τα αποθηκεύουμε κάπου πχ ένα excel ή temp table
  2. Εκτελούμε το query που θέλουμε να διερευνήσουμε 
  3. Εκτελούμε ξανά το DMV και συγκρίνουμε τα στοιχεία που αυτό δίνει σε αυτή την εκτέλεση με αυτά που είχαμε συλλέξει από την αρχική εκτέλεση

Για παράδειγμα
use AdventureWorks2014;
go

SELECT 1 as t,* into #qoi FROM sys.dm_exec_query_optimizer_info;
go

select * from Sales.SalesOrderHeader
where OrderDate>='20070101'
order by OrderDate desc;
go

insert into #qoi
SELECT 2,* FROM sys.dm_exec_query_optimizer_info;
go

select * from #qoi
order by 2,1;
go
Μελετώντας τα στοιχεία που μας δίνει το τελευταίο query θα είμαστε σε θέση να καταλάβουμε πως ακριβώς έχει συμπεριφερθεί ο query optimizer για το συγκεκριμένο execution

Καλη Χρονιά με υγεία πάντα.
/*antonch*/

Antonios Chatzipavlis

Antonios Chatzipavlis

Antonios is a Data Solutions Consultant and Trainer. He has been working in IT since 1988. In his career, he has worked as senior developer, IT Manager, Solutions Architect and IT Consultant. Since 1995 he has been devoted on new technologies and software development tools, mainly by Microsoft, either by training company staff and colleagues or assisting them in design, development and implementation as a consultant or chief developer. He has focused in Databases and Data Science since 1995. He specialized in Microsoft SQL Server since version 6.0 in areas like SQL Server Internals, Database Design and Development, Business Intelligence and in 2010 he has started working with Azure Data Platform, NoSQL databases, Big Data Technologies and Machine Learning. He is an active member of many IT communities in Greece, answering colleagues' questions and writing articles in his web site. He is the owner of SQLschool.gr which is a community portal with a lot of information about Microsoft SQL Server. He has been a Microsoft Certified Trainer (MCT) since 2000. Microsoft honored him as MVP on Data Platform due to his activities in SQL Server since 2010. He holds a large number of Microsoft Certifications and Microsoft SQL Server Certifications since version 6.5.

Episode

Task Flows in Microsoft Fabric

image

More Episodes...

Tip

What's New in SQL Server 2022 - Episodes

More Tips...

Become a member

If you want to receive updates from us become a member to our community.

Connect

Explore

Learn


sqlschool.gr © 2010-2025 All rights reserved

This site uses cookies for operational and analytics purposes only. By continuing to browse this site, you agree to their use.