March 16, 2017 at 5:37 am
Hi All,
Which query performs faster given each table has 30-40 columns and each table has huge data. We had an argument about which would perform better. I insisted that first one would do but my colleague thinks otherwise. Please let me know your inputs.
select t1.col1, t1.col2,t2.col1.t2.col2 from table1 join table2 t2 on t1.col1=t2.col1
select t1.col1, t1.col2,t2.col1.t2.col2 (select col1,col2 from table1)t1 join (select col1,col2 from table2) t2
on t1.column1=t2.column1
March 16, 2017 at 5:45 am
The two will be identical, identical plans, identical performance.
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
March 16, 2017 at 6:15 am
We are using PDW not traditional sql server. Will they have same execution plans?
March 16, 2017 at 6:20 am
GilaMonster - Thursday, March 16, 2017 5:45 AMThe two will be identical, identical plans, identical performance.
We are using PDW not traditional sql server. Will they have same execution plans?
March 16, 2017 at 6:25 am
kukr007 - Thursday, March 16, 2017 6:20 AMGilaMonster - Thursday, March 16, 2017 5:45 AMThe two will be identical, identical plans, identical performance.We are using PDW not traditional sql server. Will they have same execution plans?
Yes, I saw the title.
The two will be identical, identical plans, identical performance.
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
March 16, 2017 at 11:36 am
Depending on complexity, the second one might be a bit slower to compile (nothing noticeable). But most of the time, Gail's answer will prevail.
March 19, 2017 at 9:14 pm
This will be different:
select t1.col1, t1.col2,t2.col1.t2.col2
from (select col1,col2 from table1 group by col1,col2)t1
join (select col1,col2 from table2 group by col1,col2) t2
on t1.column1=t2.column1
How different? It depends.
In some situatiuons may be slower, but in others performance gain may be huge.
_____________
Code for TallyGenerator
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply