【发布时间】:2015-08-31 18:08:21
【问题描述】:
MySQL 5.5
我正在尝试为查询找到正确的索引。
表:
create table trans (
trans_id int(11) not null auto_increment,
acct_id int(11) not null,
status_id int(11) not null,
trans_transaction_type varchar(5) not null,
trans_amount float(9,3) default null,
trans_datetime datetime not null default '0000-00-00 00:00:00',
primary key (trans_id)
)
查询:
select trans_id
from trans
where acct_id = _acctid
and transaction_type in ('_1','_2','_3','_4')
and trans_datetime between _start and _end
and status_id = 6
基数:
select *
from information_schema.statistics
where table_name='trans'
结果:
trans_id 424339375
acct_id 12123818
trans_transaction_type 70722272
trans_datetime 84866726
status_id 22
我正在尝试查找查询的正确索引是什么?
alter table trans add index (acct_id, trans_transaction_type, trans_datetime, status_id);
alter table trans add index (acct_id, trans_datetime, trans_transaction_type, status_id);
etc...
哪些列在索引中排在第一位?
目标是查询速度/性能。磁盘空间使用无关紧要。
【问题讨论】:
标签: mysql indexing b-tree explain sql-execution-plan