I have a fact table which is partitioned along the PeriodDate
column.
CREATE TABLE MyFactTable
(
PeriodDate DATE,
OrderID INT
CONSTRAINT MyFk FOREIGN KEY (OrderID) REFERENCES DimOrder(ID)
)
I'd like create a partition aligned index on the OrderID
column, and as I understood from BOL, I need to include the partitioning key (PeriodDate
) in order to have the index aligned.
Like this:
CREATE NONCLUSTERED INDEX MyAlignedOrderIdIndex
ON MyFactTable (OrderID, PeriodDate);
My question is: in what order should I put the two columns in the index above?
ON MyFactTable (OrderID, PeriodDate);
or
ON MyFactTable (PeriodDate, OrderID);
As I read on BOL as well the order matters in composite indexes, and my queries will usually use OrderID
to lookup Dim table data.
First OrderID, PeriodDate
order seems logical choice, but since I am not familiar with partitioning I don't know how it will "like it" when the tables has millions of rows.
What does the best practices dictates here?