奇怪的事情发生了。谁能解释一下。我有一张桌子。
CREATE TABLE "country_ip" (
"begin_ip" varchar(15) NOT NULL,
"end_ip" varchar(15) NOT NULL,
"begin_ip_long" int(10) unsigned NOT NULL,
"end_ip_long" int(10) unsigned NOT NULL,
"id" char(2) NOT NULL,
"label" varchar(50) NOT NULL,
KEY "begin_ip_long" ("begin_ip_long","end_ip_long"),
KEY "end_ip_long" ("end_ip_long")
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
大约有 150 000 条记录。下一个查询有很大的时差
0.06329400 | SELECT * FROM `country_ip` WHERE '1405662435' BETWEEN `begin_ip_long` AND `end_ip_long` LIMIT 1
0.06214600 | SELECT * FROM `country_ip` USE INDEX (begin_ip_long, end_ip_long) WHERE 1405662435 BETWEEN `begin_ip_long` AND `end_ip_long` LIMIT 1
0.00008400 | SELECT * FROM `country_ip` USE INDEX (end_ip_long) WHERE 1405662435 BETWEEN `begin_ip_long` AND `end_ip_long` LIMIT 1
谁能解释为什么会这样?我的意思是为什么只有USE INDEX (end_ip_long) 有帮助,而使用USE INDEX (begin_ip_long)或USE INDEX (begin_ip_long, end_ip_long) 没有效果。谢谢。