The performance difference will depend on the access path to the data that the RDBMS chooses. It can be no difference (if "*" turns out to mean columns that are covered by the chosen index) or it can be all the difference in the world. "*" might mean wide columns (actually LOB or not) that are inefficient to retrieve and extremely wasteful if not needed. In a join, it will bring back all columns from all involved tables, and that's going to add up fast. If the index isn't covered, each row from each table is necessarily going to be at least one physical seek and probably more than one.
The performance difference will also depend on hardware. Extra seeks won't matter as much for solid state devices as they would for mechanical storage. But by touching data you don't need, you're also polluting the cache in the whole stack -- on the drives, on the controllers, the processor, the RDBMS memory cache, and the PHP layer itself needs to build and store the associative array for a bunch of data you know you're not using.
The performance difference is always non-zero, and its exact effect isn't always easy to measure. If you've got headroom to burn, that's great. But you've probably wasted some money, in that case. And you're burdening someone else who will need to come along and clean up your mess eventually. They'll have a heavy burden, since your sloppy technique left a subtle trap. (For example, since the performance difference is plan dependent, you might be just fine now but blown completely out of the water when the query changes, the tables change, the indexes on those tables change, or someone upgrades the RDBMS. Even subtler actions might trigger trouble.)
I don't think there can be much debate about the benefits of the coding style. "*" ends up causing code to be brittle, and it's just planting a land mine for someone else to trip.
On Mon, Feb 18, 2013 at 3:28 PM, Mark Steudel <[address removed]>
What are people's thoughts on "SELECT *" these days. With today's processing, disk speeds, memory, etc. does it really make a performance difference? If you look at most ORMs these days when you do something like:
$user = User::find( $user_id );
SELECT * FROM users WHERE user_id = ?
And that doesn't include any relationships ....
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Mark Steudel ([address removed]) from The Seattle PHP Meetup Group.
To learn more about Mark Steudel, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages
Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]