文档详情

Orcl5(索引、序列、同义词、簇)研讨.pptx

发布:2017-04-03约7.26千字共39页下载文档
文本预览下载声明
Oracle 11g R2 数据库基础教程 模式对象 Oracle数据库索引、序列、同义词、簇。 Index 22 22 索引 表 关键字 行指针 … WHERE key = 22 Index 有多种类型的索引结构,可以根据需要使用。最常用的两种类型是: B 树索引 默认的索引类型;采用平衡树的形式 位图索引: 每个不同的索引值都有一个位图 每一位代表一行,该行可能包含,也可能不包含索引值。 最适合于低基数列 B 树索引 B 树索引的结构 :索引的顶层为根,它包含指向索引中下一层次的条目。下一层次为分支块,它又指向位于索引中下一层次的块。最底层是叶节点,它包含指向表行的索引条目。叶块是双向关联的,这便于按键值升序或降序扫描索引。 B 树索引 Example of B+-Tree B 树索引 CREATE [ UNIQUE ] INDEX index ON table(column [ ASC | DESC ] [ , column [ ASC | DESC ] ] ...); 单列索引: CREATE INDEX idx1 ON emp(empno); 组合索引: CREATE INDEX idx2 ON emp(empno,deptno); 唯一索引: CREATE UNIQUE INDEX idx3 ON emp(ename,deptno); 为表指定了主键约束或者唯一性约束,系统将自动在这些列上建立唯一性索引,且索引名与约束名相同。 B 树索引 SQL create table emp1 as select * from emp; SQL set autotrace traceonly explain; SQL select empno from emp1; SQL create unique index emp1_idx on emp1(empno); SQL select empno from emp1 where empno=7788; SQL drop index emp1_idx; SQL create index emp1_idx on emp1(empno); SQL select empno from emp1 where empno=7788; B 树索引 SQL insert into emp1 select * from emp1; SQL … … (创建14336行) SQL select count(empno) from emp1; 位图索引 Comparing B-Tree and Bitmap Indexes B-tree Suitable for high-cardinality columns Updates on keys relatively inexpensive Inefficient for queries using OR predicates Useful for OLTP Bitmap Suitable for low-cardinality columns Updates to key columns very expensive Efficient for queries using OR predicates Useful for data warehousing 位图索引 CREATE BITMAP INDEX index ON table(column [ ASC | DESC ] [ , column [ASC | DESC ] ] ...); CREATE BITMAP INDEX idx4 ON emp(job); 位图索引 值/行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ---------------------------------------------------------- ANALYST 0 0 0 0 0 0 0 1 0 0 0 0 1 0 CLERK 1 0 0 0 0 0 0 0 0 0 1 1 0 1 MANAGER 0 0 0 1 0 1 1 0 0 0 0 0 0 0 PRESIDENT 0 0 0 0 0 0 0 0 1 0 0 0 0 0 SALESMAN 0 1 1 0 1 0 0 0 0 0 0 0 0 0 值/行 1 2 3 4 5 6
显示全部
相似文档