现在要从20多个表中检索出符合条件记录的一个相同的字段,然后她们进行并,交或者差.
比如:table1(field,field1);
     table2(field,field2);
     table3(field,field3);
     .....
     table30(field,field30)
最后查询检索的结果,table1,table2,...,table30表的field的并交差的集合,
我有两种方案
(1)
create table temp1 as select field from table1 where ...;
create table temp2 as select filed from table2 where ...;
create table temp3 as select field from temp1 where field in (select field from temp2 )表示表table1和table2符合条件记录的交集
如此往下进行直到table30;(2)
直接并,交,差
select field from table1 where field... intersect select field from table2 where field2...  intersect select field from table3 where field3 ... ....如此进行下去
由于每个表的数据量相当大,有的几百万条,有的几千万条,
最后比较的结果,(1)的效果还比(2)的效果好,(1)的查询检索时间比(2)短;
请问为什么会出现这种情况呢,到底该采用什么方式解决这样的查询呢?
还有其它的解决方案吗?

解决方案 »

  1.   

    因為你的表太多,直接并,交,差的語句很復雜,所以分析解釋,准備執行sql語句上需要耗費很多資源。
    please see:
    http://www.zdnet.com.cn/developer/code/story/0,2000081534,39128560-1,00.htm
      

  2.   

    对表进行分区,最近本人也开始对分区表研究,若表大量数据,哪么进行散列分区,有规律进行范围分区,当然最好还是混合分区,
    然后对其建立局部索引
    参考:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96524/c12parti.htm#464767
      

  3.   

    我能不能把这个查询执行计划定死,就不用那么费时间了?我现在ORACLE 的版本是WORKGROUP版,不是企业版,不支持分区,在init.ora中也没有看到optimizer_search_limit这个参数,
    急问,该怎么处理????
    求救各位老大了!!!!
      

  4.   

    用 exists 效率要好一些