Azure SQL Clustered Index On Partition

Som Pathak 0 Reputation points
2023-05-30T13:06:01.6466667+00:00

I created a table which partition on schedule_day , Do i required to create cluster index on schedule_day ?

In my case i have all queries in this format :

select * from our_table where store_id = <>, dep_id = <>, schedule_day <> and timestamp = <>

Should i create clustered index on (store_id, dep_id, timestamp) ? Azure SQL will able to locate the correct partition and then use index for search ? How i can verify if my queries are going in correct partition not scanning whole table ?

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Oury Ba-MSFT 21,121 Reputation points Microsoft Employee Moderator
    2023-06-22T16:19:43.7133333+00:00

    @Som Pathak

    Let me correct myself here.

    In general, if there is an equality predicate, an index is a must. partitioning is usually not required however it is recommended when the size of data is larger and efficient management (loading, building indexes, archiving, etc.) of that data is required.

    Azure SQL will be able to locate the correct partition and then use index for search.

    Should i create clustered index on (store_id, dep_id, timestamp)?

    If the goal is just to make this one query perform well, then probably yes.

    You should not create the clustered index for just one query, or even for a type of queries. There are many factors to consider, including column data types, the read and write workloads against the table, other indexes that may be needed, etc. Without all of that data, we cannot make a recommendation as to what the right clustered index should be in this case.

    https://learn.microsoft.com/en-us/sql/relational-databases/partitions/partitioned-tables-and-indexes?view=sql-server-ver16#aligned-index

    https://learn.microsoft.com/en-us/sql/relational-databases/query-processing-architecture-guide?view=sql-server-ver16#query-processing-enhancements-on-partitioned-tables-and-indexe

    We recommend reading a series of blogs on sqlskills.com to learn the relevant considerations when selecting the clustered index, for example: More considerations for the clustering key – the clustered index debate continues! – Kimberly L. Tripp (sqlskills.com)

    Regards,

    Oury


Your answer

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