concept give routine in category sql

appears as: given routine
SQL Server DMVs in Action: Better Queries with Dynamic Management Views

This is an excerpt from Manning's book SQL Server DMVs in Action: Better Queries with Dynamic Management Views.

We’ll now look at which specific indexes are used by a given routine. This provides you with an opportunity to pre-optimize before the query is run.

3.7.1. Finding the indexes used by a given routine

If you know which indexes are used by a given routine, you can pre-optimize these indexes before the next time the routine is run, ensuring optimal performance. The script we use to identify the indexes used by a given routine is shown here.

Listing 3.6. Identifying indexes used by a given routine

Here you can see that a single DMV and four system tables are involved in identifying the indexes used by a given routine; a brief description of each is given in table 3.8.

Table 3.8. DMV/system tables to identify the index usage

DMV/tables

Description

sys.dm_db_index_usage_stats Contains details of the different types of index operations, for example, number of updates by user queries
sys.indexes Contains details for each index, for example, name and type
sys.sysindexes Contains details of row counts and row changes (since last update statistics run)
sys.tables Contains details of table objects, for example, name
sys.schemas Contains details of schema objects, for example, name

By joining the DMV with the system tables, we have enough information to identify the indexes used by a given routine and how they’re used. The DMV joins to the system table sys.indexes on their common key columns, object_id and index_id. The other system tables typically provide descriptive information.