表主键排序和离散数据查询的速度测试
2008-08-20 21:59
465 查看
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)
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)
相关文章推荐
- 表主键排序和离散数据查询的速度测试
- 常用查询(二):查询库中所有表的数据(根据主键排序)
- mongdb性能压力测试,随机查询,数据量1亿条记录 操作系统centos6.4x64位 从测试结果看,当mongodb将数据全部载入到内存后,查询速度根据文档的大小,性能瓶颈通常会是在网络流
- 在大量数据中进行查询,有无索引查询的速度效果测试
- T-SQL查询笔记2:生成一个100万测试数据的表
- android中Sqlite查询的数据返回排序问题
- 处理千万级以上的数据提高查询速度的方法
- 处理百万级以上的数据提高查询速度的方法
- 关于mysql处理百万级以上的数据时如何提高其查询速度的方法
- asp.net网站轻量级数据查询-单条数据查询方式耗时测试
- Sql语句与存储过程查询数据的性能测试实现代码
- Mongodb百亿级数据添加,修改,删除,查询等性能测试【四】
- Linq to XML 排序,分页,多节点查询数据
- 处理百万级以上的数据提高查询速度的方法
- Oracle笔记简单查询、限定查询、数据的排序
- sql指定排序规则、筛选id最大或最小记录、查询插入数据
- Aliyun上Linux服务器挂载数据盘及速度测试
- SQL Server 百万级数据提高查询速度的方法
- c++ 连接MySql数据库并执行插入,查询数据测试代码
- 用户名查询、手机号查询、选择城市、选择状态、选择月份、ID排序、添加数据、批量发货、批量删除、敏感字、修改数据)