oracle优化--表优化(临时表)-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

oracle优化--表优化(临时表)

一、创建临时表与普通表

创新互联建站主要从事网站制作、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务闽清,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

SQL> CREATE GLOBAL TEMPORARY TABLE TMP_TEST ON COMMIT PRESERVE ROWS AS SELECT * FROM emp;

Table created.

SQL> select count(0) from TMP_TEST;

  COUNT(0)

----------

14

SQL> CREATE GLOBAL TEMPORARY TABLE TMP_TEST1 ON COMMIT DELETE ROWS AS SELECT * FROM emp;

Table created.

SQL> select count(0) from TMP_TEST1;

  COUNT(0)

----------

 14

SQL> create table tmp_test2 as select * from emp;

Table created.

SQL> select count(0) from TMP_TEST2;

  COUNT(0)

----------

14

--由于创建tmp_test2为ddl,所以TMP_TEST1数据被清空;

SQL> select count(0) from TMP_TEST1;

  COUNT(0)

----------

0

--关闭会话重新打开,TMP_TEST数据也被清空

SQL> select count(0) from TMP_TEST;

  COUNT(0)

----------

0

二、分别对副本表进行增删改操作,对比性能,可以发现以下差别:

新增时:临时表的cr=8,普通表cr=11

修改时:临时表的cr=3,cost=2;普通表cr=7,cost=3

删除时:临时表的cr=3,cost=2;普通表cr=7,cost=3

所以临时表如果作为运算中间表做增删改运算时性能皆比普通表高

SQL> insert into SCOTT.TMP_TEST SELECT * FROM SCOTT.emp;

14 rows created.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  LOAD TABLE CONVENTIONAL  ( cr=8  pr=0 pw=0 time=548 us)

        14         14         14   TABLE ACCESS FULL EMP (cr=7 pr=0 pw=0 time=64 us cost=3 size=1218 card=14)

SQL> insert into SCOTT.TMP_TEST1 SELECT * FROM SCOTT.emp;

14 rows created.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  LOAD TABLE CONVENTIONAL  ( cr=8 pr=0 pw=0 time=566 us)

        14         14         14   TABLE ACCESS FULL EMP (cr=7 pr=0 pw=0 time=63 us cost=3 size=1218 card=14)

SQL> insert into SCOTT.TMP_TEST2 SELECT * FROM SCOTT.emp;

14 rows created.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  LOAD TABLE CONVENTIONAL  ( cr=11 pr=2 pw=0 time=784 us)

        14         14         14   TABLE ACCESS FULL EMP (cr=7 pr=0 pw=0 time=31 us cost=3 size=1218 card=14)

SQL> delete from SCOTT.TMP_TEST where SAL<=2500;

9 rows deleted.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  DELETE  TMP_TEST ( cr=3 pr=0 pw=0 time=125 us)

         9          9          9   TABLE ACCESS FULL TMP_TEST (cr=3 pr=0 pw=0 time=50 us cost=2 size=117 card=9)

SQL> delete from SCOTT.TMP_TEST1 where SAL<=2500;

9 rows deleted.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  DELETE  TMP_TEST1 ( cr=3 pr=0 pw=0 time=161 us)

         9          9          9   TABLE ACCESS FULL TMP_TEST1 (cr=3 pr=0 pw=0 time=77 us cost=2 size=117 card=9)

SQL> delete from SCOTT.TMP_TEST2 where SAL<=2500;

9 rows deleted.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  DELETE  TMP_TEST2 ( cr=7 pr=0 pw=0 time=105 us)

         9          9          9   TABLE ACCESS FULL TMP_TEST2 (cr=7 pr=0 pw=0 time=13 us cost=3 size=117 card=9)

SQL> update SCOTT.TMP_TEST set sal=sal+100;

5 rows updated.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  UPDATE  TMP_TEST ( cr=3 pr=0 pw=0 time=132 us)

         5          5          5   TABLE ACCESS FULL TMP_TEST (cr=3 pr=0 pw=0 time=46 us cost=2 size=65 card=5)

SQL> update SCOTT.TMP_TEST1 set sal=sal+100;

5 rows updated.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  UPDATE  TMP_TEST1 ( cr=3 pr=0 pw=0 time=132 us)

         5          5          5   TABLE ACCESS FULL TMP_TEST1 (cr=3 pr=0 pw=0 time=34 us cost=2 size=65 card=5)

SQL> update SCOTT.TMP_TEST2 set sal=sal+100;

5 rows updated.

Rows (1st) Rows (avg) Rows (max)  Row Source Operation

---------- ---------- ----------  ---------------------------------------------------

         0          0          0  UPDATE  TMP_TEST2 ( cr=7 pr=0 pw=0 time=69 us)

         5          5          5   TABLE ACCESS FULL TMP_TEST2 (cr=7 pr=0 pw=0 time=15 us cost=3 size=65 card=5)


当前标题:oracle优化--表优化(临时表)
转载来于:http://kswsj.cn/article/ghosih.html

其他资讯