Oracle 物化檢視快速重新整理對效能的影響

selectshen發表於2016-11-05
一個表上存在物化檢視日誌和基於物化檢視日誌快速重新整理的物化檢視,如果對這個表進行DML操作,則Redolog產生量將翻數倍,並且執行時間加長,影響併發操作。

下面主要透過在Redolog產生量和執行時間上做對比:
DB Version:12.1.0.2.0
OS:CentOS 6.6

[oracle@ct6603 ~]$ sqlplus system/system

SQL*Plus: Release 12.1.0.2.0 Production on Sat Nov 5 17:11:31 2016

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Last Successful login time: Sat Nov 05 2016 17:11:12 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
#建測試表
SQL> create table tb_rowid tablespace users as select * from dba_objects;

Table created.
#記錄時間
SQL> set timing on
#設定自動提交
SQL> set autocommit on
#跟蹤統計資訊
SQL> set autotrace on stat

#表tb_rowid上無物化檢視日誌
#插入9999筆記錄,Redolog產生量1249324,耗時00:00:00.21
SQL> insert into tb_rowid select * from tb_rowid where rownum<10000;

9999 rows created.

Commit complete.
Elapsed: 00:00:00.21

Statistics
----------------------------------------------------------
         42  recursive calls
       1105  db block gets
        497  consistent gets
        508  physical reads
    1249324  redo size
        859  bytes sent via SQL*Net to client
        870  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          3  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#插入9999筆記錄,Redolog產生量1248532,耗時00:00:00.17
SQL> insert into tb_rowid select * from tb_rowid where rownum<10000;

9999 rows created.

Commit complete.
Elapsed: 00:00:00.17

Statistics
----------------------------------------------------------
          4  recursive calls
       1087  db block gets
        324  consistent gets
        245  physical reads
    1248532  redo size
        861  bytes sent via SQL*Net to client
        870  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#刪除9999筆記錄,Redolog產生量4147948,耗時00:00:00.50
SQL> delete tb_rowid where rownum<10000;

9999 rows deleted.

Commit complete.
Elapsed: 00:00:00.50

Statistics
----------------------------------------------------------
          9  recursive calls
      11277  db block gets
        225  consistent gets
        276  physical reads
    4147948  redo size
        861  bytes sent via SQL*Net to client
        842  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#刪除9999筆記錄,Redolog產生量4164704,耗時00:00:00.60
SQL> delete tb_rowid where rownum<10000;

9999 rows deleted.

Commit complete.
Elapsed: 00:00:00.60

Statistics
----------------------------------------------------------
          3  recursive calls
      11293  db block gets
        319  consistent gets
        104  physical reads
    4164704  redo size
        863  bytes sent via SQL*Net to client
        842  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#更新9999筆記錄,Redolog產生量2725824,耗時00:00:00.48
SQL> update tb_rowid set object_id=1 where rownum<10000;

9999 rows updated.

Commit complete.
Elapsed: 00:00:00.48

Statistics
----------------------------------------------------------
          8  recursive calls
      10233  db block gets
        548  consistent gets
        145  physical reads
    2725824  redo size
        863  bytes sent via SQL*Net to client
        858  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#更新9999筆記錄,Redolog產生量957056,耗時00:00:00.13
SQL> update tb_rowid set object_id=2 where rownum<10000;

9999 rows updated.

Commit complete.
Elapsed: 00:00:00.13

Statistics
----------------------------------------------------------
          8  recursive calls
        294  db block gets
        548  consistent gets
          0  physical reads
     957056  redo size
        864  bytes sent via SQL*Net to client
        858  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#更新9999筆記錄,Redolog產生量961224,耗時00:00:00.14
SQL> update tb_rowid set object_id=2 where rownum<10000;

9999 rows updated.

Commit complete.
Elapsed: 00:00:00.14

Statistics
----------------------------------------------------------
          1  recursive calls
        294  db block gets
        489  consistent gets
          0  physical reads
     961224  redo size
        864  bytes sent via SQL*Net to client
        858  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
       9999  rows processed

#表tb_rowid上有物化檢視日誌
#建物化檢視日誌
SQL> create  materialized view log on tb_rowid with rowid including new values;

Materialized view log created.

Elapsed: 00:00:00.34

#插入9999筆記錄,Redolog產生量10905808,耗時00:00:03.73
SQL> insert into tb_rowid select * from tb_rowid where rownum<10000;

9999 rows created.

Commit complete.
Elapsed: 00:00:03.73

Statistics
----------------------------------------------------------
        176  recursive calls
      43316  db block gets
       1227  consistent gets
        104  physical reads
   10905808  redo size
        862  bytes sent via SQL*Net to client
        870  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
         14  sorts (memory)
          0  sorts (disk)
       9999  rows processed

#插入9999筆記錄,Redolog產生量11015104,耗時00:00:04.03
SQL> insert into tb_rowid select * from tb_rowid where rownum<10000;

9999 rows created.

Commit complete.
Elapsed: 00:00:04.03

Statistics
----------------------------------------------------------
         32  recursive calls
      42863  db block gets
       6438  consistent gets
          2  physical reads
   11015104  redo size
        865  bytes sent via SQL*Net to client
        870  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#刪除9999筆記錄,Redolog產生量11019692,耗時00:00:03.88
SQL> delete tb_rowid where rownum<10000;

9999 rows deleted.

