Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1151400
  • 博文数量: 166
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3760
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-30 13:00
个人简介

About me:Oracle ACE pro,optimistic,passionate and harmonious. Focus on ORACLE,MySQL and other database programming,peformance tuning,db design, j2ee,Linux/AIX,Architecture tech,etc

文章分类

全部博文(166)

文章存档

2024年(18)

2023年(28)

2022年(43)

2020年(62)

2014年(3)

2013年(9)

分类: Oracle

2022-04-11 09:15:08

网上到处都是什么nologging放在insert 语句里减少redo size的说法,但是很少看到有数据来说明,或者测试的环境有所差别,其他的不说了,nologging那个eygle网站上有,append神马情况下减少redo,nologging用在神马情况下也不说了,就来说说那个insert append nologging语句以及测试了append到底是减少redo还是undo?。

create table t nologging as select ..........  这个有效,因为这个是建立一个nologging table ,为t

归档模式下测试,非归档模式,append hint可以减少redo的

--case 1:测试结果 ctas中对源表nolgging有效果,减少redo
dingjun123@ORADB> select * from redo_size;

     VALUE
----------
      1552

已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> create table t  as select * from all_objects;

表已创建。

已用时间:  00: 00: 05.90
dingjun123@ORADB> select * from redo_size;

     VALUE
----------
  8759612

已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> drop table t;

表已删除。

已用时间:  00: 00: 00.18
dingjun123@ORADB> create table t nologging as select * from all_objects;

表已创建。

已用时间:  00: 00: 08.30


dingjun123@ORADB> select * from redo_size;

     VALUE
----------
   8884200

已选择 1 行。

已用时间:  00: 00: 00.00


--case2:insert append hint +nologging???????无效果,不知道这语法从哪蹦出来的,到处引用
--下面的报错,但是把那别名换成nologging,放在源表位置和目标表位置竟然正确,这语法哪来的?在文档上没有找到,文档上的nologging不是这么在insert 里用的


dingjun123@ORADB> drop table t;

表已删除。

已用时间:  00: 00: 00.26
dingjun123@ORADB> insert into t m as select * from dual;
insert into t m as select * from dual
                *
第 1 行出现错误:
ORA-00926: 缺失 VALUES 关键字


已用时间:  00: 00: 00.01

dingjun123@ORADB> insert into t  as select * from dual x;
insert into t  as select * from dual x
               *
第 1 行出现错误:
ORA-00926: 缺失 VALUES 关键字


已用时间:  00: 00: 00.01


--开始测试,未见redo减少,但是那个nologging不报错,这是网上典型的说insert+append+nologging可以减少redo的说法

dingjun123@ORADB> create table t as select * from all_objects where 1=0;

表已创建。

已用时间:  00: 00: 00.81
dingjun123@ORADB> select * from redo_size;

     VALUE
----------
   8946112


已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> insert /*+ append */ into t select * from all_objects nologging;

已创建73940行。

已用时间:  00: 00: 10.48
dingjun123@ORADB> select * from redo_size;

     VALUE
----------
  17661336

已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> rollback;

回退已完成。

已用时间:  00: 00: 00.00
dingjun123@ORADB> select * from redo_size;

     VALUE
----------
  17661460

已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> insert /*+ append */ into t nologging select * from all_objects;

已创建73940行。

已用时间:  00: 00: 09.40
dingjun123@ORADB> select * from redo_size;

     VALUE
----------
  26318524

已选择 1 行。

已用时间:  00: 00: 00.01


--见Apress pro oracle sql beyond the select,开头就引入了这种用法,要注意,这不对
Direct Path Inserts
Direct path inserts can be invoked by using the APPEND hint (parallel inserts do this by default, by the
way). In Oracle Database 11g Release 2, there is a new APPEND_VALUES hint that can be used for
inserts that specify a values clause as opposed to using a SELECT to provide the values for inserting.
Listing 13-1 shows a simple example of both forms.
Listing 13-1. Simple Insert APPEND and APPEND_VALUES
insert /*+ append */ into kso.big_emp select * from hr.employees nologging;
insert /*+ append_values */ into dual (dummy) values ('Y');

----------------------------------------------------append hint到底减少redo还是undo-------------------------------------------------


还有那个append hint,好多地方说是减少redo的,其实不是的,append hint是减少对应table操作的产生undo,不是redo,append hint在非归档模式下的确可以减少redo产生,但是不能说append hint就减少了redo,可以看eygle那个“nologging何时才能生效”,append hint要在归档模式下减少redo,必须目标表是nologging的才可以。


append hint到底是神马东西??direct path insert,这个不说了,和神马HWM有关系,然后就是各种utility,比如神马sqlldr等,都有direct选项,然后神马parallel里的dml也是用了神马append,append神马滴后面不结束事务都不让你select,神马滴加了X锁。。。。。。。。。统统滴不研究。


下面测试append hint不管在归档非归档模式下,肯定是减少undo的

--case1:在归档模式下,结论:append hint是可以减少undo的

dingjun123@ORADB> create table t as select * from all_objects where 1=0;

表已创建。

已用时间:  00: 00: 00.76
dingjun123@ORADB> select * from undo_size;

     VALUE
----------
    114716

已选择 1 行。

已用时间:  00: 00: 00.00
dingjun123@ORADB> insert  into t  select * from all_objects;

已创建73941行。

已用时间:  00: 00: 09.31
dingjun123@ORADB> select * from undo_size;

     VALUE
----------
    399048

已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> rollback;

回退已完成。

已用时间:  00: 00: 00.04
dingjun123@ORADB> select * from undo_size;

     VALUE
----------
    399048

已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> insert /*+ append */  into t  select * from all_objects;

已创建73941行。

已用时间:  00: 00: 12.21
dingjun123@ORADB> select * from undo_size;

     VALUE
----------
    404732

已选择 1 行。

已用时间:  00: 00: 00.00
dingjun123@ORADB> rollback;

回退已完成。

已用时间:  00: 00: 00.14


--case2:在非归档模式下,append同样可以减少undo

dingjun123@ORADB> select * from undo_size;

     VALUE
----------
       108

已选择 1 行。

已用时间:  00: 00: 00.15
dingjun123@ORADB> insert /*+ append */  into t  select * from all_objects;

已创建73941行。

已用时间:  00: 00: 10.99
dingjun123@ORADB> select * from undo_size;

     VALUE
----------
       320

已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> rollback;

回退已完成。

已用时间:  00: 00: 00.01
dingjun123@ORADB> insert  into t  select * from all_objects;

已创建73941行。

已用时间:  00: 00: 12.15
dingjun123@ORADB> select * from undo_size;

     VALUE
----------
    270776

已选择 1 行。

已用时间:  00: 00: 00.01
dingjun123@ORADB> rollback;

回退已完成。

已用时间:  00: 00: 00.04
阅读(717) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~