...

View Full Version : Select Queries - listing each required variable VS *



paddyfields
10-11-2011, 01:58 PM
Hi there.

When using Select queries, does it really matter that much if you always use;

SELECT * from table

instead of

SELECT item1, item2 FROM table

Does this greatly affect the speed the query is processed?

Cheers,
Pat.

Old Pedant
10-11-2011, 07:45 PM
Depends.

If the table(s) have many large fields, then doing SELECT * could be much slower than selecting individual fields *IF* when you selected individual fields you did *NOT* include all the large one.

Consider: MySQL is in a separate process than whatever you use to invoke it (PHP or any other code...even the command line client). So whatever data you SELECT has to be sent through some sort of inter-process communication from MySQL to the client. Inter-process data transfer is much slower than in-process. The more data you pass, the longer it takes.

So even if there were zero overhead within MySQL (and there's more than zero! often not a lot more,but...) the time it takes to pass data from one process to the other could add up.

General rule: SELECT only what you need for best performance.

paddyfields
10-12-2011, 03:59 PM
Very helpful. Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum