Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql wildcard: performance overhead?

I've Googled this question and can't seem to find a consistent opinion, or many opinions that are based on solid data. I simply would like to know if using the wildcard in a SQL SELECT statement incurs additional overhead than calling each item out individually. I have compared the execution plans of both in several different test queries, and it seems that the estimates always read the same. Is it possible that some overhead is incurred elsewhere, or are they truly handled identically?

What I am referring to specifically:

SELECT *

vs.

SELECT item1, item2, etc.
like image 322
Geo Ego Avatar asked Mar 21 '26 07:03

Geo Ego


1 Answers

SELECT * FROM...

and

SELECT every, column, list, ... FROM...

will perform the same because both are an unoptimised scan

The difference is:

  • the extra lookup in sys.columns to resolve *
  • the contract/signature change when the table schema changes
  • inability to create a covering index. In fact, no tuning options at all, really
  • have to refresh views needed if non schemabound
  • can not index or schemabind a view using *
  • ...and other stuff

Other SO questions on the same subject...

  • What is the reason not to use select * ?
  • Is there a difference betweeen Select * and Select list each col
  • SQL Query Question - Select * from view or Select col1,col2…from view
  • “select * from table” vs “select colA,colB,etc from table” interesting behaviour in SqlServer2005
like image 98
gbn Avatar answered Mar 22 '26 19:03

gbn