表主键排序和离散数据查询的速度测试
2010-08-09 18:01
459 查看
表主键排序和离散数据查询的速度测试 收藏
SQL> create table clustered (x int,data char(255));
Table created.
SQL> insert /*+append+*/ into clustered (x,data) select rownum,dbms_random.random from all_objects;
40960 rows created.
Elapsed: 00:00:06.68
insert /*+ append */ into clustered (x,data) select rownum,dbms_random.random from all_objects;
一个创建主关键字
alter table clustered add constraint clustered_pk primary key(x);
analyze table clustered compute statistics;
create table non_clustered(x int,data char(255));
insert /*+ appedn */ into non_clustered select x,data from clustered order by data;
alter table non_clustered add constraint non_clustered_pk primary key (x);
analyze table non_clustered compute statistics;
select index_name,clustering_factor from user_indexes where index_name like '%CLUSTERED_PK%';
INDEX_NAME CLUSTERING_FACTOR
------------------------------ -----------------
NON_CLUSTERED_PK 40935
CLUSTERED_PK 1518
看看结果没有排序的比较快 CPU使用比较少
set autotrace traceonly explain
set timing on
SQL> select * from clustered where x between 50 and 2750;
Elapsed: 00:00:00.00
Execution Plan
----------------------------------------------------------
Plan hash value: 1763666373
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2702 | 683K| 108 (0)| 00:00:02 |
| 1 | TABLE ACCESS BY INDEX ROWID| CLUSTERED | 2702 | 683K| 108 (0)| 00:00:02 |
|* 2 | INDEX RANGE SCAN | CLUSTERED_PK | 2702 | | 7 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("X">=50 AND "X"<=2750)
select * from non_clustered where x between 50 and 2750;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 681052411
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2702 | 683K| 347 (1)| 00:00:05 |
|* 1 | TABLE ACCESS FULL| NON_CLUSTERED | 2702 | 683K| 347 (1)| 00:00:05 |
-----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("X"<=2750 AND "X">=50)
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xuejiayue1105/archive/2008/08/20/2803864.aspx
SQL> create table clustered (x int,data char(255));
Table created.
SQL> insert /*+append+*/ into clustered (x,data) select rownum,dbms_random.random from all_objects;
40960 rows created.
Elapsed: 00:00:06.68
insert /*+ append */ into clustered (x,data) select rownum,dbms_random.random from all_objects;
一个创建主关键字
alter table clustered add constraint clustered_pk primary key(x);
analyze table clustered compute statistics;
create table non_clustered(x int,data char(255));
insert /*+ appedn */ into non_clustered select x,data from clustered order by data;
alter table non_clustered add constraint non_clustered_pk primary key (x);
analyze table non_clustered compute statistics;
select index_name,clustering_factor from user_indexes where index_name like '%CLUSTERED_PK%';
INDEX_NAME CLUSTERING_FACTOR
------------------------------ -----------------
NON_CLUSTERED_PK 40935
CLUSTERED_PK 1518
看看结果没有排序的比较快 CPU使用比较少
set autotrace traceonly explain
set timing on
SQL> select * from clustered where x between 50 and 2750;
Elapsed: 00:00:00.00
Execution Plan
----------------------------------------------------------
Plan hash value: 1763666373
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2702 | 683K| 108 (0)| 00:00:02 |
| 1 | TABLE ACCESS BY INDEX ROWID| CLUSTERED | 2702 | 683K| 108 (0)| 00:00:02 |
|* 2 | INDEX RANGE SCAN | CLUSTERED_PK | 2702 | | 7 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("X">=50 AND "X"<=2750)
select * from non_clustered where x between 50 and 2750;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 681052411
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2702 | 683K| 347 (1)| 00:00:05 |
|* 1 | TABLE ACCESS FULL| NON_CLUSTERED | 2702 | 683K| 347 (1)| 00:00:05 |
-----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("X"<=2750 AND "X">=50)
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xuejiayue1105/archive/2008/08/20/2803864.aspx
相关文章推荐
- 表主键排序和离散数据查询的速度测试
- 在大量数据中进行查询,有无索引查询的速度效果测试
- mongdb性能压力测试,随机查询,数据量1亿条记录 操作系统centos6.4x64位 从测试结果看,当mongodb将数据全部载入到内存后,查询速度根据文档的大小,性能瓶颈通常会是在网络流
- 常用查询(二):查询库中所有表的数据(根据主键排序)
- Oracle笔记(四) 简单查询、限定查询、数据的排序
- Aliyun上Linux服务器挂载数据盘及速度测试
- 处理千万级以上的数据提高查询速度的方法(转)
- ORACLE数据库测试数据插入速度
- [js].net中表格数据的排序的js应用,非常简单(中国铁路查询)
- 对mysql数据库批量插入数据的速度测试
- 用php处理百万级以上的数据提高查询速度的方法
- 简单查询、限定查询、数据的排序
- solr 亿万级数据查询性能测试
- MySQL 千万 级数据量根据(索引)优化 查询 速度
- Mysql学习笔记(五)数据查询之测试sql部分。
- mysql表MyIAS、InnoDB类型大数据速度测试
- sql查询按in顺序排序显示数据 oracle
- sqlite里执行查询提示未启用约束、主键冲突之——数据竟能超字段长度存储
- mysql百万级数据量根据索引优化查询速度
- [转载]处理百万级以上的数据提高查询速度的方法