How can I provide an Index Hint to a MS-SQL Server Indexed View? -


i have indexed view fooview.

i've created following indexes against it:

  • create unique clustered index ix_foo1 on [fooview](someid, anotherid)
  • create nonclustered index ix_foo2 on [fooview](someid)

is possible use hint against ix_foo2 ? keeps using ix_foo1 when use with (noexpand) hint.

yes straightforward

create table dbo.footable   (      someid    int,      anotherid int,      filler    char(8000)   );  go  create view dbo.fooview schemabinding   select someid,          anotherid,          filler     dbo.footable  go  create unique clustered index ix_foo1   on dbo.fooview(someid, anotherid)  create nonclustered index ix_foo2   on dbo.fooview(someid)  go  select someid   dbo.fooview (noexpand) --no hint non clustered index chosen automatically  select *   dbo.fooview (noexpand) --no hint clustered index chosen automatically  select *   dbo.fooview (noexpand, index = ix_foo2) --with hint nonclustered index forced 

execution plans

(note forcing index hint led more expensive plan leaving choice optimiser though)

enter image description here


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -