以下分别为关闭 ICP 与开启 ICP 的 EXPLAIN 结果:
(localhost:mysqld.sock)|(ytt)>explain select /*+ no_icp (t1) */ * from t1 where r1 = 1 and r2 like '%dog%' and r4 = 5\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t1
partitions: NULL
type: ref
possible_keys: idx_r4,idx_u1
key: idx_u1
key_len: 5
ref: const
rows: 325
filtered: 0.12
Extra: Using where
1 row in set, 1 warning (0.00 sec)
(localhost:mysqld.sock)|(ytt)>explain select * from t1 where r1 = 1 and r2 like '%dog%' and r4 = 5\G *************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t1
partitions: NULL
type: ref
possible_keys: idx_r4,idx_u1
key: idx_u1
key_len: 5
ref: const
rows: 325
filtered: 0.12
Extra: Using index condition; Using where
1 row in set, 1 warning (0.00 sec)
其中 extra 里显示 “Using index condition” 就代表用了 ICP。不过这个信息有点过于简单了,除了 EXTRA 列结果显示不同外,其他的列结果都一样,没法从执行计划结果判断 ICP 的优略。