Insert 语句对 nologging 与 logging表 在不同场景下的优化
前言
前段时间报表数据库上有条insert sql语句,插入的大量数据,执行非常慢,需要对其进行分析优化。
分析步骤是在:ARCHIVE与NOARCHIVE模式下进行。
测试场景: 分别对表的常规插入,表在append插入,表在append + parallel插入进行性能测试,得出结果。
环境准备
| 数据库版本 | 基础表 | nologging表 | logging表 |
|---|---|---|---|
| Oracle 11g | T1 | T2 | T3 |
#创建T1,T2,T3表
create table t1 as select * from dba_objects;
create table t2 as select * from dba_objects where 1=2;
create table t3 as select * from dba_objects where 1=2;
#往T1表插入数据
SQL> insert into t1 select * from t1;
72813 rows created.
SQL> /
145626 rows created.
SQL> /
291252 rows created.
SQL> select count(*) from t1;
COUNT(*)
----------
582504
#设置T2表为nologging属性
SQL> alter table t2 nologging;
Table altered.
数据库处于ARCHIVE时
常规插入
nologging 表T2
SQL> insert into t2 select * from t1;
commit;
582824 rows created.
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 582K| 53M| 1455 (2)| 00:00:18 |
| 1 | LOAD TABLE CONVENTIONAL | T2 | | | | |
| 2 | TABLE ACCESS FULL | T1 | 582K| 53M| 1455 (2)| 00:00:18 |
---------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
3345 recursive calls
46879 db block gets
27878 consistent gets
8269 physical reads
67752144 redo size
838 bytes sent via SQL*Net to client
784 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
3 sorts (memory)
0 sorts (disk)
582824 rows processed
SQL>
Commit complete.
耗费:67752144 redo size
logging 表T3
SQL> insert into t3 select * from t1;
commit;
582824 rows created.
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 582K| 53M| 1455 (2)| 00:00:18 |
| 1 | LOAD TABLE CONVENTIONAL | T3 | | | | |
| 2 | TABLE ACCESS FULL | T1 | 582K| 53M| 1455 (2)| 00:00:18 |
---------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
2860 recursive calls
46875 db block gets
27811 consistent gets
1 physical reads
67875992 redo size
829 bytes sent via SQL*Net to client
784 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
SQL>
Commit complete.
耗费:67875992 redo size
append 插入
nologging 表T2
SQL> insert /*+ append */ into t2 select * from t1;
commit;
582824 rows created.
Execution Plan
----------------------------------------------------------
ERROR:
ORA-12838: cannot read/modify an object after modifying it in parallel
SP2-0612: Error generating AUTOTRACE EXPLAIN report
Statistics
----------------------------------------------------------
2627 recursive calls
9324 db block gets
8832 consistent gets
0 physical reads
143436 redo size
824 bytes sent via SQL*Net to client
798 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:143436 redo size
logging 表T3
SQL> insert /*+ append */ into t3 select * from t1;
582824 rows created.
Execution Plan
----------------------------------------------------------
ERROR:
ORA-12838: cannot read/modify an object after modifying it in parallel
SP2-0612: Error generating AUTOTRACE EXPLAIN report
Statistics
----------------------------------------------------------
2627 recursive calls
9327 db block gets
8832 consistent gets
0 physical reads
68384900 redo size
822 bytes sent via SQL*Net to client
797 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:68384900 redo size
parallel + append 插入
nologging 表T2
SQL> alter session enable parallel dml;
insert /*+ append parallel(2) */ into t2 select * from t1;
commit;
Session altered.
SQL>
582824 rows created.
Execution Plan
----------------------------------------------------------
ERROR:
ORA-12838: cannot read/modify an object after modifying it in parallel
SP2-0612: Error generating AUTOTRACE EXPLAIN report
Statistics
----------------------------------------------------------
52 recursive calls
32 db block gets
19 consistent gets
0 physical reads
21916 redo size
824 bytes sent via SQL*Net to client
809 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:21916 redo size
logging 表T3
SQL> alter session enable parallel dml;
insert /*+ append parallel(2)*/ into t3 select * from t1;
commit;
Session altered.
SQL>
582824 rows created.
Execution Plan
----------------------------------------------------------
ERROR:
ORA-12838: cannot read/modify an object after modifying it in parallel
SP2-0612: Error generating AUTOTRACE EXPLAIN report
Statistics
----------------------------------------------------------
50 recursive calls
33 db block gets
20 consistent gets
0 physical reads
21308 redo size
824 bytes sent via SQL*Net to client
808 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:21308 redo size
数据库处于NOARCHIVE时
常规插入
nologging 表T2
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 582K| 53M| 1455 (2)| 00:00:18 |
| 1 | LOAD TABLE CONVENTIONAL | T2 | | | | |
| 2 | TABLE ACCESS FULL | T1 | 582K| 53M| 1455 (2)| 00:00:18 |
---------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
2538 recursive calls
46869 db block gets
27796 consistent gets
8266 physical reads
67754744 redo size
824 bytes sent via SQL*Net to client
784 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:67754744 redo size
logging 表T3
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 582K| 53M| 1455 (2)| 00:00:18 |
| 1 | LOAD TABLE CONVENTIONAL | T3 | | | | |
| 2 | TABLE ACCESS FULL | T1 | 582K| 53M| 1455 (2)| 00:00:18 |
---------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
2593 recursive calls
46873 db block gets
27800 consistent gets
1600 physical reads
67757328 redo size
824 bytes sent via SQL*Net to client
784 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
3 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:67757328 redo size
append 插入
nologging 表T2
Statistics
----------------------------------------------------------
2627 recursive calls
9324 db block gets
8832 consistent gets
2993 physical reads
143480 redo size
822 bytes sent via SQL*Net to client
798 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:143480 redo size
logging 表T3
Statistics
----------------------------------------------------------
2627 recursive calls
9327 db block gets
8832 consistent gets
0 physical reads
143420 redo size
821 bytes sent via SQL*Net to client
798 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:143420 redo size
parallel + append 插入
nologging 表T2
Statistics
----------------------------------------------------------
50 recursive calls
32 db block gets
21 consistent gets
0 physical reads
21896 redo size
823 bytes sent via SQL*Net to client
810 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:21896 redo size
logging 表T3
Statistics
----------------------------------------------------------
50 recursive calls
33 db block gets
20 consistent gets
0 physical reads
21896 redo size
821 bytes sent via SQL*Net to client
809 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
582824 rows processed
耗费:21896 redo size
综合比较
| 属性 | 表名 | 常规插入产生的redo size | apppend插入产生的redo size | apppend + parallel插入产生的redo size |
|---|---|---|---|---|
| 数据库模式 | archive | |||
| nologing | t2 | 67752144 | 143436 | 21916 |
| loging | t3 | 67875992 | 68384900 | 21308 |
| 数据库模式 | noarchive | |||
| nologing | t2 | 67754744 | 143480 | 21896 |
| loging | t3 | 67757328 | 143420 | 21896 |
1)数据库处于ARCHIVE模式时,
对logging表执行append插入,是对性能没有优化的。加并行parallel才会有影响。
2)数据库处于NOARCHIVE模式时,对logging表执行append插入,可以有效的提升性能。当然加并行parallel效果会更好
Insert 语句对 nologging 与 logging表 在不同场景下的优化的更多相关文章
- oracle带条件的Insert语句
背景 在一条记录完结时,自动向表中加入一条新的记录,采用的是事务处理,修改现有记录,并新增一条记录,直接采用的insert语句会报错 //主键冲突 unique constraint (XXXXXX) ...
- SQL基础语法—insert语句
1 insert语句 insert语句用于插入数据到表中,其基本语法有以下三种: Syntax: INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IG ...
- 关于加快INSERT语句执行速度和HINT /*+ append */及/*+ append nologging */的使用
(非归档模式下)创建表T01: SQL> create table t01 as select * from dba_objects where 1=2; Table created. (非归档 ...
- SQLServer将表数据导出为Insert语句
从网上找到的方法,不过很不错,记录下来,也算是分享下~~ 有一个表,city,有列:cityID,cityName;将此表中所有数据,变为insert语句 select 'insert into ta ...
- 取得表中数据的insert语句
Build Insert Statements for the Existing Data in Tables 下面这个脚本实现了取得一个非空表中的所有insert语句 This script bui ...
- 【SQL Sever】将SQL Sever中的一个数据表的数据导出为insert语句
例如:这SQL Sever中的一张数据表,想要将这张数据表中的数据 转化成一个一个的insert语句存储在txt的文档中,那么不论走到那里这个insert语句一执行,我们就能将这个数据表中的数据 ...
- 使用C#导出MSSQL表数据Insert语句,支持所有MSSQL列属性
在正文开始之前,我们先看一下MSSQL的两张系统表sys.objects . syscolumnsMSDN中 sys.objects表的定义:在数据库中创建的每个用户定义的架构作用域内的对象在该表中均 ...
- select into from和insert into select from两种表复制语句区别
select into from和insert into select from两种表复制语句都是将源表source_table的记录插入到目标表target_table,但两句又有区别. 第一句(s ...
- 表数据转换为insert语句
/* 对象:导出物理表数据为Insert语句 描述:可以传递条件精确导出sql 加条件的前提是只知道相应的字段名及类型 */ from sysobjects where name ='proc_ins ...
随机推荐
- bzoj 1951: [Sdoi2010]古代猪文 【中国剩余定理+欧拉定理+组合数学+卢卡斯定理】
首先化简,题目要求的是 \[ G^{\sum_{i|n}C_{n}^{i}}\%p \] 对于乘方形式快速幂就行了,因为p是质数,所以可以用欧拉定理 \[ G^{\sum_{i|n}C_{n}^{i} ...
- Go语言Flag的简单示例
flag 命令行参数解析,大家可能不太清楚是什么命令行参数解析,不要紧,我们来看看: 他就是干这个活的 func FlagTest1(){ var username string var userag ...
- NOIp 2017 奶酪 【并查集】 By cellur925
题目传送门 Orz去年考场上做这道题的我应该还在抱怨没学过空间几何,不一会太困了就开始打瞌睡,然后为了防止睡觉开始在devc++上写默写离骚(逃 思路:如果两个空洞相交,那么把他们并在一个集合里.最后 ...
- 标准字符cp功能
#include<stdio.h> #include<fcntl.h> int main(int argc,char *argv[]) { FILE *src_fp,*des_ ...
- 记一次线上环境的内存溢出(java.lang.OutOfMemoryError)
事故背景 今天客户说风控项目有个别用户查询不到数据不是报错就是一直卡在那里,我就去那个接口看了下. 一看项目日志今天的都几个g了,平常也就几百兆吧,很明显出了问题. 请求接口后使用命令tail -f ...
- [转]POJ WA/RE指南
"POJ上头的题都是数学题",也不知道是那个家伙胡诌的--但是POJ的要求就是算法通过了也不让你AC.下面本人就这560题的经验,浅谈一下WA/RE了怎么办. 以下内容是扯淡-- ...
- Linux命令-自动挂载文件/etc/fstab功能详解
Linux命令-自动挂载文件etcfstab功能详解 一./etc/fstab文件的作用 磁盘被手动挂载之后都必须把挂载信息写入/etc/fstab这个文件中,否则下次开机启动时仍然需要重新挂载. 系 ...
- [SDOI2013]spring
Description Input Output Sample Input 3 3 1 2 3 4 5 6 1 2 3 0 0 0 0 0 0 4 5 6 Sample Output 2 HINT 容 ...
- 【洛谷5398】[Ynoi2018]GOSICK(二次离线莫队)
题目: 洛谷 5398 当我刚学莫队的时候,他们告诉我莫队能解决几乎所有区间问题: 现在,当我发现一个区间问题似乎难以用我所了解的莫队解决的时候,他们就把这题的正解叫做 XXX 莫队.--题记 (以上 ...
- AJPFX关于代码块的总结
代码块: { 执行语句; }(1) 当出现在局部位置时, 为局部代码块. 局部位置: 如语句块中, 函数中, 构造代码块中, 静 ...