实验:分区别对比普通表
来源:互联网 发布:武汉小孩学钢琴知乎 编辑:程序博客网 时间:2024/04/30 17:32
创建分区表
range的
create table rg_yzy (
OBJECT_NAME VARCHAR2(128),
OBJECT_ID number,
CREATED date not null)
partition by range(created)
(
partition rg_001 values less than (to_date('2012/01/01','yyyy/mm/dd')),
partition rg_002 values less than (to_date('2013/01/01','yyyy/mm/dd'))
);
ORA-14037: partition bound of partition "RG_001" is too high
http://blog.csdn.net/pengje/article/details/1551216
创建本地索引
create index idx_rg_yzy on rg_yzy(created) local
(partition rg_001 tablespace users,
partition rg_002 tablespace users);
插入数据
insert into rg_yzy select OBJECT_NAME,object_id,created from dba_objects where created < to_date('2013/01/01','yyyy/mm/dd') and object_id is not null;
ORA-14400: inserted partition key does not map to any partition
http://stackoverflow.com/questions/24454591/oracle-partition-error-ora14400-inserted-partition-key-does-not-map-to-any-p
插入失败,调整后插入0行!
增加一个分区
alter table rg_yzy add partition rg_003 values less than (to_date('2015/01/01','yyyy/mm/dd'));
SQL> select segment_name,partition_name,tablespace_name from dba_segments where segment_name='IDX_RG_YZY';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------------------------------------------------------------------- ------------------------------ ---------------------
IDX_RG_YZY RG_003 USERS
IDX_RG_YZY RG_002 USERS
IDX_RG_YZY RG_001 USERS
SQL> select segment_name,partition_name,tablespace_name from dba_segments where segment_name='RG_YZY';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------------------------------------------------------------------- ------------------------------ ----------------------
RG_YZY RG_003 USERS
RG_YZY RG_002 USERS
RG_YZY RG_001 USERS
可见分区索引是自动维护的
再次插入数据:
insert into rg_yzy select OBJECT_NAME,object_id,created from dba_objects where created < to_date('2015/01/01','yyyy/mm/dd') and object_id is not null;
87752 rows inserted
SQL> commit;
Commit complete
SQL> select count(*) from rg_yzy partition(rg_001);
COUNT(*)
----------
0
SQL> select count(*) from rg_yzy partition(rg_002);
COUNT(*)
----------
0
SQL> select count(*) from rg_yzy partition(rg_003);
COUNT(*)
----------
87752
发现不符合对测试环境的要求
修改分区,数据不合适,直接update
SQL> alter table lcl.rg_yzy enable row movement;
Table altered
SQL> update rg_yzy set created = to_date('2012/08/24','yyyy/mm/dd') where rownum<40000;
39999 rows updated
SQL> commit;
Commit complete
SQL> alter table lcl.rg_yzy disable row movement;
Table altered
SQL> select count(*) from rg_yzy partition(rg_003);
COUNT(*)
----------
47753
SQL> select count(*) from rg_yzy partition(rg_002);
COUNT(*)
----------
39999
SQL> select count(*) from rg_yzy partition(rg_001);
COUNT(*)
----------
0
SQL> alter table lcl.rg_yzy enable row movement;
Table altered
SQL> update rg_yzy set created = to_date('2011/08/24','yyyy/mm/dd') where rownum<1000;
999 rows updated
SQL> alter table lcl.rg_yzy disable row movement;
Table altered
SQL> commit;
Commit complete
SQL> select count(*) from rg_yzy partition(rg_003);
COUNT(*)
----------
47753
SQL> select count(*) from rg_yzy partition(rg_002);
COUNT(*)
----------
39000
SQL> select count(*) from rg_yzy partition(rg_001);
COUNT(*)
----------
999
现在可以了,实验开始
创建数据量一样的普通表
SQL> create table rg_yzy_cm as select OBJECT_NAME,OBJECT_ID,CREATED from dba_objects;
Table created
update数据
SQL> update rg_yzy_cm set created = to_date('2012/08/24','yyyy/mm/dd') where rownum<40000;
39999 rows updated
SQL> commit;
Commit complete
SQL> update rg_yzy_cm set created = to_date('2011/08/24','yyyy/mm/dd') where rownum<1000;
999 rows updated
SQL> commit;
Commit complete;
查询速度对比:
select count(*) from rg_yzy where created<to_date('2012/08/20','yyyy/mm/dd');
select count(*) from rg_yzy_cm where created<to_date('2012/08/20','yyyy/mm/dd');
分区表:
SQL> select count(*) from rg_yzy where created<to_date('2012/08/20','yyyy/mm/dd');
999
Execution Plan
----------------------------------------------------------
Plan hash value: 504157362
--------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 11 (0)| 00:00:01 | | |
| 1 | SORT AGGREGATE | | 1 | 9 | | | | |
| 2 | PARTITION RANGE ITERATOR| | 999 | 8991 | 11 (0)| 00:00:01 | 1 | 2 |
|* 3 | INDEX RANGE SCAN | IDX_RG_YZY | 999 | 8991 | 11 (0)| 00:00:01 | 1 | 2 |
--------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("CREATED"<TO_DATE(' 2012-08-20 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
7 recursive calls
0 db block gets
76 consistent gets
0 physical reads
0 redo size
527 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
数据量不太行啊。。。。
range的
create table rg_yzy (
OBJECT_NAME VARCHAR2(128),
OBJECT_ID number,
CREATED date not null)
partition by range(created)
(
partition rg_001 values less than (to_date('2012/01/01','yyyy/mm/dd')),
partition rg_002 values less than (to_date('2013/01/01','yyyy/mm/dd'))
);
ORA-14037: partition bound of partition "RG_001" is too high
http://blog.csdn.net/pengje/article/details/1551216
创建本地索引
create index idx_rg_yzy on rg_yzy(created) local
(partition rg_001 tablespace users,
partition rg_002 tablespace users);
插入数据
insert into rg_yzy select OBJECT_NAME,object_id,created from dba_objects where created < to_date('2013/01/01','yyyy/mm/dd') and object_id is not null;
ORA-14400: inserted partition key does not map to any partition
http://stackoverflow.com/questions/24454591/oracle-partition-error-ora14400-inserted-partition-key-does-not-map-to-any-p
插入失败,调整后插入0行!
增加一个分区
alter table rg_yzy add partition rg_003 values less than (to_date('2015/01/01','yyyy/mm/dd'));
SQL> select segment_name,partition_name,tablespace_name from dba_segments where segment_name='IDX_RG_YZY';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------------------------------------------------------------------- ------------------------------ ---------------------
IDX_RG_YZY RG_003 USERS
IDX_RG_YZY RG_002 USERS
IDX_RG_YZY RG_001 USERS
SQL> select segment_name,partition_name,tablespace_name from dba_segments where segment_name='RG_YZY';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------------------------------------------------------------------- ------------------------------ ----------------------
RG_YZY RG_003 USERS
RG_YZY RG_002 USERS
RG_YZY RG_001 USERS
可见分区索引是自动维护的
再次插入数据:
insert into rg_yzy select OBJECT_NAME,object_id,created from dba_objects where created < to_date('2015/01/01','yyyy/mm/dd') and object_id is not null;
87752 rows inserted
SQL> commit;
Commit complete
SQL> select count(*) from rg_yzy partition(rg_001);
COUNT(*)
----------
0
SQL> select count(*) from rg_yzy partition(rg_002);
COUNT(*)
----------
0
SQL> select count(*) from rg_yzy partition(rg_003);
COUNT(*)
----------
87752
发现不符合对测试环境的要求
修改分区,数据不合适,直接update
SQL> alter table lcl.rg_yzy enable row movement;
Table altered
SQL> update rg_yzy set created = to_date('2012/08/24','yyyy/mm/dd') where rownum<40000;
39999 rows updated
SQL> commit;
Commit complete
SQL> alter table lcl.rg_yzy disable row movement;
Table altered
SQL> select count(*) from rg_yzy partition(rg_003);
COUNT(*)
----------
47753
SQL> select count(*) from rg_yzy partition(rg_002);
COUNT(*)
----------
39999
SQL> select count(*) from rg_yzy partition(rg_001);
COUNT(*)
----------
0
SQL> alter table lcl.rg_yzy enable row movement;
Table altered
SQL> update rg_yzy set created = to_date('2011/08/24','yyyy/mm/dd') where rownum<1000;
999 rows updated
SQL> alter table lcl.rg_yzy disable row movement;
Table altered
SQL> commit;
Commit complete
SQL> select count(*) from rg_yzy partition(rg_003);
COUNT(*)
----------
47753
SQL> select count(*) from rg_yzy partition(rg_002);
COUNT(*)
----------
39000
SQL> select count(*) from rg_yzy partition(rg_001);
COUNT(*)
----------
999
现在可以了,实验开始
创建数据量一样的普通表
SQL> create table rg_yzy_cm as select OBJECT_NAME,OBJECT_ID,CREATED from dba_objects;
Table created
update数据
SQL> update rg_yzy_cm set created = to_date('2012/08/24','yyyy/mm/dd') where rownum<40000;
39999 rows updated
SQL> commit;
Commit complete
SQL> update rg_yzy_cm set created = to_date('2011/08/24','yyyy/mm/dd') where rownum<1000;
999 rows updated
SQL> commit;
Commit complete;
查询速度对比:
select count(*) from rg_yzy where created<to_date('2012/08/20','yyyy/mm/dd');
select count(*) from rg_yzy_cm where created<to_date('2012/08/20','yyyy/mm/dd');
分区表:
SQL> select count(*) from rg_yzy where created<to_date('2012/08/20','yyyy/mm/dd');
999
Execution Plan
----------------------------------------------------------
Plan hash value: 504157362
--------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 11 (0)| 00:00:01 | | |
| 1 | SORT AGGREGATE | | 1 | 9 | | | | |
| 2 | PARTITION RANGE ITERATOR| | 999 | 8991 | 11 (0)| 00:00:01 | 1 | 2 |
|* 3 | INDEX RANGE SCAN | IDX_RG_YZY | 999 | 8991 | 11 (0)| 00:00:01 | 1 | 2 |
--------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("CREATED"<TO_DATE(' 2012-08-20 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
7 recursive calls
0 db block gets
76 consistent gets
0 physical reads
0 redo size
527 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
数据量不太行啊。。。。
0 0
- 实验:分区别对比普通表
- 普通表索引,分区表局部索引和分区表的全局索引分区的效率对比测试
- mysql分区分表对比测试过程
- 【mysql】表分区(partition)功能实验1
- 【mysql】表分区(partition)功能实验2
- 分区分表实验用的语句
- Oracle普通表基于Rowid在线重定义表分区
- 分区表的分区与普通表交换的一些问题
- 分区表的分区与普通表交换的一些问题
- 普通表转分区表和交换分区(oracle)
- 普通表转分区表和交换分区(oracle)
- 普通表转分区表(交换分区、在线重定义)
- 临时表和普通表日志量产生的对比
- Oracle 分区表和普通表查询效率分析对比
- 将普通表转变为分区表、索引分区,及与无分区前的查询效率比较
- Mysql分区实验
- mysql分区技术实验
- 硬盘分区别忽视 七大分区原则(转载)
- Set Matrix Zeroes (Java)
- 解决主机是win8/8.1 ,安装VMware虚拟机,使用校园出校器,连接宽带,里面的系统连不上网 问题
- Device Tree
- java测试方法运行时间 System.currentTimeMillis();
- html nobr 标签
- 实验:分区别对比普通表
- CHROME审查元素如何查看hover伪类的CSS?
- 小波变换及其相关知识
- RSA私钥和公钥文件格式 (pkcs#7, pkcs#8, pkcs#12, pem)
- 杂文 - 论神州电动车之出路
- UIPageControl的简单使用
- Configuring and Managing Cluster Resources
- /usr/local /user/lib等常见问题
- 重复字符串出现的次数以及第一次数显的位置