I've created an indexed view (MyView) that consists of three columns:
Table1_ID (int not null)
Object_CreationDate (datetime, null)
Objec_Count(bigint null)
I have created clustered unique index IX_1 on two columns: Table1_ID
And Object_CreationDate
I want to run two queries:
1.
Select * from [dbo].MyView
where Table1_ID = 10
2.
Select * from [dbo].MyView
where Table1_ID = 10
AND Object_CreationDate <= GETDATE()
1-st query runs fast (even with DBCC DROPCLEANBUFFERS()) and use simple execution plan via using MyView and IX_1
2-nd query runs not so fast because it uses "old" execution plan (seeking by several indexes in three tables and nested looping)
I misunderstand this situation. As for me, it is natural use IX_1 And MyView for 2-nd query.
Moreover, I wait that 2-nd query runs the same speed or even faster then 1-st, because it uses two columns in where clause that are in clustered index.
I tried run 2-nd query with(index=IX_1)
and update statistics for columns, but still have the same execution plan.
Is it possible to force sql use MyView AND IX_1 ?