create table aaa(id int,sc int,num int)engine=myisam;
create index a on  aaa(id,sc,num);create table bbb like aaa;
create index x on bbb(id);
create index y on bbb(sc);
create index z on bbb(num);explain
select * from aaa
where id=1 or sc=11 or num=21 "id" "select_type" "table" "type" "possible_keys" "key" "key_len" "ref" "rows" "Extra"
"1" "SIMPLE" "aaa" "index"        "a"  "a"    "15"          \N "4" "Using where; Using index"
explain
select * from bbb force index(x,y,z)
where id=1 or sc=11 or num=21"id" "select_type" "table"     "type" "possible_keys" "key" "key_len" "ref" "rows" "Extra"
"1"    "SIMPLE"     "bbb"   "index_merge"   "x,y,z" "x,y,z" "5,5,5"    \N "3" "Using union(x,y,z); Using where"Explain的type显示的是访问类型,是较为重要的一个指标,结果值从好到坏依次是:
system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL
问:
上面2个表的索引那个效率好点,看type的话 效率index_merge>index ,
用show status like 'last_query_cost' 来看,aaa上的索引开销比bbb上的开销低,到底是组合索引好还是合并索引好?维护上的话是不是组合索引好点(只属于一个索引),而bbb表上的索引有3个.