left join/inner join以后数据条数比原数据表多的原因及解决办法

本文探讨了使用left join/inner join后数据条数增多的现象,分析了其背后的原因,并提出了解决这种问题的优化策略。通过案例展示了在不聚合情况下,查询效率和数据量的关系,以及如何提升查询速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
页面一:
select vendor, application,applicationversion,filename ,fileversion, lastuse from `ASIA`.applications
where INSTR(vendor, "") and  INSTR(application , "") and  INSTR(filename, "") and lastuse< 1597741978 and lastuse> 1595149978
GROUP BY vendor ,application ,applicationversion ,filename
ORDER BY vendor desc LIMIT 10 OFFSET 0;                           # 没有join表

页面二:

select vendor ,application ,applicationversion ,fileversion,filename ,lastuse ,host.deviceid , hostname from `ASIA`.applications as app
left join  `ASIA`.hostinfo as host on app.deviceid=host.deviceid
where INSTR(hostname, "") and INSTR(vendor, "") and  INSTR(application , "") and  INSTR(applicationversion, "") and  INSTR(filename, "")
GROUP BY vendor ,application ,applicationversion ,filename
ORDER BY vendor desc LIMIT 10 OFFSET 0;              # 有join表

问题:第一个页面比第二个页面快,页面二查询太慢了

 
 
 
 
分析:
页面1聚合:耗时0.19s
select vendor, application,applicationversion,filename ,fileversion, lastuse from `ASIA`.applications
                            where INSTR(vendor, "") and  INSTR(application , "") and  INSTR(filename, "") and lastuse< 15977
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值