CREATE GLOBAL TEMPORARY TABLE TMP_TEST ON COMMIT PRESERVE ROWS AS SELECT * FROM emp; Table created. SQL> s..."/>
溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

oracle優(yōu)化--表優(yōu)化(臨時(shí)表)

發(fā)布時(shí)間:2020-08-07 18:33:08 來(lái)源:ITPUB博客 閱讀:194 作者:wysyl1990 欄目:關(guān)系型數(shù)據(jù)庫(kù)

一、創(chuàng)建臨時(shí)表與普通表


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


--由于創(chuàng)建tmp_test2為ddl,所以TMP_TEST1數(shù)據(jù)被清空;


SQL> select count(0) from TMP_TEST1;


  COUNT(0)

----------

0


--關(guān)閉會(huì)話重新打開,TMP_TEST數(shù)據(jù)也被清空


SQL> select count(0) from TMP_TEST;


  COUNT(0)

----------

0


二、分別對(duì)副本表進(jìn)行增刪改操作,對(duì)比性能,可以發(fā)現(xiàn)以下差別:


新增時(shí):臨時(shí)表的cr=8,普通表cr=11

修改時(shí):臨時(shí)表的cr=3,cost=2;普通表cr=7,cost=3

刪除時(shí):臨時(shí)表的cr=3,cost=2;普通表cr=7,cost=3


所以臨時(shí)表如果作為運(yùn)算中間表做增刪改運(yùn)算時(shí)性能皆比普通表高


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)


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI