select t1.a, t1.b, t2.c, t2.d from t1, t2 where (t1.a = t2.a and t2.e = 123)
由于t2过于庞大,希望能对上面进行优化,
实际上就是希望t1能和一个查询出来的子集进行join望高手指点

解决方案 »

  1.   

    你的表数据分布情况怎样?可以试下:
    考虑对t2建立复合字段索引 (e,a);对t1建立索引(a)
      

  2.   

    建议贴出以下如何结果,以便于分析:show table status like 't2' \Gshow table status like 't1' \Gshow index from t1;show index from t2;explain 你的SQL语句
      

  3.   

    t1.a为主键,t2.a,t2.e均为索引就是表太大,千万数量级,
    从此表中查出子集为select t2.c, t2.d from t2 while t2.e = 5;
    这个行数比较少,千行以内.
    希望能以这个子集和t1 join 取出关联的t1.a, t1.b
      

  4.   

    那考虑对t2建立复合字段索引 (e,a)试下看看
      

  5.   

    select t1.a,b,t2.c,t2.d from t1  inner join  (select a,c,d,e from t2) t2 on t1.a=t2.a where t2.e=123;
      

  6.   

    CREATE TABLE t1 (a int not null  primary key, b int, c int);
    CREATE TABLE t2 (id int not null  auto_increment primary key, a int, d int);select t1.a, t1.b, t1.c, t2.d from t1, t2 where (t1.a = t2.a and t2.e = 123)
    如何对这个语句进行优化
      

  7.   

    从你这里提供的信息看来,你这里面已经是最好的内联接了
    我觉得如果你是基于这个SQL来优化的话,那建议你考虑对t1(a)建立索引,对t2(e,a)建立索引否则,如果不是基于你的这个SQL语句,那考虑改变处理逻辑来优化了,如建立临时表来处理等等。
      

  8.   

    1、贴记录及要求结果出来看看;
    2、索引情况、主键是什么;
    3、EXPLAIN 你的SQL语句。
      

  9.   

    兄台,像你这里(select a,c,d,e from t2)有点多此一举吧?假如T2的记录很多,会慢得要命
      

  10.   

    select t1.a,t1.b,t2.d from t1  inner join (select a,d from t2 where a=123) t2 on t1.a=t2.a;
    nianzhang747应该是这个意思看起来好象可以了,
    先结贴.