制限数が異なる次のクエリでは、異なるクエリ プランと非常に異なるスキャン行が作成されます。
mysql> explain SELECT * FROM `funds_cash_apply` WHERE 1 and `id` > '0' and `channel` in ('70','81') and `state` = '1' and `state_pay` = '0' and `create_time` < '1447063200' order by id asc limit 50 \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: funds_cash_apply
type: range
possible_keys: PRIMARY,idx_state_state_e
key: PRIMARY
key_len: 4
ref: NULL
rows: 373619
Extra: Using where
1 row in set (0.00 sec)
mysql> explain SELECT * FROM `funds_cash_apply` WHERE 1 and `id` > '0' and `channel` in ('70','81') and `state` = '1' and `state_pay` = '0' and `create_time` < '1447063200' order by id asc limit 5000 \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: funds_cash_apply
type: ref
possible_keys: PRIMARY,idx_state_state_e
key: idx_state_state_e
key_len: 1
ref: const
rows: 6652
Extra: Using index condition; Using where; Using filesort
1 row in set (0.00 sec)
インデックスを持つテーブル:
PRIMARY KEY (`id`),
UNIQUE KEY `idx_water_no` (`water_no`,`state`) USING BTREE,
KEY `idx_kdt_id` (`kdt_id`,`state`,`create_time`) USING BTREE,
KEY `idx_batch_id` (`batch_water_no`,`state`) USING BTREE,
KEY `idx_cp_uid` (`cp_uid`,`state`,`create_time`),
KEY `idx_acct_no` (`acct_no`,`state`,`create_time`),
KEY `idx_state_state_e` (`state`,`state_exception`) USING BTREE
異なる制限 (50 対 500) が異なるクエリ プランを作成し、スキャン行に大きな変化があるのはなぜですか?</p>