mysql优化union_mysql多条sql语句unionall连接优化
explain (SELECT netdev.id,devName,ip,birthdayDate,manufacturer,sendDate,maintenanceDate,build,pp.paraName as ppname,netdev.xh as xhname,'服务器' as ame FROM netdev left join para as pp on netdev.pp = pp.id left join organize as O id=O.id where netdev.id)
union all
(SELECT s.id,subName as devName,subIp as ip,birthdayDate,manufacturer,sendDate,maintenanceDate,build,a.paraname as ppname,s.XH as xhname,'控制单元' as ame FROM subserver s left join para as a on s.PP = a.id left join organize as O id=O.id WHERE zzid != '0' )
union all
(SELECT crossing.id,crsName as devName,crsIp assql语句优化方式
ip,birthdayDate,manufacturer,sendDate,maintenanceDate,build,pp.paraName as ppname,crossing.xh as xhname,'运维节点' as ame FROM crossing left join para as pp on crossing.pp = pp.id left j
oin organize as O id=O.id)
union all
(SELECT cam.id,cam.cameraName as devName,cam.ip as ip,birthdayDate,p.paraName as
manufacturer,sendDate,maintenanceDate,build,pp.paraName as ppname,cam.xh as xhname,'前端设备' as ame FROM camera as cam left join para as pp on cam.pp = pp.id left join crossingcamera crs on crs.cameraCode =
cam.cameraCode left join para as p on cam.sdk = p.paraValue and p.paraType='manufacturer' left join organize as O id=O.id)
union all
(SELECT R.id,R.name as devName,R.ip,birthdayDate,manufacturer,sendDate,maintenanceDate,build,pp.paraName as ppname,R.xh as xhname,'动环设备' as ame FROM ringdev as R left join para as pp on R.pp=pp.id left join organize as O on R.oid=O.id)
union all
(SELECT O.id,O.name as devName,O.ip,birthdayDate,manufacturer,sendDate,maintenanceDate,build,pp.paraName as ppname,O.xh as xhname,'其他设备' as ame FROM otherdev as O left join para as pp on O.pp=pp.id left join organize as ORG on O.oid=ORG.id)
limit 0,20
现在想显⽰所有设备的信息,因为最初的建表原因(建表⾮本⼈操作)... 所以⽤到union all
但是当某个表的数据达到10w以上查询就变的很慢 这个应该怎么优化?
之前因为问题不完整,可能是我想简单了... 请各位谅解
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论