原SQL 构建如下:
select * from table1 t1,table2 t2
where t1.pid=t2.id 
and (条件1 or 条件2 or 条件3)
and (条件4 or 条件5 or 条件6).....
这种该怎么优化好,提供一个思路即可。多谢!

解决方案 »

  1.   

    把具体的SQL帖出来看看,你条件之间全是独立的吗?
      

  2.   

    没具体sql,从形式看没什么好改进的.
      

  3.   

    代码如下:
    select count(*) into returnValue from dual
            where exists (

    select 1 from ViewForPurviewOut a where a.resourceid = FAULT_OPERATION_RESOURCE_ID 
    and ((not exists (select 1 from ViewForPurview b
                  where b.configid = a.pdcguid and b.attrid = '5' and b.attrexpre = 0 and b.guid = pProductID) 
         and exists (select 1 from cc_purview_datarange c where c.configid = a.pdcguid and c.attrid = '5' and c.attrexpre = 0)) /* 不包含产品范围 */
                or exists (select 1 from ViewForPurview b
                  where b.configid = a.pdcguid and b.attrid = '5' and b.attrexpre = 1 and b.guid = pProductID)) /* 包含产品范围 */
      
      
                and ((not exists (select 1 from ViewForPurview b
                  where b.configid = a.pdcguid and b.attrid = '1' and b.attrexpre = 0 and b.guid = pAreaID) 
         and exists (select 1 from cc_purview_datarange c where c.configid = a.pdcguid and c.attrid = '1' and c.attrexpre = 0)) /* 不包含地理范围 */
                or exists (select 1 from ViewForPurview b
                  where b.configid = a.pdcguid and b.attrid = '1' and b.attrexpre = 1 and b.guid = pAreaID)) /* 包含地理范围 */
      
                and ((not exists (select 1 from ViewForPurview b
                  where b.configid = a.pdcguid and b.attrid = '6' and b.attrexpre = 0 and b.guid = pCustomerID) 
         and exists (select 1 from cc_purview_datarange c where c.configid = a.pdcguid and c.attrid = '6' and c.attrexpre = 0))/* 不包含客户范围 */
                or exists (select 1 from ViewForPurview b
                  where b.configid = a.pdcguid and b.attrid = '6' and b.attrexpre = 1 and b.guid = pCustomerID)) /* 包含客户范围 */
      
                and exists (select 1 from cc_purview_operole por
                  join cc_base_roleope ro on por.roleid = ro.roleid
                  where ro.opeid = pOpUnitID and por.operange = a.poguid) /* 包含操作项 */
                and a.typeid = 20 and a.userid = pUserID);
      

  4.   

    主要是最外层exist()中间这一段