Oracle11g温习-第十三章:索引
2013年4月27日 星期六
10:46
|
1、索引(Index)的功能:对记录进行排序,加快表的查询速度 |
||
|
2、索引的分类 |
||
|
1)B-tree 索引(默认) a、在一个大表上 b、建立在重复值比较少的列上 ,在做select查询时,返回记录的行数小于全部记录的4% c、如果这一列经常用来做where子句和排序,也可以用来建立索引 d、一般用于OLTP 2) bitmap index a、建立在重复值非常高的列上 b、 在做DML 操作时,代价值比较高 c、一般用于OLAP 或DSS —— B-tree 索引不能使用or连接的语句,bitmap index可以使用 |
||
|
3、建立索引:默认建立 B-tree index |
||
|
4、建立索引表空间 |
||
|
SYS @ prod >create tablespace indexes datafile '/u01/app/oracle/oradata/prod/index01.dbf' size 50m autoextend on next 10m maxsize 50m extent management local uniform size 128k; Tablespace created. SQL> select file_id,file_name,tablespace_name from dba_data_files; FILE_ID FILE_NAME TABLESPACE_NAME ---------- -------------------------------------------------- ------------------------------ 1 /u01/app/oracle/oradata/prod/system01.dbf SYSTEM 2 /u01/app/oracle/oradata/prod/lx01.dbf LX01 3 /u01/app/oracle/oradata/prod/sysaux01.dbf SYSAUX 4 /u01/app/oracle/oradata/prod/users01.dbf USERS 7 /u01/app/oracle/oradata/prod/undotbs02.dbf UNDOTBS2 12 /u01/app/oracle/oradata/prod/index01.dbf INDEXES SQL> create table test (id int,name varchar2(10),sex varchar2(4)); Table created. SQL> begin for i in 1..10000 loop insert into test values(i,'user’||i,'M'); end loop; end; / SQL> begin for i in 10001..20000 loop insert into test values(i,'user’||i,'F'); end loop; end; SQL> select count(*) from test; COUNT(*) ---------- 20000
|
||
|
5、基于函数的索引 |
||
|
SQL> conn scott/tiger Connected. SQL> set autotrace on; SQL> create index emp_ename_ind on emp(ename) tablespace indexes; Index created. SQL> select * from emp where ename='SCOTT'; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ------------------------------ --------------------------- ---------- ------------------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20 Execution Plan ---------------------------------------------------------- Plan hash value: 3220259315 --------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 87 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 87 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | EMP_ENAME_IND | 1 | | 1 (0)| 00:00:01 | --------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("ENAME"='SCOTT') Note ----- - dynamic sampling used for this statement Statistics ---------------------------------------------------------- 0 recursive calls 0 db block gets 0 consistent gets 0 physical reads 0 redo size 0 bytes sent via SQL*Net to client 0 bytes received via SQL*Net from client 0 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed ——通过函数访问,索引无效 SQL> select * from emp where lower(ename)='scott'; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ------------------------------ --------------------------- ---------- ------------------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20 Execution Plan ---------------------------------------------------------- Plan hash value: 3956160932 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 87 | 15 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| EMP | 1 | 87 | 15 (0)| 00:00:01 | ——索引无效 -------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter(LOWER("ENAME")='scott') Note ----- - dynamic sampling used for this statement Statistics ---------------------------------------------------------- 0 recursive calls 0 db block gets 0 consistent gets 0 physical reads 0 redo size 0 bytes sent via SQL*Net to client 0 bytes received via SQL*Net from client 0 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed ——建立函数索引 SQL> create index emp_ename_funind on emp(lower(ename)) tablespace indexes; Index created. SQL> select * from emp where lower(ename)='scott'; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ------------------------------ --------------------------- ---------- ------------------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20 Execution Plan ---------------------------------------------------------- Plan hash value: 519807088 ------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 87 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 87 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | EMP_ENAME_FUNIND | 1 | | 1 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - access(LOWER("ENAME")='scott') Note ----- - dynamic sampling used for this statement Statistics ---------------------------------------------------------- 0 recursive calls 0 db block gets 0 consistent gets 0 physical reads 0 redo size 0 bytes sent via SQL*Net to client 0 bytes received via SQL*Net from client 0 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed |
||
|
6、索引监控 |
||
|
SQL> conn scott/tiger Connected. SQL> alter index emp_ename_funind monitoring usage; Index altered. SQL> select index_name,table_name,monitoring,used from v$object_usage; INDEX_NAME TABLE_NAME MONITORIN USED ------------------------------ --------------- --------- --------- EMP_ENAME_FUNIND EMP YES NO SQL> select * from emp where LOWER(ename)='scott'; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 SQL> select * from emp where lower(ename)='scott'; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- --------------- --------------- ---------- ------------------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20 SQL> select index_name,table_name,monitoring,used from v$object_usage; INDEX_NAME TABLE_NAME MONITORIN USED ------------------------------ --------------- --------- --------- EMP_ENAME_FUNIND EMP YES YES |
||
|
7、【反向索引----------用于建立索引的列值是连续的或通过序列生成时,避免索引存放到集中的leaf block上,避免生成热块】。 |
||
|
1)建立反向索引 SQL> create index r_empno_ind on test(empno) reverse; Index created. ——【对于emp表里empno列来说,因为客户ID号顺序递增,所以为了均衡索引数据分布,应在该列上建立反向索引。】 2)重建索引 SQL> alter index r_empno_ind rebuild reverse; Index altered. |
||
|
8、与索引有关的视图 |
||
|
DBA_INDEXES: DBA_IND_COLUMNS: V$OBJECT_USAGE: |
Oracle11g温习-第十三章:索引的更多相关文章
- Oracle11g温习-第十七章:权限管理
2013年4月27日 星期六 10:50 1.权限(privilege): [system privilege(系统权限):针对于database 的相关权限 object p ...
- Oracle11g温习-第十一章:管理undo
2013年4月27日 星期六 10:40 1.undo tablespace 功能 undo tablespace 功能:用来存放从datafiles 读出的数据块旧的镜像 [ ...
- Oracle11g温习-第七章:redo日志
2013年4月27日 星期六 10:33 1.redo (重做) log 的功能: 用于数据恢复 2.redo log 特征: [特征]: 1) 记录数据块的变化(DML.D ...
- Oracle11g温习-第六章:控制文件
2013年4月27日 星期六 10:33 .控制文件的功能和特点 1) [定义数据库当前物理状态] 2) [维护数据的一致性] 如果控制文件中的检查点与数据文件中的一致,则说明数据一致,可以启动到 ...
- Oracle11g温习-第五章:数据字典
1.数据字典(Data dictionary)的功能 1) central of oracle database 每个oracle数据库的核心 2) descr ...
- Oracle11g温习-第四章:手工建库
1.create database plan 1.库类型: OLTP : 在线事务处理系统 OLAP : 在线应用处理系统 DSS : 数据决策系统 2.数据库名字及字符集 3. ...
- Oracle11g温习-第三章:instance实例管理
2013年4月27日 星期六 10:30 1.instance 功能: 用于管理和访问database. 2.init parameter files :管理实例相关启动参数.位置:$ORACLE ...
- 第十三章——表和索引分区(1)——使用Range Left进行表分区
原文:第十三章--表和索引分区(1)--使用Range Left进行表分区 前言: 如果数据表的数据持续增长,并且表中的数据量已经达到数十亿甚至更多,数据的查询和操作将非常困难,面对非常庞大的表,几时 ...
- perl5 第十三章 Perl的面向对象编程
第十三章 Perl的面向对象编程 by flamephoenix 一.模块简介二.Perl中的类三.创建类四.构造函数 实例变量 五.方法六.方法的输出七.方法的调用八.重载九.析构函数十.继承十一. ...
随机推荐
- (转载)C# winform 在一个窗体中如何设置另一个窗体的TextBox的值
方法1:修改控件的访问修饰符.(不建议使用此法) public System.Windows.Forms.TextBox textBox1; 在调用时就能直接访问 Form1 frm = new Fo ...
- 【C#】扩展方法浅谈
C#3 引入的扩展方法这一个理念. 扩展方法最明显的特征是在方法参数中第一个参数有this声明. 其实C#库中有很多已经是扩展方法了.比如linq中对序列使用的查询语句, where, select等 ...
- ZooKeeper分布式过程协同技术详解1——ZooKeeper的概念和基础
简介 分布式系统和应用,不仅能提供更强的计算能力,还能为我们提供更好的容灾性和扩展性. ZooKeeper是Google的Chubby项目的开源实现,它曾经作为Hadoop的子项目,在大数据领域得到广 ...
- win10 右键菜单很慢的解决方式
本来想用 win7 的,不想花很多时间折腾了.现在新电脑主板硬盘CPU都在排挤 win7 ,真是可怜呀.正题: 新电脑的性能应该还算不错的, 18 年跑分 29w 以上,但在图标上面右键却都要转圈几秒 ...
- 【BZOJ】3142: [Hnoi2013]数列
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3142 12年也有一个组合数学...(这几年的画风啊.... 考虑直接去做:DP? DP+容 ...
- Jtest的简单使用
Jtest主要用于快速测试自己的代码是否正确 条件,导入相应的Jtest包 @Test public void test() { System.out.println(" ...
- Android Studio NDK开发-JNI调用Java方法
相对于NDK来说SDK里面有更多API可以调用,有时候我们在做NDK开发的时候,需要在JNI直接Java中的方法和变量,比如callback,系统信息等.... 如何在JNI中调用Java方法呢?就需 ...
- css垂直居中方法
CSS垂直居中的简便方法:{position:absolute;left:0;bottom:0;top:0;right:0;margin:auto;}.
- vux的x-input的源码分析
<template> <div class="vux-x-input weui-cell" :class="{'weui-cell_warn': sho ...
- Unity---关于游戏小包的记录
最近因为需求,出了一个pc版的游戏小包,遇到一些坑,在此做一下记录. 首先需要明白的是出小包的意义所在,其实就是为了压缩包体,游戏需要的大部分资源,在第一次运行游戏的时候通过热更新去FTP资源服务器上 ...