I have a mysql user table that is around 35 columns wide, I notice that the things I query for most often, picture_url, username, onlinestatus are located on the far right side of the table. Would it be better performance to have the most used items be at the very beginning of the table?
views:
38answers:
1The column position makes no difference at all to performance in any MySQL storage engine. When you read any column from a row, you have already incurred the most expensive part, which is the I/O of seeking and reading that row from the data file on disk.
If you want to improve performance of frequently-used columns, uses indexes. Also learn about covering indexes which allow queries to read a column's value from the index without having to also read the rest of the row from the table storage. But this also has nothing to do with the ordinal position of the column.
One more tip about columns and performance: if your query only needs a subset of the columns, don't use SELECT *
. Transferring all the columns over the network to your application does have a cost, and if you don't need all the columns, don't fetch them.