如果经常使用的话,是否应该将mysql表上的列向左移动?

时间:2021-08-29 05:57:43

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?

我有一个35列宽的mysql用户表,我注意到我查询的东西,picture_url, username, onlinestatus都位于表的最右边。将最常用的项目放在表的最开始会更好吗?

1 个解决方案

#1


3  

The 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.

列的位置对MySQL存储引擎的性能没有任何影响。当您从一行读取任何列时,您已经发生了最昂贵的部分,即从磁盘上的数据文件中查找和读取该行的I/O。

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.

关于列和性能的另一个技巧是:如果查询只需要列的一个子集,那么不要使用SELECT *。通过网络将所有列传输到应用程序确实有成本,如果不需要所有列,就不要获取它们。

#1


3  

The 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.

列的位置对MySQL存储引擎的性能没有任何影响。当您从一行读取任何列时,您已经发生了最昂贵的部分,即从磁盘上的数据文件中查找和读取该行的I/O。

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.

关于列和性能的另一个技巧是:如果查询只需要列的一个子集,那么不要使用SELECT *。通过网络将所有列传输到应用程序确实有成本,如果不需要所有列,就不要获取它们。