我写了如下SQL(很典型的3张表,t3是连接t1,t2的关系表),执行效率非常低。(t1.obid、t2.obid、t3.left、t3.right字段均为PK)select t1.obid
from t1
,t2
,t3
where t3.left = t1.obid
and t3.right = t2.obid
;改为如下写法后,执行效率大大提高,请高人指教,这是什么原因呢?(t1.col可以是t1表中任意一列)select t1.obid
,t1.col
from t1
,t2
,t3
where t3.left = t1.obid
and t3.right = t2.obid
;
from t1
,t2
,t3
where t3.left = t1.obid
and t3.right = t2.obid
;改为如下写法后,执行效率大大提高,请高人指教,这是什么原因呢?(t1.col可以是t1表中任意一列)select t1.obid
,t1.col
from t1
,t2
,t3
where t3.left = t1.obid
and t3.right = t2.obid
;
2:t1.col是索引
我的水平只能猜测到这样了,学习中....
select t1.obid
from t1,
t3,
t2
where t3.left = t1.obid
and t3.right = t2.obid;
from t1
,t2
,t3
where t3.left = t1.obid
and t3.right = t2.obid
只需查询索引就可取到所需的数据
而
select t1.obid,t1.col
from t1
,t2
,t3
where t3.left = t1.obid
and t3.right = t2.obid
查询索引之后,还需要回表取col。导致时间长。
建议建一个obid,col的复合索引试试.