欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle组合索引与回表

程序员文章站 2022-05-21 08:57:52
...

回表 简单来说就是数据库根据索引找到了指定的记录所在行后,还需要根据rowid再次到数据块里取数据的操作。 回表一般就是指执行

回表

简单来说就是数据库根据索引找到了指定的记录所在行后,还需要根据rowid再次到数据块里取数据的操作。

"回表"一般就是指执行计划里显示的"TABLE ACCESS BY INDEX ROWID"。

例如select的字段里有索引不包含的列

根据tom的Oracle编程艺术,建表big_table,300W数据。

建索引:

create index idx_big_table_created on big_table(created);

下面语句不会回表,因为只查询了索引列。

explain plan for

select created

from big_table a

where created = to_date('2010/3/30 10:08:30', 'yyyy/mm/dd hh24:mi:ss');

select * from table(dbms_xplan.display)

Oracle组合索引与回表

下面语句要回表,因为还查询了除索引列的其他列,虽然id字段是主键。

explain plan for

select id,created

from big_table a

where created = to_date('2010/3/30 10:08:30', 'yyyy/mm/dd hh24:mi:ss');

select * from table(dbms_xplan.display)

Oracle组合索引与回表

组合索引

当某个索引包含有多个已索引的列时,称这个索引为组合(concatented)索引。

下面语句不会回表:

explain plan for

select object_name, count(1)

from big_table a

where created >= to_date('2010/3/30 10:07:50','yyyy/mm/dd hh24:mi:ss')

and created to_date('2010/3/30 10:08:37','yyyy/mm/dd hh24:mi:ss')