qq243920161 2019-04-25 16:22 采纳率: 0%
浏览 1527

为什么数据库的左外连接查询特别慢?

就查了7条记录就要2秒钟,绝对不能忍,用内连接很快,为什么用左外连接就慢成蜗牛。

查询语句:

explain select * from (
    select * from device where enterprise_id in (
        select enterprise_id from user_enterprise where user_id = 1
    )
) t1
left join (
    select * from device_data
    where device_data_id in ('139212', '139295', '142934', '142935')
) t2
using(device_id)

表结构:

表结构

explain结果:

图片说明

  • 写回答

2条回答 默认 最新

  • 太阳伞下的阿呆 2019-04-26 09:03
    关注

    1.本身所有外链接执行成本就高于内连接
    2.where in中使用子查询这种写法是极其不推荐的,in语法是有限制的。通常使用关联的方式写
    3.执行计划中已经指明了存在表扫描

    评论

报告相同问题?