How to check a query using an index

I am using SQL Server and I do not have a sufficient dataset to test query performance.

I want to analyze the query and see if the index is used or not. How can I check that

+4
source share
2 answers

In SQL Management Studio, simply enter a query and press Control-L (query mapping execution plan). There you can see if any indexes are used. "Table scan" means that the index is not used. β€œIndex scan” means that the index is being used.

+4
source

This is actually more complicated than it sounds - a typical modern DBMS (and MS SQL Server is no exception) sometimes performs a full table scan, even if the index is available, simply because it can be faster with small amounts of data. 1

Example:

What else, the decision that the DBMS makes may depend on how fresh / accurate the statistics are .

The most reliable test for using the index is to simply populate your database with representative amounts of data , and then see the execution plan . And do not forget the time of the actual execution of the request while you are on it!


1 Simplified example: if the whole table fits into one page of the database, it’s faster to just load this page and go through it sequentially than wait for additional I / O for the page with the index.

+7
source

All Articles