分区索引学习笔记

简介: 续接上次的分区表学习笔记,对分区索引进行了总结。 --index maintance SQL> select index_name,table_name from user_indexes where table_name='RANGE_PA...

续接上次的分区表学习笔记,对分区索引进行了总结。

--index maintance
SQL> select index_name,table_name from user_indexes where table_name='RANGE_PART';

no rows selected

--create one global index
SQL> create index glb_range_part on range_part(a,b)
  2  global partition by range(a)
  3  ( partition part_01 values less than(1000),
  4    partition part_02 values less than(maxvalue)
  5  );

Index created.
SQL> create index ind_range_part on range_part(a,b) local;
create index ind_range_part on range_part(a,b) local
                                          *
ERROR at line 1:
ORA-01408: such column list already indexed
--如果已经定义了index的列,则不能再创建其他的索引
--再次验证
SQL> create index ind_range_part on range_part(a,b);

Index created.

SQL> create index ind_range_part on range_part(a,b) local;
create index ind_range_part on range_part(a,b) local
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object

--提示是index名字重复了,似乎可以重新建一个其他名字的index
SQL> create index ind1_range_part on range_part(a,b);
create index ind1_range_part on range_part(a,b)
                                           *
ERROR at line 1:
ORA-01408: such column list already indexed
--这次还是回到上一步,错误重现


--如果不加local,索引在status列会有不同
SQL> select index_name,table_name,status from user_indexes where table_name='RANGE_PART';

INDEX_NAME                     TABLE_NAME                     STATUS
------------------------------ ------------------------------ --------
IND_RANGE_PART                 RANGE_PART                     VALID

SQL> drop index ind_range_part;

Index dropped.

SQL> create index ind_range_part on range_part(a,b) local;

Index created.

SQL> select index_name,table_name,status from user_indexes where table_name='RANGE_PART';

INDEX_NAME                     TABLE_NAME                     STATUS
------------------------------ ------------------------------ --------
IND_RANGE_PART                 RANGE_PART                     N/A


关于global index还有一点是global partition Index必须是prefixed的
SQL> create index ind_range_part on range_part(b,a)
global partition by range(a)
( partition part_01 values less than(1000),
  partition part_02 values less than(maxvalue)
)
SQL> /
global partition by range(a)
                           *
ERROR at line 2:
ORA-14038: GLOBAL partitioned index must be prefixed

--清除所有的索引,重新测试


SQL> create index ind_range_part on range_part(a,b)
global partition by range(a)
( partition glb_part_01 values less than(1000),
  partition glb_part_02 values less than(maxvalue)
)
  2    3    4    5    6 
SQL> /

Index created.

 

SQL> create index ind_range_part2 on range_part(b,a) local;

Index created.

 1* select index_name,status from user_indexes where table_name='RANGE_PART'
SQL> /

INDEX_NAME                     STATUS
------------------------------ --------
IND_RANGE_PART                 N/A
IND_RANGE_PART2                N/A

SQL> select index_name,partition_name,high_value,status from user_ind_partitions where index_name in(select index_name from user_indexes where table_name='RANGE_PART');

INDEX_NAME                     PARTITION_NAME                 HIGH_VALUE           STATUS
------------------------------ ------------------------------ -------------------- --------
IND_RANGE_PART                 GLB_PART_01                    1000                 USABLE
IND_RANGE_PART2                PART_05                        MAXVALUE             USABLE
IND_RANGE_PART2                PART_02                        4000                 USABLE
IND_RANGE_PART2                PART_01                        2000                 USABLE
IND_RANGE_PART                 GLB_PART_02                    MAXVALUE             USABLE

SQL> alter table range_part merge partitions part_01,part_02;

Table altered.

SQL> select index_name,partition_name,high_value,status from user_ind_partitions where index_name in(select index_name from user_indexes where table_name='RANGE_PART');

INDEX_NAME                     PARTITION_NAME                 HIGH_VALUE           STATUS
------------------------------ ------------------------------ -------------------- --------
IND_RANGE_PART                 GLB_PART_01                    1000                 UNUSABLE
IND_RANGE_PART2                PART_05                        MAXVALUE             USABLE
IND_RANGE_PART                 GLB_PART_02                    MAXVALUE             UNUSABLE
IND_RANGE_PART2                SYS_P51                        4000                 UNUSABLE

--分区编译
SQL> alter index ind_range_part2 rebuild partition SYS_P51;

Index altered.
INDEX_NAME                     PARTITION_NAME                 HIGH_VALUE           STATUS
------------------------------ ------------------------------ -------------------- --------
IND_RANGE_PART                 GLB_PART_01                    1000                 UNUSABLE
IND_RANGE_PART2                PART_05                        MAXVALUE             USABLE
IND_RANGE_PART                 GLB_PART_02                    MAXVALUE             UNUSABLE
IND_RANGE_PART2                SYS_P51                        4000                 USABLE

