|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, October 24, 2012 8:17 PM
Points: 1,558,
Visits: 247
|
|
Learned something new today even though I missed the question. Thanks for submitting.
http://brittcluff.blogspot.com/
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 18, 2013 9:37 AM
Points: 134,
Visits: 99
|
|
Thanks for the question and like the answer options very much
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 18, 2013 9:37 AM
Points: 134,
Visits: 99
|
|
sknox (2/10/2012)
Hugo Kornelis (2/10/2012)
I hate questions where I have to second-guess the author. Did the author mean that the optimizer would choose to use the indexed view automatically? Or did he mean that you could make the optimizer use it by using hints? I took a 50% chance gamble, and I chose wrong.  If I'd meant automatically, I'd have said automatically. 
+1
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 18, 2013 9:37 AM
Points: 134,
Visits: 99
|
|
sknox (2/10/2012)
BTW, now that I am posting anyway - there is one word in the explanation is wrong: "The query optimizer in lower editions will only consider the indexed view if you use the NOEXPAND table hint" (emphasis mine) - this is incorrect. With the NOEXPAND hint, the optimizer will not consider the indexed view; this hint forces the optimizer to use the indexed view. Enterprise edition (and developer edition) is the only place where the optimizer will consider the indexed view as one of multiple options, and choose the cheapest. Yes, that is incorrect, but I think you've picked the wrong word(s) to correct. The intended meaning was "The query optimizer in lower editions will only consider the indexes on the view if you use the NOEXPAND table hint." The reason I used the word consider is that NOEXPAND does not force the use of a particular index, it only tells SQL server not to refer back to the original table.
Using NOEXPAND hint, says the optimizer to consider the index and it won't force its usage. To force a particular index usage, the optional INDEX() clause need to be used.
http://msdn.microsoft.com/en-us/library/ms181151.aspx
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 9:28 AM
Points: 5,243,
Visits: 7,054
|
|
SathishK (2/10/2012) Using NOEXPAND hint, says the optimizer to consider the index and it won't force its usage. To force a particular index usage, the optional INDEX() clause need to be used.
http://msdn.microsoft.com/en-us/library/ms181151.aspx Using NOEXPAND means that the optimizer may not use any index on the underlying base table(s). The only freedom the optimizer has is to choose which of the indexes on the view to use. And I have never seen a real-world case where there was more than a single index on a view.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 8:39 AM
Points: 1,054,
Visits: 218
|
|
| Good Question, I guessed right as I haven't worked wtih 2012 at all.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:53 AM
Points: 1,176,
Visits: 778
|
|
| interesting question - tks
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 20, 2013 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 7:44 AM
Points: 1,555,
Visits: 1,925
|
|
sknox (2/10/2012)
Hugo Kornelis (2/10/2012)
I hate questions where I have to second-guess the author. Did the author mean that the optimizer would choose to use the indexed view automatically? Or did he mean that you could make the optimizer use it by using hints? I took a 50% chance gamble, and I chose wrong.  If I'd meant automatically, I'd have said automatically. 
You might do that. However, there have been several examples of questions where a detail like that was left out of the question. I would have liked the question more if it had been clear that the "automatically" was intentionally left out. I guessed at the meaning right but still got it wrong because I thought that indexed views weren't supported at all in Express, both by initial guess and after research. Which means that I learned something from from it so thank you. I'm looking forward to the article.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 7:15 AM
Points: 2,865,
Visits: 2,467
|
|
Hugo And I have never seen a real-world case where there was more than a single index on a view
Does that mean that there couldn't be more than one? Does that also mean that the index hint will n ot work?
Steve Jimmo Sr DBA “If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan
|
|
|
|