两张表,各表都有几十万数据,现在要通过索引字段关联起来,在进行web查询的的时候非常慢!
以下是我的表及查询语句
create table gc_dfss(
hbs_bh char(8) not null,
dffs_ny date  not null,
hj_dl varchar(20) null,
);
create table gc_dfys(
hbs_bh char(8) not null,
dffs_ny date  not null,
ss_df varchar(20) null,
);
分别在两表上建立两个索引 hbs_bh,dffs_nys
select *from (
select rownum bj,t.* from (
select a.hbs_bh,a.dffs_ny ,b.ss_df from gc_dfss a,gc_dfys b where a.hbs_bh=b.hbs_bh and a.dffs_ny=b.dffs_ny ) t where rownum<20 ) u where u.bj>0 ; 我在plsql中测试,单表是很快的,但只要一关联起来就很慢,一般显示前二十条要7秒多。

解决方案 »

  1.   

    select rownum bj,a.hbs_bh,a.dffs_ny ,b.ss_df from gc_dfss a,gc_dfys b where a.hbs_bh=b.hbs_bh and a.dffs_ny=b.dffs_ny where rownum<20
      

  2.   

    select rownum bj,a.hbs_bh,a.dffs_ny ,b.ss_df from gc_dfss a,gc_dfys b where a.hbs_bh=b.hbs_bh and a.dffs_ny=b.dffs_ny and rownum<20
      

  3.   

    看看这句话的执行计划select a.hbs_bh,a.dffs_ny ,b.ss_df 
    from gc_dfss a,gc_dfys b 
    where a.hbs_bh=b.hbs_bh 
    and a.dffs_ny=b.dffs_ny
      

  4.   

    最外层的条件没有用,有记录的情况u.bj肯定>0,没有就不出了,所以没必要再套一层。而且rownum<20也可以放到内层吧!改---->select rownum bj,a.hbs_bh,a.dffs_ny ,b.ss_df from gc_dfss a,gc_dfys b 
    where a.hbs_bh=b.hbs_bh and a.dffs_ny=b.dffs_ny 
    and rownum<20