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中,认为这将是一个简单的“字符串”,以避免扫描的结果。为什么这个MySQL查询性能很差(DEPENDENT_SUBQUERY)
我认为这不会是一个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 |
我更新了问题的扩展结果 – Miguel
'id IN ... GROUP_CONCAT(...)' - 你确定你想要吗? 123 IN('123,456,789')'不会成功。这样做:'123 IN('123','456','789')',但这不是你有的,也不能得到它。重来。 –
因为这只是数字我相信你可以选择退出引号...... – Miguel