惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - liuqun

oracle优化7(如何干预执行计划 - hints) oracle优化6(使用sql_trace/10046事件进行数据库诊断) oracle优化4(sql语句性能诊断,sql执行计划) oracle优化3(访问Table的方式) oracle优化2(选用适合的ORACLE优化器) oracle优化1(数据库、数据表、数据表I/O优化原则) Oracle常用命令14(.net / java代码调用(sql代码、程序包过程)) Oracle常用命令13(数据库的启动、关闭) Oracle常用命令12(导入:imp、导出:exp) Oracle常用命令11(触发器) Oracle常用命令10(程序包) Oracle常用命令9(函数) Oracle常用命令8(过程) Oracle常用命令7(游标) Oracle常用命令6(PL/SQL) Oracle常用命令5(同义词、视图、索引) Oracle常用命令4(表分区) Oracle常用命令3(DDL、DML、TCL、DCL、序列) Oracle常用命令2(用户、角色管理)
oracle优化5(用索引提高效率)
liuqun · 2011-04-03 · via 博客园 - liuqun

用索引提高效率

索引是表的一个概念部分,用来提高检索数据的效率. 实际上,ORACLE使用了一个复杂的自平衡B-tree结构. 通常,通过索引查询数据比全表扫描要快. ORACLE找出执行查询和Update语句的最佳路径时, ORACLE优化器将使用索引. 同样在联结多个表时使用索引也可以提高效率. 另一个使用索引的好处是,它提供了主键(primary key)的唯一性验证.

除了那些LONGLONG RAW数据类型, 你可以索引几乎所有的列. 通常, 在大型表中使用索引特别有效. 当然,你也会发现, 在扫描小表时,使用索引同样能提高效率.

虽然使用索引能得到查询效率的提高,但是我们也必须注意到它的代价. 索引需要空间来存储,也需要定期维护, 每当有记录在表中增减或索引列被修改时, 索引本身也会被修改. 这意味着每条记录的INSERT , DELETE , UPDATE将为此多付出4 , 5 次的磁盘I/O . 因为索引需要额外的存储空间和处理,那些不必要的索引反而会使查询反应时间变慢.

定期的重构索引是有必要的.

ALTER INDEX <INDEXNAME> REBUILD <TABLESPACENAME>

ORACLE对索引有以下几种访问模式:

索引扫描的类型:根据索引的类型与where限制条件的不同,有4种类型的索引扫描:

索引唯一扫描(index unique scan)

索引范围扫描(index range scan)

索引全扫描(index full scan)

索引快速扫描(index fast full scan)

索引唯一扫描(index unique scan)

通过唯一索引查找一个数值经常返回单个ROWID

说明:如果该唯一索引有多个列组成(即组合索引),则至少要有组合索引的引导列(创建组合索引时的第一列,称为引导列)参与到该查询中

如:explain plan for select * from usertab where u_id=21;

select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------

Plan hash value: 1902254847

--------------------------------------------------------------------------------

| Id  | Operation                          | Name         | Rows  | Bytes | Cost

--------------------------------------------------------------------------------

|   0 | SELECT STATEMENT                   |              |     1 |    58 |

|   1 |  TABLE ACCESS BY GLOBAL INDEX ROWID| USERTAB      |     1 |    58 |

|*  2 |   INDEX UNIQUE SCAN                | SYS_C0011318 |     1 |       |

--------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   2 - access("U_ID"=21)

14 rows selected

索引范围扫描(index range scan)

使用一个索引存取多行数据,同上面一样,如果索引是组合索引,则至少要有组合索引的引导列参与到该查询中

  在唯一索引上使用索引范围扫描的典型情况下是在谓词(where