oracle数据库为啥某个表查询很慢--oracle高水位线
oracle数据库,其他表都读取很快,这个表数据量也就是4-5万左右的内容,为啥读取起来却特别慢。与这个表做关联的sql语句,也响应的变慢了。而且奇怪的是,某些时候,确实又异常的快。这是什么奇怪的原因呢?
起因:
近几天,发现生产系统的某个页面,查询特别的慢。相关的表其实数据量并不多的。无奈,只能添加索引,草草了事。以为这样就可以了吗?过了几天,又有另外一个使用到这个表的sql出现查询缓慢了。意识到问题可能不仅仅是索引没加,这时想到可能是因为这个表一直在做delete,insert定时任务的原因。后面发现,果然是和oracle和一个特性有关:高水位线(HWM)。
如何解决:
以scott.t3表举例:
开启行迁移 alter table scott.t3 enable row movement; --先压缩 alter table scott.t3 shrink space compact; analyze table scott.t3 compute statistics for table; --降低水位线 alter table scott.t3 shrink space; --关闭行迁移 alter table scott.t3 disable row movement;