Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345»»

Indexed Views Expand / Collapse
Author
Message
Posted Monday, February 13, 2012 2:36 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 8:52 AM
Points: 1,782, Visits: 6,485
On Enterprise edition the results are the same - the view index is used.

On both this and Developer edition I get a warning for each statement
"Warning: Index hints supplied for view 'dbo.v1' will be ignored."
Post #1251058
Posted Monday, February 13, 2012 3:16 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:52 PM
Points: 6,048, Visits: 8,328
Toreador (2/13/2012)
On Enterprise edition the results are the same - the view index is used.

On both this and Developer edition I get a warning for each statement
"Warning: Index hints supplied for view 'dbo.v1' will be ignored."

*lol* I was so wrapped up in checking the execution plan that I completely forgot to check out the messages pane. Yes, I get this warning as well (Developer Edition).

I'm still interested in the results of running this code in non-Enterprise and non-Developer editions, but given this warning message, I estimate a 95% probability that the index hints will be ignored on those editions as well.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1251068
Posted Monday, February 13, 2012 10:03 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:43 PM
Points: 4,126, Visits: 3,428
Hugo Kornelis (2/13/2012)
Toreador (2/13/2012)
On Enterprise edition the results are the same - the view index is used.

On both this and Developer edition I get a warning for each statement
"Warning: Index hints supplied for view 'dbo.v1' will be ignored."

*lol* I was so wrapped up in checking the execution plan that I completely forgot to check out the messages pane. Yes, I get this warning as well (Developer Edition).

I'm still interested in the results of running this code in non-Enterprise and non-Developer editions, but given this warning message, I estimate a 95% probability that the index hints will be ignored on those editions as well.

Hugo

I ran your code under R2 DataCenter, up to date, and got 'Warning: Index hints supplied for view 'dbo.v1' will be ignored.' 5 times.
Post #1251318
Posted Monday, February 13, 2012 11:45 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, October 21, 2014 9:16 AM
Points: 796, Visits: 718
Revenant (2/13/2012)
Hugo Kornelis (2/13/2012)
Toreador (2/13/2012)
On Enterprise edition the results are the same - the view index is used.

On both this and Developer edition I get a warning for each statement
"Warning: Index hints supplied for view 'dbo.v1' will be ignored."

*lol* I was so wrapped up in checking the execution plan that I completely forgot to check out the messages pane. Yes, I get this warning as well (Developer Edition).

I'm still interested in the results of running this code in non-Enterprise and non-Developer editions, but given this warning message, I estimate a 95% probability that the index hints will be ignored on those editions as well.

Hugo

I ran your code under R2 DataCenter, up to date, and got 'Warning: Index hints supplied for view 'dbo.v1' will be ignored.' 5 times.


The same results regarding the warning message were returned from SQL 2008 R2 instances, Std edition, RTM as well as sp1.
Post #1251401
Posted Monday, February 13, 2012 12:25 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:52 PM
Points: 6,048, Visits: 8,328
jascunce (2/13/2012)
Revenant (2/13/2012)
I ran your code under R2 DataCenter, up to date, and got 'Warning: Index hints supplied for view 'dbo.v1' will be ignored.' 5 times.

The same results regarding the warning message were returned from SQL 2008 R2 instances, Std edition, RTM as well as sp1.

Thanks, Revenant and Jascunce! That confirms my suspicion.

Did you also check the actual execution plan to confirm if the query optimizer used (an index on) the base table or (an index on) the view?



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1251449
Posted Monday, February 13, 2012 12:52 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, October 21, 2014 9:16 AM
Points: 796, Visits: 718
Hugo Kornelis (2/13/2012)
jascunce (2/13/2012)
Revenant (2/13/2012)
I ran your code under R2 DataCenter, up to date, and got 'Warning: Index hints supplied for view 'dbo.v1' will be ignored.' 5 times.

The same results regarding the warning message were returned from SQL 2008 R2 instances, Std edition, RTM as well as sp1.

Thanks, Revenant and Jascunce! That confirms my suspicion.

Did you also check the actual execution plan to confirm if the query optimizer used (an index on) the base table or (an index on) the view?


