Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 是否存在组合>;=或<;=触发全表扫描?_Mysql_Sql - Fatal编程技术网

Mysql 是否存在组合>;=或<;=触发全表扫描?

Mysql 是否存在组合>;=或<;=触发全表扫描?,mysql,sql,Mysql,Sql,我在mysql innodb中有一个表,如下所示: messageIdStart | messageIdEnd | blob ------------------------------------ 40 50 ... 51 58 ... 59 70 ... ... 我想获取ID大于特定值的所有行 例如,

我在mysql innodb中有一个表,如下所示:

messageIdStart | messageIdEnd | blob 
------------------------------------
      40             50         ...
      51             58         ...
      59             70         ...

                ...
我想获取ID大于特定值的所有行

例如,我希望所有具有ID大于55的消息的行。我会:

select * from table 
    where messageIdStart >= 55 or messageIdEnd <= 55;
但这是我继承的

我正在考虑将数据集重新格式化为第二种格式,但不想过早地进行优化


谢谢

您的查询可能会查看您已有的索引。您应该使用EXPLAIN和EXPLAIN EXTENDED来确认这一点

explain select * from table 
where messageIdStart >= 55 or messageIdEnd <= 55;
解释从表中选择*

其中messageIdStart>=55或messageIdEnd将取决于执行“>=”或“这两列上都有索引”的属性。这是否意味着这两列上都有一个复合索引,或者每列有一个索引,即两个索引?每列有一个索引(不是复合索引)。我可以创建一个复合索引。如果是这样,那么您的查询将不会使用表扫描,您也可以使用explain命令进行更多验证。
explain select * from table 
where messageIdStart >= 55 or messageIdEnd <= 55;
select * from table use index (idx_table_messageIdStart)
where messageIdStart >= 55 or messageIdEnd <= 55;