很多情况下我们都会需要复制源表数据以达到冗余数据的目的,那么到底是使用CREATE TABLE AS SELECT的CTAS方式,还是先建好表的结构然后再插入数据好呢? 我们来看看这2种方式的不同表现:

SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - ProductionSQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2/* 数据库处于归档模式下 */SQL> select ss.name,ms.value  from v$mystat ms,v$sysstat ss2  where3  ms.statistic#=ss.statistic#4  and ss.name in ('undo change vector size','redo size');
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                                 0
undo change vector size                                                   0SQL> create table YOUYUS as select * from dba_objects;
Table created.SQL> select ss.name,ms.value  from v$mystat ms,v$sysstat ss2  where3  ms.statistic#=ss.statistic#4  and ss.name in ('undo change vector size','redo size');
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                           5783384
undo change vector size                                               15408
/* CTAS方式产生了少量的undo,可以猜想其使用直接路径方式插入,Oracle仅产生维护数据字典的undo */SQL> drop table YOUYUS;
Table dropped.SQL> conn / as sysdba
Connected./* 清理现场 */SQL> create table YOUYUS as select * from dba_objects where 0=1;
Table created.SQL> select ss.name,ms.value  from v$mystat ms,v$sysstat ss2  where3  ms.statistic#=ss.statistic#4  and ss.name in ('undo change vector size','redo size');NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                             19492
undo change vector size                                                5680/* 建立空表YOUYUS,同样需要维护数据字典  */SQL> insert into YOUYUS select * from dba_objects;50729 rows created.SQL> commit;Commit complete.SQL> select ss.name,ms.value  from v$mystat ms,v$sysstat ss2  where3  ms.statistic#=ss.statistic#4  and ss.name in ('undo change vector size','redo size');NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                           5743540
undo change vector size                                              203904/* 普通insert操作产生了远大于CTAS的undo */SQL> drop table YOUYUS;
Table dropped.SQL> conn / as sysdba
Connected.SQL> select ss.name,ms.value  from v$mystat ms,v$sysstat ss2  where3  ms.statistic#=ss.statistic#4  and ss.name in ('undo change vector size','redo size');NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                                 0
undo change vector size                                                   0SQL> create table YOUYUS as select * from dba_objects where 0=1;
Table created.SQL> insert /*+ append */ into YOUYUS select * from dba_objects;
50729 rows created.SQL> commit;Commit complete.SQL> select ss.name,ms.value  from v$mystat ms,v$sysstat ss2  where3  ms.statistic#=ss.statistic#4  and ss.name in ('undo change vector size','redo size');
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                           5781712
undo change vector size                                               14808/* 建表后直接路径插入方式与CTAS产生的redo和undo数量大致相仿 */

从资源消耗的角度讲CTAS或直接路径插入方式有一定优势,如果启用nologging选项的话这种优势会更加显著。

转载于:https://www.cnblogs.com/macleanoracle/archive/2010/09/07/2967529.html

CTAS VS create table and then insert相关推荐

  1. oracle中create table as和insert into select语句

    SELECT INTO , INSERT INTO SELECT 和 CREATE TABLE AS SELECT INSERT INTO SELECT Create table newTable a ...

  2. create table ,create table as 与create like三种建表方式的使用详解

    Hive的hql是基于sql而来,而sql中关于表的创建有几种方式.同样,hive也支持这些表的创建方式.  官网文档关于建表的地址:hive常见建表方式官网文档 1.自主创业方式create tab ...

  3. oracle中create table with as和insert into with as语句

    oracle支持使用with as 子句来创建表 语法: create table table_name as with clause_name as (select query ) [, claus ...

  4. oracle数据库【表复制】insert into select from跟create table as select * from 两种表复制语句区别...

    create table  as select * from和insert into select from两种表复制语句区别 create table targer_table as select ...

  5. ireport修改jrxml中的sql语句_SQL中的create table与insert into语句

    学习交流,欢迎留言~~ 今天学习SQL的时候遇到了个小疑问,创建数据表肯定是用create table语句的,但是为什么后面总是跟随着insert into呢? 身为一个不弄白不舒服斯基,走起~~~ ...

  6. oracle insert into as select,比较create table as select * 与 insert into table select *

    实验环境: SYS@aaron> select * from v$version; BANNER ------------------------------------------------ ...

  7. sql语句-create table XXX select 和 insert into XXX select 语句的使用

    无需先建表,并将select的查询结果导入到新表中 CREATE TABLE new_emp AS SELECT * FROM emp WHERE deptno IN(20, 30); 将select ...

  8. postgres语法_SQL Create Table解释了MySQL和Postgres的语法示例

    postgres语法 A table is a group of data stored in a database. 表是存储在数据库中的一组数据. To create a table in a d ...

  9. Oracle中,使 CREATE TABLE AS SELECT 支持ORDER BY

    Oracle中,使 CREATE TABLE AS SELECT 支持ORDER BY 文章发表:kehui  发表日期:2002-01-21  阅读次数:1103  大家都知道,"CREA ...

最新文章

  1. Windows Azure平台Win VM密码重置
  2. hdu2371 矩阵乘法(求序列位置改变m次后的序列)
  3. 从程序设计角度看B/S C/S到底有什么不同???
  4. 浅谈中大型企业CMDB的建设
  5. HttpURLConnection和HttpClient的简单用法
  6. dokcer mysql修改编码_默认支持utf8编码的mysql docker镜像
  7. java 写入指定路径文件_java对指定目录下文件读写操作介绍 | 学步园
  8. C语言学习笔记---001C语言的介绍,编译过程原理,工具等
  9. 浅谈UWB室内定位(二)_vortex_新浪博客
  10. 奇妙的go语言(面向对象)
  11. SQL的别名和SQL的执行顺序和SQL优化
  12. php 串行化与json(转)--很不错的文章
  13. [Linux学习]更改默认启动图形界面或命令行
  14. 云创大数据荣获“南京实体经济十大优秀企业”
  15. ogg格式怎样才能转换成MP3格式
  16. 如何写好一篇科技论文?
  17. 使用ceph-deploycep集群部署,并用3个磁盘作为专用osd
  18. php直播平台原理,php直播平台源码的直播带货平台有何技巧,别说没告诉你
  19. 国家集训队 种树 题解
  20. SmartBI入门(一)介绍和安装

热门文章

  1. 解决 Ubuntu 无法更新软件问题
  2. Android通过Geth RPC接口实现接入以太坊私有链
  3. 2017年10大年度最佳的ICO项目
  4. 线程间通讯机制(基础篇)——Handler、Runnable、HandlerThread、AsyncTask的使用
  5. Rxjava+Retrofit的使用实例(基于retrofit2.1.0)
  6. oracle数据库的性能测试工具有哪些,使用Oracle性能测试工具swingbench测试instance caging...
  7. anaconda tensorflow 2.3_2020款福特撼路者将于7月17日上市 动力升级/搭载2.3T+10AT
  8. A % B Problem
  9. BZOJ 1488 Luogu P4727 [HNOI2009]图的同构 (群论、Burnside引理、组合计数)
  10. Luogu P1198 BZOJ 1012 最大数 (线段树)