Wade Williams
Wade Williams

Reputation: 4140

MYSQL: Why SELECT [explicit column names] is faster than SELECT *

I've experienced this first hand but I'm having a hard time locating any resources on the subject after several Google searches:

SELECT * FROM Table LIMIT x

has a slower return time than explicitly listing all of a specific table's column names:

SELECT id, name, email, address, phone, sex, date, ip FROM Table LIMIT x

What is the reason for this?

(assuming you are Explicitly Selecting all the column names, i.e., the table contains only columns id, name, email, address, phone, sex, date, ip)

Upvotes: 0

Views: 2061

Answers (2)

Mchl
Mchl

Reputation: 62387

The sentence 'using SELECT with explicitly listed columns is faster than SELECT *' has sense when you in fact list only some of the columns in table. For example, if you only need an ID from table containing several long VARCHAR or TEXT fields, grabbing only one column will save a lot of time and bandwidth.

Upvotes: 1

iamkrillin
iamkrillin

Reputation: 6876

When you do select * the rdbms has to expand the * to the column names and do the select after words. When you provide explicit column names that step isnt necessary.

Upvotes: 1

Related Questions