1、如果表足够小,access table full ,读几个块就可以将小表搞定的话,就没有必要建立外键之外的索引。 2、如果小表中的单行数据量非常大的话,建立一个索引还是有必要的。 3、如果小表是有外键约束的话,建立一个索引也是有必要的,这里并不是为了提高查询效率,而是为了避免锁。 4、如果小标本身仅仅是查询,更新很少,或者没有更新,比如是系统中的一个参数表的话,可以考虑将其建立为一个索引组织表。 5、一张大表和一张小表,Oracle一般会倾向于使用NL的连接方式,通常将小表作为LEADING表,有必要根据小标的连接条件,在大表中建立相应的索引,或者根据实际情况建立组合索引。
贴个SQL吧,大家帮我看看 select t3.* from (select
t1.id,t1.deviceid,t2.device_type_id,t1.geomtype,t1.left,t1.top,t1.right,t1.bottom,t1.orientation,t1.scale,t1.text,t1.height,t1.font_orientation from t1,t2 where
t1.geomtablename=t2.geom_table_name) t3,t4 where (t4.min_scale<={:scale} and t4.max_scale>={:scale} and t3.device_type_id=t4.device_type_id) and ((t3.left>={:xmin} and
t3.left<={:xmax}and t3.bottom>={:ymin} and t3.bottom<={:ymax}) or (t3.right>={:xmin} and t3.right<={:xmax} and t3.top>={:ymin} and t3.top<={:ymax}) or (t3.left>=
{:xmin} and t3.left<={:xmax} and t3.top>={:ymin} and t3.top<={:ymax}) or (t3.right>={:xmin} and t3.right<={:xmax} and t3.bottom>={:ymin} and t3.bottom<={:ymax}) or
(t3.left<={:xmin} and t3.bottom<={:ymin} and t3.right>={:xmax} and t3.top>={:ymax}) or (((t3.left>={:xmin} and t3.left<={:xmax}) or (t3.right>={:xmin} and t3.right<=
{:xmax})) and t3.top>={:ymax} and t3.bottom<={:ymin}) or (((t3.bottom>={:ymin} and t3.bottom<={:ymax}) or (t3.top>={:ymin} and t3.top<={:ymax})) and t3.left<={:xmin}
and t3.right>={:xmax})) t1表记录200多万条,t2、t4不到200条记录,t1表以下字段建了索引:id\left\top\right\bottom\deviceid\geomtablename,t2和t4都没有建索引,我这样做合理吗?大家给点意见。
另外、你的两表的关联方法是nested loop join?
如果建索引后不影响预期的执行计划,也没什么影响,那就无所谓。
2、如果小表中的单行数据量非常大的话,建立一个索引还是有必要的。
3、如果小表是有外键约束的话,建立一个索引也是有必要的,这里并不是为了提高查询效率,而是为了避免锁。
4、如果小标本身仅仅是查询,更新很少,或者没有更新,比如是系统中的一个参数表的话,可以考虑将其建立为一个索引组织表。
5、一张大表和一张小表,Oracle一般会倾向于使用NL的连接方式,通常将小表作为LEADING表,有必要根据小标的连接条件,在大表中建立相应的索引,或者根据实际情况建立组合索引。
select t3.* from (select
t1.id,t1.deviceid,t2.device_type_id,t1.geomtype,t1.left,t1.top,t1.right,t1.bottom,t1.orientation,t1.scale,t1.text,t1.height,t1.font_orientation from t1,t2 where
t1.geomtablename=t2.geom_table_name) t3,t4 where (t4.min_scale<={:scale} and t4.max_scale>={:scale} and t3.device_type_id=t4.device_type_id) and ((t3.left>={:xmin} and
t3.left<={:xmax}and t3.bottom>={:ymin} and t3.bottom<={:ymax}) or (t3.right>={:xmin} and t3.right<={:xmax} and t3.top>={:ymin} and t3.top<={:ymax}) or (t3.left>=
{:xmin} and t3.left<={:xmax} and t3.top>={:ymin} and t3.top<={:ymax}) or (t3.right>={:xmin} and t3.right<={:xmax} and t3.bottom>={:ymin} and t3.bottom<={:ymax}) or
(t3.left<={:xmin} and t3.bottom<={:ymin} and t3.right>={:xmax} and t3.top>={:ymax}) or (((t3.left>={:xmin} and t3.left<={:xmax}) or (t3.right>={:xmin} and t3.right<=
{:xmax})) and t3.top>={:ymax} and t3.bottom<={:ymin}) or (((t3.bottom>={:ymin} and t3.bottom<={:ymax}) or (t3.top>={:ymin} and t3.top<={:ymax})) and t3.left<={:xmin}
and t3.right>={:xmax}))
t1表记录200多万条,t2、t4不到200条记录,t1表以下字段建了索引:id\left\top\right\bottom\deviceid\geomtablename,t2和t4都没有建索引,我这样做合理吗?大家给点意见。