“ Do not use SELECT
*” Has almost become MySQL A golden rule , Even 《 Ali Java Development Manual 》 It also clearly states that it shall not be used * List of fields as queries , It also gives this rule the blessing of authority .
But I use it directly in the development process SELECT * There are still quite a few , There are two reasons ：
* Because it's simple , Very efficient development , And if fields are frequently added or modified later ,SQL Statements do not need to be changed ;
I think premature optimization is a bad habit , Unless you can determine at the beginning what fields you actually need in the end , And properly indexed ; otherwise , I'll do it when I'm in trouble SQL Optimize , If, of course, the trouble is not fatal .
But we have to know why it is not recommended to use it directly SELECT *, This article from 4 Give reasons in three aspects .
<>1. Unnecessary disks I/O
We know MySQL Essentially, user records are stored on disk , Therefore, the query operation is a disk IO act （ Provided that the records to be queried are not cached in memory ）.
More fields to query , Explain that the more content to read , This increases the size of the disk IO expenses . Especially when some fields are TEXT,MEDIUMTEXT perhaps BLOB
And so on , The effect is particularly obvious .
That uses SELECT * Will it make MySQL Take up more memory ?
Not theoretically , Because for Server Layer