CBredlow
CBredlow

Reputation: 2840

Is there a runtime difference between SELECT * and SELECT explicit columns?

I have a theoretical table with millions of rows:

Person table
ID             int
first_name     varchar(50)
last_name      varchar(50)
date_inserted  datetime
middle_name    varchar(50)
nick_name      varchar(50)
favorite_color varchar(50)
birth_date     datetime
last_edited    datetime

And my query is the following:

SELECT * FROM PERSON WHERE last_edited > subdate(now(), 2)

which returns tens of thousands of rows.

Is there any significant runtime difference between that query and running

SELECT 
    ID, 
    first_name, 
    last_name, 
    date_inserted, 
    middle_name, 
    nick_name, 
    favorite_color, 
    birth_date, 
    last_edited 
FROM Person
    WHERE last_edited > subdate(now(), 2);

Upvotes: 1

Views: 318

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269763

No. The run-time difference is going be based on the volume of data returned. This is the same for the two queries, because the same columns are referenced.

Often, columns are listed explicitly so only the needed columns are included. That can benefit performance, and well as making the code more robust with respect to changes in the table structure.

Upvotes: 6

Related Questions