There is a list of issues with using select *
.
1 - consistency of output
If your client expects certain fields and you change the layout of a table, select *
will change its output if the underlying tables changes, breaking your client code.
2 - Network performance
If you only need a subset of all field in the output, select *
will waste network bandwidth by sending unneeded data across the wire.
3a - Database performance
On simple tables select *
may not slow performance down, but if you have blob fields (that you're not interested in) select *
will fetch those as well, killing performance
3b - Memory usage on the database server
If MySQL needs to use a temporary table, select *
will tax the servers, disk, memory and CPU extra by making MySQL store more data in memory.
3c - On InnoDB covering indexes cannot be used
On InnoDB if you select fields that are indexed, MySQL needs never to read the actual table data, it just reads the info straight from the index, select *
kills this optimization.
4 - Clarity of code
select *
gives the reader of a query no info on which fields will be retrieved from the server. select name, address, telephone from ...
makes it instantly clear what data we are dealing with.
If your tables are in Zulu you can even do
select
igama as name
ikheli as address
....
Which is much more useful than the original names for the 99.7% of the people that don't speak Zulu.
5 - Don't hack code, craft it
Select * is just a quick hack to make stuff work.
But when you write code you're supposed to have an idea what you're doing, make that explicit, select what you need, give fields meaningful name using aliases if needed.
Tweak your code to select only what you need.
If I see a select *
in a code review, I mark it down sight unseen because it's a code smell.
Hope this helps.