mysql没有在BETWEEN查询上使用索引

时间:2014-12-11 16:26:12

标签: mysql sql

表有100,845行。我正在尝试通过IP(ip2long)在特定国家/地区的IP范围内检测国家/地区。

SELECT `country_code` FROM `geo_ip_country`
WHERE 3271557119 BETWEEN `start_ip_long` AND `end_ip_long`

start_ip_longend_ip_long都已编入索引。但是根据explain query,查询不使用索引并执行全表扫描,所有100,845行。

id  select_type     table   type    possible_keys   rows    Extra   
1   SIMPLE  geo_ip_country  ALL     key_name        100845  Using where

我试过了:

  • start_ip_long AND end_ip_long
  • 上制作单独的索引
  • 在(start_ip_long,end_ip_long)上创建综合索引
  • 仅在start_ip_long
  • 上制作一个索引

如何优化此查询或表以便在这种情况下使用索引?

0 个答案:

没有答案