Quantcast
Channel: User Simon_Weaver - Stack Overflow
Viewing all articles
Browse latest Browse all 116

Answer by Simon_Weaver for Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc

$
0
0

What's going on if SELECT * is FASTER than SELECT <column subset> ?

(and everyone is telling you that's not possible!)

So I ended up with a simple SELECT statement for a table with only a few dozen rows that was taking 524ms, 510ms, 550ms. This was happening both in EF Core and SSMS. If instead I changed it to SELECT * inside SSMS then it was taking about 25ms. It made zero sense. This is from my home to Azure via Google Fiber.

In the end I found myself in a situation where commenting out all the column names was still much slower then SELECT *.

This query took 522ms.

enter image description here

Whereas this took only 15ms

enter image description here

The threshold where it seemed to matter was around 1410 bytes sent to server. So I concluded it was probably network related, and switched from WiFi to ethernet and boom both queries were now taking ~15ms.

I'm not going to attempt to explain why this may have happened. I have a new laptop and an old router so something is getting tripped up.

The point being, it isn't always your SQL or SQL Server or your underlying network connection.


Viewing all articles
Browse latest Browse all 116

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>