Assume we have a table:
| col1 | col2 | .... | coln |
-------------------------------------------
| - | - | - | - |
| - | - | - | - |
| - | - | - | - |
-------------------------------------------
a query where the columns are ordered:
$query1 = "SELECT col1, col2, col3, col4, col5, ..., coln FROM table";
and a query where the columns are unordered:
$query2 = "SELECT col180, col1, col78, col13, col930, col2 FROM table";
Is one of the queries faster than the other? Why would it be faster? Or, why isn't one faster?
Yes, order matters.
Index the SQL ORDER BY Column(s) Indexes are all about quick searches. And having one in the columns you use in the ORDER BY clause can speed up your query.
For your question just use SELECT *. If you need all the columns there's no performance difference.
It should make a very small impact on performance. Here is a previous answer by spencer7593 that explains in detail:
The order of columns in a table will have a very small impact on performance, as compared to the performance impact of your database design (entities, attributes and relationships), your transaction design and your query design.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With