Commit complete.
Elapsed: 00:00:03.88

Statistics
----------------------------------------------------------
         43  recursive calls
      42877  db block gets
        572  consistent gets
         27  physical reads
   11019692  redo size
        865  bytes sent via SQL*Net to client
        842  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          3  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#刪除9999筆記錄,Redolog產生量11010468,耗時00:00:03.73
SQL> delete tb_rowid where rownum<10000;

9999 rows deleted.

Commit complete.
Elapsed: 00:00:03.73

Statistics
----------------------------------------------------------
         18  recursive calls
      42846  db block gets
        592  consistent gets
          0  physical reads
   11010468  redo size
        865  bytes sent via SQL*Net to client
        842  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
       9999  rows processed

#更新9999筆記錄,Redolog產生量16150340,耗時00:00:06.94
SQL> update tb_rowid set object_id=2 where rownum<10000;

9999 rows updated.

Commit complete.
Elapsed: 00:00:06.94

Statistics
----------------------------------------------------------
         51  recursive calls
      73132  db block gets
       1292  consistent gets
        109  physical reads
   16150340  redo size
        865  bytes sent via SQL*Net to client
        858  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          3  sorts (memory)
          0  sorts (disk)
       9999  rows processed

#更新9999筆記錄,Redolog產生量16078152,耗時00:00:07.19
SQL> update tb_rowid set object_id=2 where rownum<10000;

9999 rows updated.

Commit complete.
Elapsed: 00:00:07.19

Statistics
----------------------------------------------------------
         30  recursive calls
      91767  db block gets
       1160  consistent gets
          1  physical reads
   16078152  redo size
        865  bytes sent via SQL*Net to client
        858  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
       9999  rows processed

#表tb_rowid上有快速重新整理物化檢視
#建物化檢視mv_tb_rowid
SQL> create materialized view mv_tb_rowid tablespace users refresh fast on commit with rowid as select * from  tb_rowid;

Materialized view created.

Elapsed: 00:00:29.52

#插入9999筆記錄,Redolog產生量20177192,耗時00:00:08.98
SQL> insert into tb_rowid select * from tb_rowid where rownum<10000;

9999 rows created.

Commit complete.
Elapsed: 00:00:08.98

Statistics
----------------------------------------------------------
       1415  recursive calls
      98178  db block gets
       4696  consistent gets
        412  physical reads
   20177192  redo size
        866  bytes sent via SQL*Net to client
        870  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
         92  sorts (memory)
          0  sorts (disk)
       9999  rows processed
       
#插入9999筆記錄,Redolog產生量19942160,耗時00:00:07.26
SQL>  insert into tb_rowid select * from tb_rowid where rownum<10000;

9999 rows created.

Commit complete.
Elapsed: 00:00:07.26

Statistics
----------------------------------------------------------
        223  recursive calls
      97346  db block gets
       7576  consistent gets
          1  physical reads
   19942160  redo size
        866  bytes sent via SQL*Net to client
        871  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
         24  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#刪除9999筆記錄,Redolog產生量25751700,耗時00:00:08.75
SQL> delete tb_rowid where rownum<10000;

9999 rows deleted.

Commit complete.
Elapsed: 00:00:08.75

Statistics
----------------------------------------------------------
        227  recursive calls
     136425  db block gets
       2362  consistent gets
          0  physical reads
   25751700  redo size
        866  bytes sent via SQL*Net to client
        842  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
         24  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#刪除9999筆記錄,Redolog產生量25890548,耗時00:00:08.73
SQL> delete tb_rowid where rownum<10000;

9999 rows deleted.

Commit complete.
Elapsed: 00:00:08.73

Statistics
----------------------------------------------------------
        204  recursive calls
     136332  db block gets
       2223  consistent gets
        241  physical reads
   25890548  redo size
        868  bytes sent via SQL*Net to client
        842  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
         22  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#更新9999筆記錄,Redolog產生量42848860,耗時00:00:18.52
SQL> update tb_rowid set object_id=2 where rownum<10000;

9999 rows updated.

Commit complete.
Elapsed: 00:00:18.52

Statistics
----------------------------------------------------------
        902  recursive calls
     249586  db block gets
       5487  consistent gets
        292  physical reads
   42848860  redo size
        868  bytes sent via SQL*Net to client
        858  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
         24  sorts (memory)
          0  sorts (disk)
       9999  rows processed
#更新9999筆記錄,Redolog產生量43267360,耗時00:00:16.95
SQL> update tb_rowid set object_id=2 where rownum<10000;

9999 rows updated.

Commit complete.
Elapsed: 00:00:16.95

Statistics
----------------------------------------------------------
        215  recursive calls
     250097  db block gets
       4048  consistent gets
          0  physical reads
   43267360  redo size
        868  bytes sent via SQL*Net to client
        858  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
         22  sorts (memory)
          0  sorts (disk)
       9999  rows processed
        
總結:
        表上無物化檢視日誌    表上有物化檢視日誌     表上有物化檢視日誌且有一個快速重新整理的物化檢視
插入        1M/0.21秒            10M/3.73秒                20M/8.98秒
刪除        4M/0.5秒            10M/3.88秒                 25M/8.75秒
更新        1M/0.13秒            15M/6.94秒                40M/18.52秒

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-2127870/,如需轉載,請註明出處,否則將追究法律責任。

相關文章