1
爲什麼mysql不使用index_merge?mysql索引合併問題
看起來像我的服務器有index_merge ON,但優化器仍然沒有考慮到。
optimizer switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on
explain SELECT a,b FROM `zip25` WHERE b=91367 OR a=91367
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE zip25 ALL a,b NULL NULL NULL 752299 Using where
[編輯]
表定義
CREATE TABLE `zip25` (
`a` char(5) DEFAULT NULL,
`b` char(5) DEFAULT NULL,
`distance` float NOT NULL,
KEY `a` (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
在此先感謝
的常用方法來優化這種查詢使用UNION(通常它的速度更快,甚至然後使用index_merge)。不過,我認爲這個問題實際上是爲什麼index_merge沒有被使用。你可以發佈表格定義嗎? – 2012-04-14 11:54:32
嗨達哈澤,是的,我的問題是爲什麼index_merge沒有被使用。我用表格定義編輯了我的問題。 – Venu 2012-04-14 12:01:33
a和b實際上是char而不是int。隱式轉換通常會阻止MySQL使用索引。嘗試將值放在引號內:'解釋SELECT a,b FROM'zip25' where b =「91367」或a =「91367」'。也嘗試整數類型相同。 – 2012-04-14 12:03:18