This is interesting. The actual execution plan from the Std instance with sp1 reports that the clustered index from the base table, not the view, was used in each of the 5 queries. Sorry I couldn't get that info from the RTM instance since it was just upgraded but I would think the results would still be the same .

I compared that with the execution of the code in a SQL 2008 R2 Enterprise instance with sp1 and the results were like you had reported from the Developer edition; the clustered index from the view was used.
Post #1251465
Posted Monday, February 13, 2012 2:35 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:43 PM
Points: 4,126, Visits: 3,428
jascunce (2/13/2012)
Hugo Kornelis (2/13/2012)
jascunce (2/13/2012)
Revenant (2/13/2012)
I ran your code under R2 DataCenter, up to date, and got 'Warning: Index hints supplied for view 'dbo.v1' will be ignored.' 5 times.

The same results regarding the warning message were returned from SQL 2008 R2 instances, Std edition, RTM as well as sp1.

Thanks, Revenant and Jascunce! That confirms my suspicion.

Did you also check the actual execution plan to confirm if the query optimizer used (an index on) the base table or (an index on) the view?


This is interesting. The actual execution plan from the Std instance with sp1 reports that the clustered index from the base table, not the view, was used in each of the 5 queries. Sorry I couldn't get that info from the RTM instance since it was just upgraded but I would think the results would still be the same .

I compared that with the execution of the code in a SQL 2008 R2 Enterprise instance with sp1 and the results were like you had reported from the Developer edition; the clustered index from the view was used.

The same for the DataCenter Edition.

The plan is attached.


  Post Attachments 
Hugo.sqlplan (2 views, 43.94 KB)
Post #1251535
Posted Monday, February 13, 2012 3:10 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:52 PM
Points: 6,048, Visits: 8,328
Revenant (2/13/2012)
jascunce (2/13/2012)
This is interesting. The actual execution plan from the Std instance with sp1 reports that the clustered index from the base table, not the view, was used in each of the 5 queries. Sorry I couldn't get that info from the RTM instance since it was just upgraded but I would think the results would still be the same .

I compared that with the execution of the code in a SQL 2008 R2 Enterprise instance with sp1 and the results were like you had reported from the Developer edition; the clustered index from the view was used.

The same for the DataCenter Edition.

The plan is attached.


All exactly as I expected. This confirms that on editions below Enterprise, the only way to get the optimizer to use an index on the view is to use the NOEXPAND hint; using an index hint will not work, as they are ignored on views.

Remember, on Enterprise Edition (and hence also on the feature-equal Developer Edition and on DataCenter, which is essentially Enterprise++), the optimizer will automatically consider using indexes on views, regardless of whether the query references the view or the base tables. On lower editions (such as Standard, Workgroup, and Express), the optimizer will never consider using indexes on views, unless the NOEXPAND hint is used to force the use of an index on the view.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1251568
Posted Monday, February 13, 2012 3:28 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, October 21, 2014 9:16 AM
Points: 796, Visits: 718
Hugo Kornelis (2/13/2012)
[quote]Revenant (2/13/2012)

All exactly as I expected. This confirms that on editions below Enterprise, the only way to get the optimizer to use an index on the view is to use the NOEXPAND hint; using an index hint will not work, as they are ignored on views.

Remember, on Enterprise Edition (and hence also on the feature-equal Developer Edition and on DataCenter, which is essentially Enterprise++), the optimizer will automatically consider using indexes on views, regardless of whether the query references the view or the base tables. On lower editions (such as Standard, Workgroup, and Express), the optimizer will never consider using indexes on views, unless the NOEXPAND hint is used to force the use of an index on the view.


I have attached the execution plan of the 5 queries plus an additional query using the NOEXPAND hint. The warning message was not reported with the execution of this query.


  Post Attachments 
Hugo_SQL2008R2_Std.sqlplan (1 view, 34.75 KB)
Post #1251578
Posted Wednesday, February 15, 2012 3:18 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, February 17, 2014 9:44 AM
Points: 127, Visits: 105
Interesting question... thanks...
Post #1252782
« Prev Topic | Next Topic »

Add to briefcase «««12345»»

Permissions Expand / Collapse