SELECT A,B,C,D from Table1 Where Constraint1
vs
SELECT A from Table1 Where Constraint1
SELECT B from Table1 Where Constraint1
SELECT C from Table1 Where Constraint1
SELECT D from Table1 Where Constraint1
Is there any performance difference ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think that the first one is faster, but.. let’s test it!
Considering in the second group of selects to return A, B, C & D.
IN
SQL SERVER 2008 R2:Let’s try it:
Running Execution plan for the first:
and this results on:
It’s on spanish, but you can see the numbers. Has a CPU Cost of
0.0000796So, let’s try it with the second:
and this results on:
As you can see, each select use the same CPU Cost, but.. here has to do 4 selects. With a little row, you won’t see the difference, but, let me update, with more data
UPDATE
Now, I made a couple of inserts, and now we have:
Let’s do the same: We got the first
select, and in the execution plan, we got:as you can see, we got more
CPU COST(of course, more rows!)And then let’s check the 4 selects:
Again, we got the same
CPU COST, but we run it 4 times !!In conclusion, there is no difference on showing one field or four, but we got a big difference on doing one
selectagainst 4.I know it’s a simply question, but I wanted to do some “science/research”