Home > Database > Mysql Tutorial > sybase的SQL多表联合查询调优

sybase的SQL多表联合查询调优

WBOY
Release: 2016-06-07 17:28:19
Original
1359 people have browsed it

在大型项目中关系型数据库多表联合查询是很频繁的,现在项目上有以下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;

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template