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 a开发者_如何学JAVAll the column names, i.e., the table contains only columns id, name, email, address, phone, sex, date, ip)
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.
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.
精彩评论