2 xuxiaolinhappy xuxiaolinhappy 于 2013.09.25 21:27 提问

mysql 视图 left join 非常慢

select uuid() AS myid,tu.id AS id,tu.job_number AS job_number,tu.email AS useremail,tu.name AS name,tu.dept AS dept,tu.manger AS manger,tu.status AS status,tu.createDate AS createDate,tu.updateDate AS updateDate,tchk.name AS sysName,tchk.number AS sysNumber,tchk.status AS sysStatus,tchk.createDate AS sysCreateDate,'香港集群账号' AS tableName from (tiw_user tu left OUTER join tiw_clusterHkNum tchk on((tchk.tiwUid = tu.id))) where 1 = 1
union all
select uuid() AS myid,tu.id AS id,tu.job_number AS job_number,tu.email AS useremail,tu.name AS name,tu.dept AS dept,tu.manger AS manger,tu.status AS status,tu.createDate AS createDate,tu.updateDate AS updateDate,tcsz.name AS sysName,tcsz.number AS sysNumber,tcsz.status AS sysStatus,tcsz.createDate AS sysCreateDate,'深圳集群账号' AS tableName from (tiw_user tu left OUTER join tiw_clusterSzNum tcsz on((tcsz.tiwUid = tu.id))) where 1 = 1
union all
select uuid() AS myid,tu.id AS id,tu.job_number AS job_number,tu.email AS useremail,tu.name AS name,tu.dept AS dept,tu.manger AS manger,tu.status AS status,tu.createDate AS createDate,tu.updateDate AS updateDate,tcwh.name AS sysName,tcwh.number AS sysNumber,tcwh.status AS sysStatus,tcwh.createDate AS sysCreateDate,'武汉集群账号' AS tableName from (tiw_user tu left OUTER join tiw_clusterWhNum tcwh on((tcwh.tiwUid = tu.id))) where 1 = 1

说明:(一共用十表union进行连接 代码都是重复)且左右表的数据量相差比较大

1个回答

en_joker
en_joker   2017.11.16 13:24

在连接上加入索引。
你这sql语句都是一样的,是不是粘错了。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!