有个SQL查询语句涉及到一个大表和一个小表,大表建了索引,小表需要建索引吗?
解决方案 »
- 请教创建oracle数据库id主键自动递增的写法
- 求一个反着的行列转换的方法
- 关于返回结果集的问题,可参与各种连接查询以及子查询
- 大家看看这条分页存储过程,10万条数据 可以使用这个吗
- oracle EM Application告警如何处理
- 问题急!各位大虾请进阿!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 监听无法配置和启动, 各位帮忙, 谢谢
- 装好pl/sql后登陆时 Username,password,database connect as都该如何填呀?在线等待!谢谢!
- 大家帮忙看看下面的触发器哪里有问题?
- 请教数据库连接失败的原因
- 如何设置在sqlplus中不以科学计数法显示
- oracle 失效对象自动重新编译
另外、你的两表的关联方法是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都没有建索引,我这样做合理吗?大家给点意见。