October 13, 2016 at 8:08 am
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
What?
"Use EXISTS instead of DISTINCT when using joins which involves tables having one-to-many relationship."
Shoot me now. Why have I bothered with three volumes of the query tuning book and (soon I hope) three volumes of the execution plans book?
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 13, 2016 at 8:10 am
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
I was bad. I could have ignored it. I just didn't want to.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 13, 2016 at 8:13 am
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
What?
"Use EXISTS instead of DISTINCT when using joins which involves tables having one-to-many relationship."
Shoot me now. Why have I bothered with three volumes of the query tuning book and (soon I hope) three volumes of the execution plans book?
I for one am quite glad you bothered. If it weren't for people like you writing these books then people like me might read articles like that and actually believe them. :w00t:
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 13, 2016 at 8:13 am
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
I was bad. I could have ignored it. I just didn't want to.
I took it for "Granted" that somebody wouldn't be able to resist. 😉
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 13, 2016 at 8:17 am
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
What?
"Use EXISTS instead of DISTINCT when using joins which involves tables having one-to-many relationship."
I can kinda see where that one comes from (though it's badly articulated). Consider:
SELECT DISTINCT CustomerName FROM Customers INNER JOIN Orders ON ... WHERE OrderStatus = 'A'
vs
SELECT CustomerName FROM Customers WHERE EXISTS (SELECT 1 FROM Orders WHERE <join> and OrderStatus = 'A')
The latter is likely to be more efficient than the former.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 13, 2016 at 8:20 am
GilaMonster (10/13/2016)
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
What?
"Use EXISTS instead of DISTINCT when using joins which involves tables having one-to-many relationship."
I can kinda see where that one comes from (though it's badly articulated). Consider:
SELECT DISTINCT CustomerName FROM Customers INNER JOIN Orders ON ... WHERE OrderStatus = 'A'
vs
SELECT CustomerName FROM Customers WHERE EXISTS (SELECT 1 FROM Orders WHERE <join> and OrderStatus = 'A')
The latter is likely to be more efficient than the former.
Assuming your guess is right, yeah.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 13, 2016 at 8:21 am
GilaMonster (10/13/2016)
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
What?
"Use EXISTS instead of DISTINCT when using joins which involves tables having one-to-many relationship."
I can kinda see where that one comes from (though it's badly articulated). Consider:
SELECT DISTINCT CustomerName FROM Customers INNER JOIN Orders ON ... WHERE OrderStatus = 'A'
vs
SELECT CustomerName FROM Customers WHERE EXISTS (SELECT 1 FROM Orders WHERE <join> and OrderStatus = 'A')
The latter is likely to be more efficient than the former.
Yes this one of them that lacks enough context to make the "tip" useful. Just a simple query like the one you posted would have made the concept clear and useful. As posted in the article it is nearly worthless.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 13, 2016 at 8:23 am
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
I was bad. I could have ignored it. I just didn't want to.
There seems to be more ads than good advice on that page.
October 13, 2016 at 8:32 am
Sean Lange (10/13/2016)
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
I was bad. I could have ignored it. I just didn't want to.
I took it for "Granted" that somebody wouldn't be able to resist. 😉
I couldn't resist. I wish I would have.
October 13, 2016 at 8:32 am
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
I was bad. I could have ignored it. I just didn't want to.
I think this one is my pesonal highlight:
IN is efficient when most of the filter criteria are in the sub-query.
EXISTS is efficient when most of the filter criteria is in the main query.
I may need to redo my reviewing work of your exec plans book after reading that page.. :w00t:
October 13, 2016 at 8:40 am
Hugo Kornelis (10/13/2016)
I may need to redo my reviewing work of your exec plans book after reading that page.. :w00t:
BWA-HA-HA-HA-HA!
<quiet voice>
don't you dare
</quiet voice>
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 13, 2016 at 8:46 am
Hugo Kornelis (10/13/2016)
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
I was bad. I could have ignored it. I just didn't want to.
I think this one is my pesonal highlight:
IN is efficient when most of the filter criteria are in the sub-query.
EXISTS is efficient when most of the filter criteria is in the main query.
I may need to redo my reviewing work of your exec plans book after reading that page.. :w00t:
I liked this one.
Use stored procedures instead of views because they offer better performance and don't include code, variable or parameters that don't do anything.
How exactly does a stored procedure not include code, variables or parameters but a view does? And how about those views that have variables and parameters that don't do anything...I have no words for how awesome that is. I can't even come up with a scenario where anything in that statement could possibly be twisted to make sense.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 13, 2016 at 8:50 am
Grant Fritchey (10/13/2016)
Hugo Kornelis (10/13/2016)
I may need to redo my reviewing work of your exec plans book after reading that page.. :w00t:BWA-HA-HA-HA-HA!
<quiet voice>
don't you dare
</quiet voice>
My favorite:
28. Include a clustered index on the columns in the GROUP BY clause.
So if I need to run queries that group the data in two different ways, I guess my options are:
1. Drop and rebuild the clustered index before I run my query.
2. Figure out how to have two clustered indexes on one table, causing the data to be stored in two different orders in the same table.
3. Duplicate the data into enough tables to have one table for each query I need to run.
What could possibly go wrong?
October 13, 2016 at 9:19 am
Ed Wagner (10/13/2016)
Grant Fritchey (10/13/2016)
Hugo Kornelis (10/13/2016)
I may need to redo my reviewing work of your exec plans book after reading that page.. :w00t:BWA-HA-HA-HA-HA!
<quiet voice>
don't you dare
</quiet voice>
My favorite:
28. Include a clustered index on the columns in the GROUP BY clause.
So if I need to run queries that group the data in two different ways, I guess my options are:
1. Drop and rebuild the clustered index before I run my query.
2. Figure out how to have two clustered indexes on one table, causing the data to be stored in two different orders in the same table.
3. Duplicate the data into enough tables to have one table for each query I need to run.
What could possibly go wrong?
Covering indexes?
October 13, 2016 at 9:26 am
GilaMonster (10/13/2016)
Grant Fritchey (10/13/2016)
Sean Lange (10/13/2016)
WOW...http://www.sql-datatools.com/2016/05/sql-queries-tuning-and-optimization.htmlThis is supposed to be a list of things to do to optimize queries. While some of these are valid most of them lack context or explanation. And some of them are just plain awful. :sick:
What?
"Use EXISTS instead of DISTINCT when using joins which involves tables having one-to-many relationship."
I can kinda see where that one comes from (though it's badly articulated). Consider:
SELECT DISTINCT CustomerName FROM Customers INNER JOIN Orders ON ... WHERE OrderStatus = 'A'
vs
SELECT CustomerName FROM Customers WHERE EXISTS (SELECT 1 FROM Orders WHERE <join> and OrderStatus = 'A')
The latter is likely to be more efficient than the former.
Okay, so it's time to learn something new here... Can you point me to a reference (because I don't want to bog down The Thread on technicalities) so I can read up on why EXISTS might be more efficient than the JOIN?
Viewing 15 posts - 56,236 through 56,250 (of 66,712 total)
You must be logged in to reply to this topic. Login to reply