大剑
天天加班,哪有时间写博客 ---- 专注于ERP软件开发技术,关注Oracle相关技术

实表和临时表查询速度比较和优化

glave posted @ 2010年1月13日 04:10 in ORACLE with tags oracle 临时表,实表,查询速度 , 2299 阅读

实表和临时表查询速度比较和优化

Oracle中的临时表给我们的数据交换带来了很大的便利,但便利的同时又隐藏着危机。
曾经做过一个实验:
检索200W条数据的时候,   当数据为实表,只需不到5分钟时间
        当数据为临时表,却需要40分钟以上。
这是非常可怕的,分析一下原因,可能有以下原因。

首先,Oracle管理员会根据实际需求为数据库分配表空间,临时表和实表的表空间是独立的,
也就是说,需要分别设置。
一般会把大部分空间分给实表,临时表只分配一小部分。
例如:一个10G大小的数据库,临时表也许只会分配200M,当然临时表是可自动扩展的。
200M大小其实对一般应用已经足够,但是但设计到数量级特别大的时候,
临时表空间不足,他就会向系统索取资源,当无法从内存获得空间,就会从硬盘获取空间
这样,速度显而易见是很慢的。
其次,实表在表建立的时候就已经分配了表空间,临时表则是在使用的时候分配表空间,
这样,给庞大的数据分配空间也就成了一个庞大的消耗,而且,这些空间也许都不是连续的
分散在硬盘的各个可能的地方,自然就会影响到整个查询速度。
有一个很明显的例子就是,当这些临时表的数据被删除的时候,都会话费相当的时间。

如何避免呢?
可能还没有最彻底的方案,但是可以减小。
首先,临时表的表空间合理分配大小,但也不能太大,临时表空间会记录最大的一次空间,
这样会造成资源不必要的浪费。
第二,建立临时表索引,这样会大大加快速度。
第三,优化SQL语句。尽量少用 not in, in, not exists,exists,decode等函数。
 

Avatar_small
Jharkhand 7th Model 说:
2023年9月14日 15:29

State Council of Educational Research and Training (SCERT) Jharkhand has Going to Conducted High School Aunval Exam 2024, SCERT Jharkhand which is Mainly Responsible for Conducting Exam Every year, This SCERT Jharkhand 7th Exam Very Year More Than 25 Laks of Students Attended, SCERT Jharkhand is Administered by the State Government of Jharkhand and Thrives to Improve the Quality of Jharkhand 7th Model Paper 2024 Education in the state.SCERT Jharkhand is also Responsible for Prescribing the SCERT Jharkhand Model Paper 2024 for the Students Studying in the Jharkhand Affiliated Schools, Jharkhand Question Paper 2024 Designed by Senior Experts Study Materiel help the Students to get an idea about the Final Exam 2024.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter