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.
Whereas this took only 15ms
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.