I have a table in Azure SQL Database that looks like this:
CREATE TABLE [dbo].[DayStatus](
[Date] [DATE] NOT NULL,
[LocationId] [INT] NOT NULL,
[TypeId] [INT] NOT NULL,
[Total] [DECIMAL](15, 5) NULL,
[Timezone] [NVARCHAR](70) NULL,
[Currency] [NVARCHAR](3) NOT NULL,
PRIMARY KEY CLUSTERED
(
[Date] ASC,
[LocationId] ASC,
[TypeId] ASC
)
) ON [PRIMARY]
GO
Question
I need to optimize the following SELECT statement to the above table:
SELECT
[Date],
[LocationId],
[TypeId],
[Total],
[Timezone],
[Currency]
FROM [dbo].[DayStatus]
WHERE
Date >= '2022-06-01' and Date <= '2023-01-17'
and Currency = 'USD'
and LocationId in (1, 2, 3, 4, 6, 10)
and TypeId in (1, 2, 3, 5)
I have considered the following indexes, but it seems I cannot see a significant performance difference.
Which one is better, and is there an even better one?
Test 1
CREATE NONCLUSTERED INDEX [IX__Test1] ON [dbo].[DayStatus]
(
[Date] ASC,
[Currency] ASC,
[LocationId] ASC,
[TypeId] ASC
)
GO
Test 2
CREATE NONCLUSTERED INDEX [IX__Test2] ON [dbo].[DayStatus]
(
[Currency] ASC,
[LocationId] ASC,
[TypeId] ASC
)
INCLUDE([Date],[Timezone],[Total])
GO
EDIT
Would it be better to have the query below?
SELECT
[Date],
[LocationId],
[TypeId],
[Total],
[Timezone],
[Currency]
FROM [dbo].[DayStatus]
WHERE
Currency = 'USD'
and LocationId in (1, 2, 3, 4, 6, 10)
and TypeId in (1, 2, 3, 5)
and Date >= '2022-06-01' and Date <= '2023-01-17'