Oracle 分区索引详解(local、global)

1 概述

索引是否分区
非分区索引
普通索引
分区索引
本地分区索引:Local
本地前缀分区索引:Prefixed,索引列 = 分区列
全局分区索引:Global
不适用:位图索引
本地非前缀分区索引:Nonprefixed,索引列 <> 分区列

2 分区索引

2.1 本地分区索引

create table scott.partition (
  p_id   number,
  p_id2  number,
  p_name varchar2(50),
  p_date date
) partition by range(p_id)(
  partition p1 values less than (20000),
  partition p2 values less than (40000),
  partition p3 values less than (80000),
  partition p4 values less than (100000),
  partition p5 values less than (maxvalue)
);

-- 试图创建本地分区索引
-- ORA-14024: local 索引的分区数必须等于基础表的分数数,如: 3 != 5
create index scott.partition_local on scott.partition(p_id) 
local(partition p1,
      partition p2,
      partition p3);

-- 创建本地分区索引
create index scott.partition_local on scott.partition(p_id)
local(partition p1, -- 索引分区个数 必须与 表分区数 完全对应
      partition p2,
      partition p3,
      partition p4,
      partition p5);
 
-- drop index scott.partition_local;
-- 等同上述,写法简洁,推荐
create index scott.partition_local on scott.partition(p_id)
local;

-- 默认:普通索引(非分区索引)
create index scott.partition_normal on scott.partition(p_name);

-- p_id 是 表分区列,故 scott.partition_local 为 本地前缀分区索引
-- p_id2 不是 ..., 故 scott.partition_local2 为 本地非...
create index scott.partition_local2 on scott.partition(p_id2)
local;

2.2 全局分区索引

create index scott.partition_global on scott.partition(p_date)
global partition by range(p_date)
(partition pg1 values less than(to_date('2020-01-01', 'YYYY-MM-DD')),
 partition pg2 values less than(to_date('2021-01-01', 'YYYY-MM-DD')),
 partition pg3 values less than(to_date('2022-01-01', 'YYYY-MM-DD')),
 partition pg4 values less than(to_date('2023-01-01', 'YYYY-MM-DD')),
 partition pg5 values less than(maxvalue));

-- drop index scott.partition_global;
-- 同理,若分区表已存在列分区,以下为简洁写法
create index scott.partition_global on scott.partition(p_date)
global;

2.3 索引查询

-- 分区索引
select * from dba_part_indexes;
select * from dba_ind_partitions;

-- 普通索引
select * from dba_indexes;

3 扩展

3.1 表分区

  • 3
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼丸丶粗面

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值