在大型项目中关系型数据库多表联合查询是很频繁的,现在项目上有以下7张表,每张表达数据量也比较小,但是7张表通过多表联合查询
摘要:在大型项目中关系型数据库多表联合查询是很频繁的,现在项目上有以下7张表,每张表达数据量也比较小,但是7张表通过多表联合查询,查询的速度却非常慢,,希望能够给出一个查询效率比较快的sql。
表1:oper,字段id,operkey等等(数据量3500)
表2:policy,字段id,name等等(数据量5000)
表3:strategy,字段id,name等等(数据量5000)
表4:strategy_approver,字段id,userid,approver等等(数据量50000)
表5:policy_oper(表1和表2的中间表),字段policyid,operid
表6:strategy_policy(表2和表3的中间表),字段policyid,strategyid
表7:strategy_approver_rela(表3和表4的中间表),字段strategyid,strategyapproverid
项目上使用的查询语句如下:
select * from strategy where st.id in (
select * from strategy st
inner join strategy_policy sp on st.id = sp.strategyid
inner join policy p on p.id = sp.policyid
inner join policy_oper po on po.policyid = p.id
inner join oper o o.id = po.operid
inner join strategy_approver_rela sar on sar.strategyid = st.id
inner join strategy_approver sa on sa.id = sar.strategyid
where st.id=? and st.name=? and .... and .... and
)
注:以上查询效率及其慢,已经超过用户体验的最差值,希望能够提供较快的查询效率的sql;
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号