- 浏览: 204753 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
zoutuo1986:
翻过的帖子,这篇讲配置最细
solr -
18612536750:
Struts2 标签,取得Map的某一个key对应value值 -
zhangzhihua5:
solr -
xiaguangme:
“capacity才是真正的Entry数组的大小,即真实的En ...
源码阅读之Map和Set -
qiyang199132:
我擦民工 都没人来。。 我来捧场了
JSP 防止重复提交 防止重复刷新 防止后退问题以及处理方式
Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用。
从产品上说,分区技术是Oracle企业版中独立收费的一个组件。
以下是对于分区及本地索引的一个示例。
首先根据字典表创建一个测试分区表:
SQL> connect eygle/eygle
Connected.
SQL> CREATE TABLE dbobjs
2 (OBJECT_ID NUMBER NOT NULL,
3 OBJECT_NAME varchar2(128),
4 CREATED DATE NOT NULL
5 )
6 PARTITION BY RANGE (CREATED)
7 (PARTITION dbobjs_06 VALUES LESS THAN (TO_DATE('01/01/2007', 'DD/MM/YYYY')),
8 PARTITION dbobjs_07 VALUES LESS THAN (TO_DATE('01/01/2008', 'DD/MM/YYYY')));
Table created.
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS DBOBJS_06 EYGLE
DBOBJS DBOBJS_07 EYGLE
创建一个Local索引,注意这里可以将不同分区的索引指定创建到不同的表空间:
SQL> CREATE INDEX dbobjs_idx ON dbobjs (created) LOCAL
2 (PARTITION dbobjs_06 TABLESPACE users,
3 PARTITION dbobjs_07 TABLESPACE users
4 );
Index created.
这个子句可以进一步调整为类似:
CREATE INDEX dbobjs_idx ON dbobjs (created) LOCAL
(PARTITION dbobjs_06 TABLESPACE users,
PARTITION dbobjs_07 TABLESPACE users
) TABLESPACE users;
通过统一的tablespace子句为索引指定表空间。
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS_IDX';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS_IDX DBOBJS_06 USERS
DBOBJS_IDX DBOBJS_07 USERS
SQL> insert into dbobjs
2 select object_id,object_name,created
3 from dba_objects where created <to_date('01/01/2008','dd/mm/yyyy') and object_id is not null;
6227 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from dbobjs partition (DBOBJS_06);
COUNT(*)
----------
6154
SQL> select count(*) from dbobjs partition (dbobjs_07);
COUNT(*)
----------
73
我们可以通过查询来对比一下分区表和非分区表的查询性能差异:
SQL> set autotrace on
SQL> select count(*) from dbobjs where created < to_date('01/01/2008','dd/mm/yyyy');
COUNT(*)
----------
6227
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=9)
1 0 SORT (AGGREGATE)
2 1 PARTITION RANGE (ALL)
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=8 Bytes=72)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
25 consistent gets
0 physical reads
0 redo size
380 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select count(*) from dbobjs where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(*)
----------
6154
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=9)
1 0 SORT (AGGREGATE)
2 1 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=4 Bytes=36)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
24 consistent gets
0 physical reads
0 redo size
380 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select count(distinct(object_name)) from dbobjs where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(DISTINCT(OBJECT_NAME))
----------------------------
4753
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=75)
1 0 SORT (GROUP BY)
2 1 TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'DBOBJS' (Cost=1 Card=4 Bytes=300)
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
101 consistent gets
0 physical reads
0 redo size
400 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
对于非分区表的测试:
SQL> CREATE TABLE dbobjs2
2 (object_id NUMBER NOT NULL,
3 object_name VARCHAR2(128),
4 created DATE NOT NULL
5 );
Table created.
SQL> CREATE INDEX dbobjs_idx2 ON dbobjs2 (created);
Index created.
SQL> insert into dbobjs2
2 select object_id,object_name,created
3 from dba_objects where created <to_date('01/01/2008','dd/mm/yyyy') and object_id is not null;
6227 rows created.
SQL> commit;
Commit complete.
SQL> select count(distinct(object_name)) from dbobjs2 where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(DISTINCT(OBJECT_NAME))
----------------------------
4753
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (GROUP BY)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'DBOBJS2'
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX2' (NON-UNIQUE)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2670 consistent gets
0 physical reads
1332 redo size
400 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
当增加表分区时,LOCAL索引被自动维护:
SQL> ALTER TABLE dbobjs
2 ADD PARTITION dbobjs_08 VALUES LESS THAN (TO_DATE('01/01/2009', 'DD/MM/YYYY'));
Table altered.
SQL> set autotrace off
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS_IDX';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS_IDX DBOBJS_06 USERS
DBOBJS_IDX DBOBJS_07 USERS
DBOBJS_IDX DBOBJS_08 EYGLE
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS DBOBJS_06 EYGLE
DBOBJS DBOBJS_07 EYGLE
DBOBJS DBOBJS_08 EYGLE
-The End-
从产品上说,分区技术是Oracle企业版中独立收费的一个组件。
以下是对于分区及本地索引的一个示例。
首先根据字典表创建一个测试分区表:
SQL> connect eygle/eygle
Connected.
SQL> CREATE TABLE dbobjs
2 (OBJECT_ID NUMBER NOT NULL,
3 OBJECT_NAME varchar2(128),
4 CREATED DATE NOT NULL
5 )
6 PARTITION BY RANGE (CREATED)
7 (PARTITION dbobjs_06 VALUES LESS THAN (TO_DATE('01/01/2007', 'DD/MM/YYYY')),
8 PARTITION dbobjs_07 VALUES LESS THAN (TO_DATE('01/01/2008', 'DD/MM/YYYY')));
Table created.
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS DBOBJS_06 EYGLE
DBOBJS DBOBJS_07 EYGLE
创建一个Local索引,注意这里可以将不同分区的索引指定创建到不同的表空间:
SQL> CREATE INDEX dbobjs_idx ON dbobjs (created) LOCAL
2 (PARTITION dbobjs_06 TABLESPACE users,
3 PARTITION dbobjs_07 TABLESPACE users
4 );
Index created.
这个子句可以进一步调整为类似:
CREATE INDEX dbobjs_idx ON dbobjs (created) LOCAL
(PARTITION dbobjs_06 TABLESPACE users,
PARTITION dbobjs_07 TABLESPACE users
) TABLESPACE users;
通过统一的tablespace子句为索引指定表空间。
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS_IDX';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS_IDX DBOBJS_06 USERS
DBOBJS_IDX DBOBJS_07 USERS
SQL> insert into dbobjs
2 select object_id,object_name,created
3 from dba_objects where created <to_date('01/01/2008','dd/mm/yyyy') and object_id is not null;
6227 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from dbobjs partition (DBOBJS_06);
COUNT(*)
----------
6154
SQL> select count(*) from dbobjs partition (dbobjs_07);
COUNT(*)
----------
73
我们可以通过查询来对比一下分区表和非分区表的查询性能差异:
SQL> set autotrace on
SQL> select count(*) from dbobjs where created < to_date('01/01/2008','dd/mm/yyyy');
COUNT(*)
----------
6227
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=9)
1 0 SORT (AGGREGATE)
2 1 PARTITION RANGE (ALL)
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=8 Bytes=72)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
25 consistent gets
0 physical reads
0 redo size
380 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select count(*) from dbobjs where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(*)
----------
6154
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=9)
1 0 SORT (AGGREGATE)
2 1 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=4 Bytes=36)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
24 consistent gets
0 physical reads
0 redo size
380 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select count(distinct(object_name)) from dbobjs where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(DISTINCT(OBJECT_NAME))
----------------------------
4753
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=75)
1 0 SORT (GROUP BY)
2 1 TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'DBOBJS' (Cost=1 Card=4 Bytes=300)
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
101 consistent gets
0 physical reads
0 redo size
400 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
对于非分区表的测试:
SQL> CREATE TABLE dbobjs2
2 (object_id NUMBER NOT NULL,
3 object_name VARCHAR2(128),
4 created DATE NOT NULL
5 );
Table created.
SQL> CREATE INDEX dbobjs_idx2 ON dbobjs2 (created);
Index created.
SQL> insert into dbobjs2
2 select object_id,object_name,created
3 from dba_objects where created <to_date('01/01/2008','dd/mm/yyyy') and object_id is not null;
6227 rows created.
SQL> commit;
Commit complete.
SQL> select count(distinct(object_name)) from dbobjs2 where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(DISTINCT(OBJECT_NAME))
----------------------------
4753
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (GROUP BY)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'DBOBJS2'
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX2' (NON-UNIQUE)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2670 consistent gets
0 physical reads
1332 redo size
400 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
当增加表分区时,LOCAL索引被自动维护:
SQL> ALTER TABLE dbobjs
2 ADD PARTITION dbobjs_08 VALUES LESS THAN (TO_DATE('01/01/2009', 'DD/MM/YYYY'));
Table altered.
SQL> set autotrace off
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS_IDX';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS_IDX DBOBJS_06 USERS
DBOBJS_IDX DBOBJS_07 USERS
DBOBJS_IDX DBOBJS_08 EYGLE
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS DBOBJS_06 EYGLE
DBOBJS DBOBJS_07 EYGLE
DBOBJS DBOBJS_08 EYGLE
-The End-
发表评论
-
oracle基础学习
2012-11-07 15:13 1599转自(http://www.cnblogs.com ... -
oracle start with connect by 用法
2011-09-30 09:49 1426oracle 提供了start with connect by ... -
Hibernate操作Oarcle中Clob、Blob字段小结
2011-08-24 11:19 1213最近常碰到有人问如何运用Hibernate操作Oracle中的 ... -
数据库优化基本策略(转载)
2011-07-15 08:58 9081.选择正确类型的sql。 有时候你想要动态生成sql,却发现 ... -
oracle 查询数据null值排序
2011-07-11 18:16 1268sqlserver 认为 null 最小。 升序排列:nul ... -
不错的sql
2011-07-04 09:05 10231,说明:复制表(源表名a,新表名b) 法一:select ... -
oracle CLOB和BLOB
2011-06-25 21:18 1437一、区别和定义 LONG: 可变长的字符串数据, ... -
Oracle中TO_DATE格式
2011-05-19 17:34 889TO_DATE格式(以时间:2007-11-02 13:4 ... -
ORACLE错误一览表,方便大家查询!
2011-05-03 17:50 1567ORACLE错误一览表,方便 ... -
oracle 锁表
2011-04-26 16:37 1181查看锁表进程SQL语句1: select sess.sid, ... -
PL/SQL Developer 常用技巧
2011-03-18 14:10 8881、PL/SQL Developer记住登 ... -
java调用oracle存储过程
2010-12-17 11:14 1207在大型数据库系统中,有两个很重要作用的功能,那就是存储过程和触 ...
相关推荐
本文将围绕Oracle创建索引的基本规则进行深入探讨,旨在帮助读者更好地理解如何根据不同的场景选择合适的索引类型,并掌握创建索引时的一些关键考虑因素。 #### 一、B-Tree索引 B-Tree(平衡树)索引是Oracle中最...
"数据库创建索引SQL Oracle" 数据库索引是数据库性能优化的重要手段之一。创建索引可以提高查询速度,降低数据库的负载,提高数据的安全性。本文将详细介绍数据库创建索引的原则、分类、创建方法、管理和优化等方面...
正如文档标题“Oracle创建索引要做到三个适当”所强调的,创建索引需要遵循“适当”的原则,具体包括在适当的表上、适当的列上创建适当数量的索引。以下将对这三个方面进行详细阐述,以帮助数据库管理员更好地理解...
oracle创建索引很好的参考资料,好的索引能够非常大的提高数据库的查询速度
2. **创建索引**:索引用于提高数据查询的效率。Oracle支持B树索引、位图索引等多种类型。例如,为EmployeeID创建索引: ```sql CREATE INDEX idx_employee_id ON Employees(EmployeeID); ``` 这条语句创建了一...
Oracle索引的创建、简介、技巧,希望可以给学习Oracle的人带来帮助!
Oracle 在线创建索引和重组索引 Oracle 在线创建索引和重组索引是数据库管理员经常需要处理的问题。在线创建索引可以提高查询性能,而重组索引可以减少索引的碎片化和空间浪费。下面我们将详细介绍在线创建索引和...
为了理解如何优化创建索引的过程,首先需要了解Oracle创建索引时涉及的主要I/O操作: 1. **RA**:对源表加X类型的表级DDL锁。 2. **RB**:读取源表数据块的I/O。 3. **RC**:索引键排序,如果内存中无法容纳所有的...
在Oracle数据库管理系统中,创建表和唯一索引是数据库设计中的关键步骤,它们对于数据的组织、查询效率和数据完整性至关重要。以下将详细介绍如何创建学员信息表,创建唯一索引,以及如何修改表来添加主键和检查约束...
创建索引有多种方式,如使用`CREATE INDEX`语句,例如: ```sql CREATE INDEX idx_employee_name ON employees(last_name); ``` 这将在`employees`表的`last_name`列上创建一个索引,使得按照员工姓氏查找变得高效。...
"Oracle 海量数据中提升创建索引的速度" Oracle 海量数据中提升创建索引的速度是指在 Oracle 数据库中,特别是在海量数据的情况下,如何提高创建索引的速度。创建索引是数据库优化中的重要步骤,但是在海量数据的...
对于Oracle数据库,批量创建索引可以通过SQL命令或者PL/SQL脚本来实现。例如,你可以使用`CREATE INDEX`语句来创建单个索引,然后通过循环结构批量处理多个索引。如果需要删除索引,可以使用`DROP INDEX`语句。为了...
通过创建索引,可以显著提升查询性能,尤其是在处理大型数据表时更为明显。索引类似于书籍中的目录,能够帮助数据库快速定位到所需的数据行。 #### 二、创建索引 根据提供的描述,创建索引的具体命令为: ```sql ...
### Oracle中亿级记录表创建索引的知识点详解 #### 一、背景介绍 在Oracle数据库中处理亿级数据量的表时,合理的索引设计是优化查询性能的关键因素之一。索引能够加快数据检索的速度,减少I/O操作次数,但同时也...
标题中的“postgresql和oracle创建空间索引”涉及的是在两种主流的关系型数据库管理系统(RDBMS)中,如何为地理空间数据创建索引的技术。在处理包含地理信息的数据时,如地图坐标、地理位置等,空间索引能显著提高...
在数据库中,索引可以加速对表中数据的访问,特别是对于那些频繁进行查询操作的列,创建索引能够显著提高查询速度。 Oracle支持多种类型的索引,包括B树索引、位图索引、函数索引和唯一索引等。B树索引是最常见的...
1. 创建索引:使用CREATE INDEX语句创建全文索引,指定索引类型(如CTX),并提供包含文本数据的列名。 2. 分析索引:创建索引后,使用DBMS_INDEXAnalyzer进行分析,以优化索引性能。 三、全文检索语法 1. 使用...
对于经常出现在WHERE子句中的列,创建索引会提高查询效率。 - **索引类型**:根据数据类型和查询需求选择合适的索引类型。例如,对于低基数(非唯一或重复值多)的列,位图索引可能更有效;对于需要执行范围查询的...
Oracle 中创建空间索引的实现步骤和注意事项 空间索引是 Oracle 中的一种特殊索引类型,用于加速空间数据的查询和检索。空间索引可以大大提高空间数据的查询效率,特别是在处理大量空间数据时。本文将详细介绍如何...
- **函数索引(Function-Based Index)**: 允许基于函数的结果创建索引,使得对函数结果的查询能利用索引。 - **唯一索引(Unique Index)**: 确保索引键的唯一性,与唯一约束相似,但不强制非空。 - **分区索引...