Query speed based on order of columns

前端 未结 4 1680
半阙折子戏
半阙折子戏 2021-02-04 14:57

Does the order of the column types in your database have any affect on the query time?

For example, would a table with mixed ordering (INT, TEXT, VARCHAR, INT, TEXT) be

4条回答
  •  别那么骄傲
    2021-02-04 15:50

    The order is unlikely to matter much. The running time is dominated by things like disk access times, and the number and order of disk accesses is unlikely to change as a result of reordering the data within a row.

    The one exception is if you have a very big item in your row (much bigger than a disk block, usually 4K?). If you have one very big column in a table, you might want to put it as the last column so that if you aren't accessing it, it might not need to be fully paged in. But even then, you'd have to work pretty hard to generate a data set and access pattern where the difference would be noticeable.

提交回复
热议问题