Index optimization in Azure SQL database

Vijay Kumar 2,036 Reputation points
2023-02-22T05:58:47.6133333+00:00

How to find out poorly performing indexes in Azure SQL DB?

Azure SQL Database
{count} votes

2 answers

Sort by: Most helpful
  1. SSingh-MSFT 16,371 Reputation points Moderator
    2023-02-22T09:05:11.2633333+00:00

    Hi @Vijay Kumar,

    Thanks for posting this question in Microsoft Q&A forum.

    As I understand, you want to identify poor performance in Indexes of Azure SQL Databae.

    Azure SQL Database offers automatic index tuning. Automatic index tuning uses machine learning to learn horizontally from all databases in Azure SQL Database through AI and dynamically improve its tuning actions. Automatic index tuning includes a verification process to ensure there is a positive improvement to the workload performance from indexes created.

    User's image

    Reference Link: https://learn.microsoft.com/en-us/azure/azure-sql/database/automatic-tuning-overview?view=azuresql#automatic-tuning-options

    Enable Auto Tuning

    User's image

    Hope this helps. If this answers your query, do click Accept Answer and Mark Helpful for the same. And, if you have any further query do let us know.

    1 person found this answer helpful.

  2. Alberto Morillo 34,671 Reputation points MVP Volunteer Moderator
    2023-02-22T14:43:36.98+00:00

    The following DMVs may help you.

    Indexes not used.

    -- List unused indexes
    SELECT  OBJECT_NAME(i.[object_id]) AS [Table Name] ,
            i.name
    FROM    sys.indexes AS i
            INNER JOIN sys.objects AS o ON i.[object_id] = o.[object_id]
    WHERE   i.index_id NOT IN ( SELECT  ddius.index_id
                                FROM    sys.dm_db_index_usage_stats AS ddius
                                WHERE   ddius.[object_id] = i.[object_id]
                                        AND i.index_id = ddius.index_id
                                        AND database_id = DB_ID() )
            AND o.[type] = 'U'
    ORDER BY OBJECT_NAME(i.[object_id]) ASC ; 
    
    

    Indexes with more costs than benefits.

    Indexes with more writes than reads that you may consider consolidating with othes or removing them.

    -- Potentially inefficent non-clustered indexes (writes > reads)
    SELECT  OBJECT_NAME(ddius.[object_id]) AS [Table Name] ,
            i.name AS [Index Name] ,
            i.index_id ,
            user_updates AS [Total Writes] ,
            user_seeks + user_scans + user_lookups AS [Total Reads] ,
            user_updates - ( user_seeks + user_scans + user_lookups )
                AS [Difference]
    FROM    sys.dm_db_index_usage_stats AS ddius WITH ( NOLOCK )
            INNER JOIN sys.indexes AS i WITH ( NOLOCK )
                ON ddius.[object_id] = i.[object_id]
                AND i.index_id = ddius.index_id
    WHERE   OBJECTPROPERTY(ddius.[object_id], 'IsUserTable') = 1
            AND ddius.database_id = DB_ID()
            AND user_updates > ( user_seeks + user_scans + user_lookups )
            AND i.index_id > 1
    ORDER BY [Difference] DESC ,
            [Total Writes] DESC ,
            [Total Reads] ASC ;
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.