explain select id, nome from bea_clientes where id in (
select group_concat(distinct(bea_clientes_id)) as list
from bea_agenda
where bea_clientes_id>0
and bea_agente_id in(300006,300007,300008,300009,300010,300011,300012,300013,300014,300018,300019,300020,300021,300022)
)
上記のことを (説明なしで) 実行しようとすると、MySQL は DEPENDENT SUBQUERY を使用してビジー状態になり、非常に遅くなります。問題は、オプティマイザがクライアントの各 ID のサブクエリを計算する理由です。スキャンを避けるために、その結果をプレーンな「文字列」として配置するのと同じであると信じて、IN引数をgroup_concatに配置しました。
これは 5.5+ の MySQL サーバーでは問題にならないと思いましたか? MariaDb でのテストも同じことを行います。
これは既知のバグですか? これを結合として書き直すことができることはわかっていますが、それでもこれはひどいものです。
Generated by: phpMyAdmin 4.4.14 / MySQL 5.6.26
Comando SQL: explain select id, nome from bea_clientes where id in ( select group_concat(distinct(bea_clientes_id)) as list from bea_agenda where bea_clientes_id>0 and bea_agente_id in(300006,300007,300008,300009,300010,300011,300012,300013,300014,300018,300019,300020,300021,300022) );
Lines: 2
Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|----|--------------------|--------------|-------|-------------------------------|---------------|---------|------|-------|------------------------------------|
| 1 | PRIMARY | bea_clientes | ALL | NULL | NULL | NULL | NULL | 30432 | Using where |
| 2 | DEPENDENT SUBQUERY | bea_agenda | range | bea_clientes_id,bea_agente_id | bea_agente_id | 5 | NULL | 2352 | Using index condition; Using where |