--对全局索引全表rebuild失败
SQL> ALTER INDEX IND_RANGE_PART REBUILD;
ALTER INDEX IND_RANGE_PART REBUILD
            *
ERROR at line 1:
ORA-14086: a partitioned index may not be rebuilt as a whole
--只能根据分区来相应rebuild

SQL> ALTER INDEX IND_RANGE_PART REBUILD PARTITION GLB_PART_01;

Index altered.

SQL> ALTER INDEX IND_RANGE_PART REBUILD PARTITION GLB_PART_02;

Index altered.


SQL> ALTER TABLE RANGE_PART RENAME PARTITION SYS_P51 TO PART_01;

Table altered.

SQL> ALTER TABLE RANGE_PART SPLIT PARTITION PART_01 AT(2000) INTO (PARTITION PART_01,PARTITION PART_02);

Table altered.

SQL> select index_name,partition_name,high_value,status from user_ind_partitions where index_name in(select index_name from user_indexes where table_name='RANGE_PART');

INDEX_NAME                     PARTITION_NAME                 HIGH_VALUE           STATUS
------------------------------ ------------------------------ -------------------- --------
IND_RANGE_PART                 GLB_PART_01                    1000                 UNUSABLE
IND_RANGE_PART2                PART_05                        MAXVALUE             USABLE
IND_RANGE_PART2                PART_02                        4000                 UNUSABLE
IND_RANGE_PART2                SYS_P51                        2000                 UNUSABLE
IND_RANGE_PART                 GLB_PART_02                    MAXVALUE             UNUSABLE

--PARTITION_NAME为SYS_P51,这个是Index的partition_name
SQL> SELECT PARTITION_NAME FROM USER_TAB_PARTITIONS WHERE TABLE_NAME='RANGE_PART';

PARTITION_NAME
------------------------------
PART_01
PART_02
PART_05

--分区名字没有问题

--rebuild索引有以下的方式
SQL> ALTER TABLE RANGE_PART MODIFY PARTITION PART_01 REBUILD UNUSABLE LOCAL INDEXES;

Table altered.

SQL> ALTER INDEX IND_RANGE_PART2 REBUILD PARTITION PART_02;

Index altered.

最后有几个视图需要注意一下。

SQL> SELECT PARTITION_COUNT,STATUS,TABLE_NAME FROM USER_PART_TABLES WHERE TABLE_NAME='RANGE_PART';

PARTITION_COUNT STATUS   TABLE_NAME
--------------- -------- ------------------------------
              3 VALID    RANGE_PART

--查找partition key
SQL> SELECT NAME,OBJECT_TYPE,COLUMN_NAME FROM USER_PART_KEY_COLUMNS WHERE NAME='RANGE_PART';


NAME                           OBJEC COLUMN_NAME
------------------------------ ----- --------------------
RANGE_PART                     TABLE A

--USER_TAB_PARTITIONS
--USER_IND_PARTITIONS

目录
相关文章
|
机器学习/深度学习 自然语言处理 知识图谱
第6章:知识建模:概述、方法、实例
第6章:知识建模:概述、方法、实例
第6章:知识建模:概述、方法、实例
|
4天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1101 0
|
3天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
471 9
|
13天前
|
人工智能 运维 安全
|
11天前
|
人工智能 测试技术 API
智能体(AI Agent)搭建全攻略:从概念到实践的终极指南
在人工智能浪潮中,智能体(AI Agent)正成为变革性技术。它们具备自主决策、环境感知、任务执行等能力,广泛应用于日常任务与商业流程。本文详解智能体概念、架构及七步搭建指南,助你打造专属智能体,迎接智能自动化新时代。
|
4天前
|
弹性计算 Kubernetes jenkins
如何在 ECS/EKS 集群中有效使用 Jenkins
本文探讨了如何将 Jenkins 与 AWS ECS 和 EKS 集群集成,以构建高效、灵活且具备自动扩缩容能力的 CI/CD 流水线,提升软件交付效率并优化资源成本。
297 0
|
10天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
12天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
800 23
|
3天前
|
缓存 供应链 监控
VVIC seller_search 排行榜搜索接口深度分析及 Python 实现
VVIC搜款网seller_search接口提供服装批发市场的商品及商家排行榜数据,涵盖热销榜、销量排名、类目趋势等,支持多维度筛选与数据分析,助力选品决策、竞品分析与市场预测,为服装供应链提供有力数据支撑。