我是靠谱客的博主 贪玩水池,最近开发中收集的这篇文章主要介绍mysql索引 范围,mysql范围索引,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I have very simple select like this:

SELECT * FROM table

WHERE column1 IN (5, 20, 30);

on column1 is seted index, after explaining query is index used, all looks to be ok.

but if there are more than three values in range, like this:

SELECT * FROM table

WHERE column1 IN (5, 20, 30, 40);

index is not used and select runs thru all records. Am I doing something wrong? thanks

解决方案

How many rows does MySql think there are in the table?

Mysql often (usually correctly!) assumes it will be quicker to do a sequential scan of the rows, rather than mess around with the more complex access via an index.

It varies from DBMS to DBMS but the tradeoff point is somewhere about 30% of the rows.

IE. If the optimiser expects more than 30% of the rows to be selected it will sequentially scan the whole table as this is usually faster than doing lots of direct access via indexes.

最后

以上就是贪玩水池为你收集整理的mysql索引 范围,mysql范围索引的全部内容,希望文章能够帮你解决mysql索引 范围,mysql范围索引所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部