oracle 如何预估将要创建的索引的大小
一.1 oracle 如何预估将要创建的索引的大小
oracle 提供了2种可以预估将要创建的索引大小的办法:
① 利用包 Dbms_space.create_index_cost 直接得到
② 利用11g新特性 Note raised when explain plan for create index
下边分别举例说明。
一.2 环境说明
[oracle@rhel6_lhr ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Dec 26 15:58:06 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> create table test_index_size as select * from dba_objects;
Table created.
SQL> EXEC DBMS_STATS.gather_table_stats(ownname => 'SYS',tabname => 'TEST_INDEX_SIZE');
PL/SQL procedure successfully completed.
一.3 第一种 Dbms_space.create_index_cost
脚本:
declare
l_index_ddl varchar2(1000);
l_used_bytes number;
l_allocated_bytes number;
begin
dbms_space.create_index_cost(ddl => 'create index idx_t on sys.test_index_size(object_id) ',
used_bytes => l_used_bytes,
alloc_bytes => l_allocated_bytes);
dbms_output.put_line('used= ' || l_used_bytes || 'bytes' ||
' allocated= ' || l_allocated_bytes || 'bytes');
end;
/
实验:
SQL> set serveroutput on
SQL> declare
2 l_index_ddl varchar2(1000);
3 l_used_bytes number;
4 l_allocated_bytes number;
5 begin
6 dbms_space.create_index_cost(ddl => 'create index idx_t on sys.test_index_size(object_id) ',
7 used_bytes => l_used_bytes,
8 alloc_bytes => l_allocated_bytes);
9 dbms_output.put_line('used= ' || l_used_bytes || 'bytes' ||
10 ' allocated= ' || l_allocated_bytes || 'bytes');
11 end;
12 /
used= 383105bytes allocated= 2097152bytes
PL/SQL procedure successfully completed.
SQL>
PL/SQL 过程已成功完成。
说明: used_bytes 给出索引数据实际表现的字节数。
allocated 是当实际创建索引时在表空间中实际占用的字节数。
一.4 第二种11g新特性:Note raised when explain plan for create index
这是一个挺实用的小特性,在11g r2中使用explain plan for create index时Oracle会提示评估的索引大小(estimated index size)了:
SQL> set linesize 200 pagesize 1400;
SQL> explain plan for create index idx_t on sys.test_index_size(object_id) ;
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------
Plan hash value: 32582980
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | CREATE INDEX STATEMENT | | 76621 | 374K| 350 (1)| 00:00:05 |
| 1 | INDEX BUILD NON UNIQUE| IDX_T | | | | |
| 2 | SORT CREATE INDEX | | 76621 | 374K| | |
| 3 | INDEX FAST FULL SCAN| IDX_T | | | | |
--------------------------------------------------------------------------------
Note
-----
- estimated index size: 2097K bytes
14 rows selected.
一.5 创建真实索引
SQL> create index idx_t on sys.test_index_size(object_id) ;
Index created.
SQL> analyze index IDX_T validate structure;
Index analyzed.
SQL> select bytes from dba_segments where segment_name='IDX_T';
BYTES
----------
2097152
可以看到2种办法给出的索引评估大小与实际索引占用空间差别不大,但这里有个前提条件就是预估索引大小之前必须对表进行分析过。
转载于:https://www.cnblogs.com/lhrbest/p/4548632.html
oracle 如何预估将要创建的索引的大小相关推荐
- oracle索引大小暴增_oracle 如何预估将要创建的索引的大小
一.1oracle 如何预估将要创建的索引的大小 oracle 提供了2种可以预估将要创建的索引大小的办法: ① 利用包 Dbms_space.create_index_cost 直接得到 ② 利 ...
- Oracle如何预估将要创建的索引和表的大小
Oracle如何预估将要创建的索引和表的大小 1. 对于表和索引空间的预估,可以使用DBMS_SPACE包的CREATE_TABLE_COST和CREATE_INDEX_COST存储过程,虽然没有看这 ...
- Oracle分区之五:创建分区索引总结
分区索引总结: 一,分区索引分为2类: 1.global,它必定是Prefix的.不存在non-prefix的 2.local,它又分成2类: 2.1.prefix:索引的第一个列等于表的分区列 ...
- oracle自动分区如何创建本地索引吗,创建与管理Oracle分区表和本地索引的实例解析...
创建与管理Oracle分区表和本地索引的相关知识是本文我们主要要介绍的内容,我们知道,Oracle的分区技术在某些条件下可以极大的提高查询的性能,所以被广泛采用.从产品上说,分区技术是Oracle企业 ...
- oracle查看创建索引语句,ORACLE下如何获得全部的索引创建语句
ORACLE下如何获得全部的索引创建语句 ORACLE下如何获得全部的索引创建语句 今天打算将一个数据库的索引在另一个测试库上重新创建一遍,研究了一下. set pagesize 0 set long ...
- oracle 创建clob类型字段的索引,LOB字段相关概念(自动创建LOB索引段和重建索引方法)...
LOBs,或Large Objects字段,是Oracle中用于处理存储非字符数据推荐的一种字段类型,例如mp3,video,图片,和long字符串数据.二进制大对象,或BLOBs,字符大对象,或CL ...
- oracle中LOB字段相关概念(自动创建LOB索引段和重建索引方法)
OBs,或Large Objects字段,是Oracle中用于处理存储非字符数据推荐的一种字段类型,例如mp3,video,图片,和long字符串数据.二进制大对象,或BLOBs,字符大对象,或CLO ...
- oracle nolgging,ORACLE创建管理索引
ORACLE索引管理需要遵从一系列的指导原则,包含以下内容: 插入表数据之后再创建索引 针对合理的表和列创建索引 对索引列的顺序进行排列来提升性能 限制每个表的索引的个数 删除不再需要的索引 估计索引 ...
- ORACLE创建唯一索引
oracle创建唯一索引 Create UNIQUE Index PK_INSTANCE_ID on TB_DD_APPROVAL_OUT (INSTANCE_ID ) oracle基于多列的唯一性约 ...
最新文章
- 设计模式之工厂模式和抽象工厂模式
- Cissp-【第1章 安全和风险管理】-2020-12-03(1页-32页)
- Amazing Slide(图片轮播制作工具)中文版
- 在html页面中加入矢量图,HTML5画布矢量图形?
- angular 自定义指令参数详解
- 关于 命令行参数 main(int argc,char** argv)
- php设置排序,7种php基本排序实现方法
- Javascript获取类名方法
- linux设置服务开机启动
- linux卸载htop,linux下 htop 工具简介
- 你是怎么看待那些拿几千块钱炒股的人?
- 大学计算机实验教程实验报告2.2,大学计算机实验2 实验报告.pdf
- 优酷下载的会员独享KUX视频格式怎么转换成MP4
- php登录界面的代码,php登录页面()代码
- Linux教程+操作系统教程 -- 大全
- 心理学在游戏设计中的作用
- C语言中file文件指针概念及其操作 (转载)
- linux文件误删除该如何恢复?
- 计算机键盘都起什么作用,电脑键盘各个按键功能 电脑键盘各个按键有什么功能...
- Keepalived HAProxy应用