SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query Tuning


Query Tuning

Author
Message
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85615 Visits: 41082
Comments posted to this topic are about the item Query Tuning

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Ian_McCann
Ian_McCann
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2030 Visits: 2309
Good question and not the answer I was expecting.
Could you expand on the explanation for option E
Christian Buettner-167247
Christian Buettner-167247
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3555 Visits: 3889
Got it wrong because I did not see that EventID was the PK.
But to be honest, i don't agree with the explanation for why the last option is not valid.
If you explicitly mention the set-up (1000 rows), I expect that the question is based on that the set-up.
And not on any possible future state.

But in the end my fault because I just did not see that PK Sad

Best Regards,

Chris Büttner
free_mascot
free_mascot
Hall of Fame
Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)

Group: General Forum Members
Points: 3975 Visits: 2235
Thanks Jeff, good question.

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Diogy
Diogy
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 29
I don't get it. LOL! ^^

My answer was E.

Can you help explain below statement?
"because a nullability check using ISNULL CAN be SARGable if the ISNULL is written correctly"

Probably, give us a sample of ISNULL not written correctly. ^^

As far as I know, once we use function in WHERE clause, it will be non-sargable and index seek will not be used anymore.

Thanks in advance.
TomThomson
TomThomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14260 Visits: 12197
Good question.

My hangover produced the wrong answer (blame isNull); must remember to drink fruit-juice and coffee before looking at QoTD the morning after a long, late, and liquid celebration. Kicked myself on seeing the answer - isNull is always eliminable by elemetary logic!
P(isNull(A, B)) == (A is Null and P(B*)) or (P(A) and not (A is Null))
(B* is either B or cast(B as A), depending on whether B and A have the same type or not)
for every predicate P. So unless either A or B is unsargable or getting B to the type of A involves the type conversion of a column (which it clearly doesn't when B is a constant) isNull(A,B) ought to be sargable.

edit: But it isn't sargable. I'm feeling stupid. Blush

Tom

Thomas Abraham
Thomas Abraham
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2711 Visits: 2255
Nice Question! Thanks Jeff.

I'd like to add a "me too" for the NON-SARGable example of the ISNULL.

Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
Britt Cluff
Britt Cluff
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1799 Visits: 253
Tough question. I got it wrong because I thought it was a trick and that was too obvious.

http://brittcluff.blogspot.com/
Chris Umbaugh
Chris Umbaugh
SSC Veteran
SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)

Group: General Forum Members
Points: 286 Visits: 241
Great question Jeff! I like you explanation for the last answer, option (I). I was going to be angry if that were one of the correct answers. We do not query tune in order to make fast queries over test data. We do it to insure "lights out" performance in production, to prevent contention, etc. Certainly the use of a SEEK or a SCAN does not matter in test on 1000 rows. However, I do not get paid to make fast queries in TEST.

Chris Umbaugh
Data Warehouse / Business Intelligence Consultant
twitter @ToledoSQL
tabinsc
tabinsc
SSC Eights!
SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)

Group: General Forum Members
Points: 824 Visits: 917
Excellent question Jeff! I do have one question: If clustered index columns are auto-appended to nonclustered indexes, what if the nonclustered index is unique? Adding the clustered index column(s) to an unique nonclustered index would change the unique constraint on it, right?

Tony
------------------------------------
Are you suggesting coconuts migrate?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search