Description:
SELECT * FROM users might be the most innocent-looking SQL SELECT command ever written.
But in production, the SQL SELECT command written like SELECT * can quietly waste memory, slow down your application, and make your database work harder than it needs to.
The asterisk (*) means "return everything from this table. Including the data my use case doesn't need."
Maybe you only need a username, but if you issue queries like this, your database has to read and return all rows from all of the columns while also transferring the data, and your application has to process it.
That means that you move a bunch of unnecessary data across the network and a few extra bytes every now and then can easily become gigabytes of traffic in the long run.
If your application is widely used and you don't fix your SQL queries soon, you will waste gigabytes of traffic.
Depending on how your SQL query is written, using SELECT * can also prevent the database from using covering SQL indexes, because the database index probably doesn't contain every column in the table.
Now MySQL Server has to fetch the data from the entire table.
And here's another thing. If a developer performs some maintenance on your table and adds a column or two, your query performance will change without you knowing.
Add a new column today, and every SELECT * SQL query suddenly starts returning more data.
The fix is simple: ditch SQL SELECT * queries and only select the columns you actually need.
Your database will read less data, your app will process less data, and your future self and the developers around you will thank you.
SELECT * = Easy now, expensive later.
#database #sql #mysql #developer
Share this link via
Or copy link

























