建议贴出以下如何结果,以便于分析:show table status like 't2' \Gshow table status like 't1' \Gshow index from t1;show index from t2;explain 你的SQL语句
t1.a为主键,t2.a,t2.e均为索引就是表太大,千万数量级, 从此表中查出子集为select t2.c, t2.d from t2 while t2.e = 5; 这个行数比较少,千行以内. 希望能以这个子集和t1 join 取出关联的t1.a, t1.b
那考虑对t2建立复合字段索引 (e,a)试下看看
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;
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) 如何对这个语句进行优化
考虑对t2建立复合字段索引 (e,a);对t1建立索引(a)
从此表中查出子集为select t2.c, t2.d from t2 while t2.e = 5;
这个行数比较少,千行以内.
希望能以这个子集和t1 join 取出关联的t1.a, t1.b
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)
如何对这个语句进行优化
我觉得如果你是基于这个SQL来优化的话,那建议你考虑对t1(a)建立索引,对t2(e,a)建立索引否则,如果不是基于你的这个SQL语句,那考虑改变处理逻辑来优化了,如建立临时表来处理等等。
2、索引情况、主键是什么;
3、EXPLAIN 你的SQL语句。
nianzhang747应该是这个意思看起来好象可以了,
先结贴.