开发者

Do I need to define an index for a MySQL table with a single row (settings table)

Do I need to define an index for a MySQL table with a single 开发者_StackOverflow社区row (settings table) for performance/optimization reasons?


If it has a single row it's pointless, because the whole table will get seq scanned anyway.


This is a very common question for all relational databases. PostgreSQL's query planner will deliberately not use indexes when reading a few pages of data because performance suffers when doing an index scan instead of a simple sequential scan. I would expect that nearly all databases (with the smallest amount of intelligence) would do the same in this case.

Rhetorical: why perform multiple read(2) calls when you can just perform one and scan 8K of data? Context switching, OS file-system cache, etc. Chances are the page for the index is already in cache, so the optimization is really tiny in the greater scheme of things. Saving two cache hits for a row of data vs just one cache hit... who cares?

Specifically for MySQL, with MyISAM or InnoDB with the file-per-table options set, you don't need an index (I'm not sure if you need an index if you have all of your data in a single InnoDB file).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