Asynchronous Global Index

RDBMS 19.23

-- 参考文档:

https://docs.oracle.com/database/121/VLDBG/GUID-087B87A6-959A-40C6-82AF-36E401FD089B.htm#VLDBG14107 -- 异步GIDX简介

https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_3001.htm#CIHCAAGD -- update [global] index

How To Update Both Global and Local Indexes when Moving Table Partition? (Doc ID 795854.1) -- 更新global索引和local索引 参考

How to Drop/Truncate Multiple Partitions in Oracle 12C (Doc ID 1482264.1) -- Index maintenance

Global Index Maintenance (GIDX) on Partitioned Tables not Running Asynchronously in 12c+ (Doc ID 2404701.1) -- 条件

https://oracle-base.com/articles/12c/asynchronous-global-index-maintenance-for-drop-and-truncate-partition-12cr1#:\~:text=When combined with the UPDATE INDEXES clause the,types%2C domain indexes or those owned by SYS.

异步GIDX简介:

Asynchronous Global Index Maintenance for Dropping and Truncating Partitions

The partition maintenance operations DROP PARTITION and TRUNCATE PARTITION are optimized by making the index maintenance for metadata only.

Asynchronous global index maintenance for DROP and TRUNCATE is performed by default; however, the UPDATE INDEXES clause is still required for backward compatibility.

The following list summarizes the limitations of asynchronous global index maintenance:

  • Only performed on heap tables

  • No support for tables with object types

  • No support for tables with domain indexes

  • Not performed for the user SYS

Maintenance operations on indexes can be performed with the automatic scheduler job SYS.PMO_DEFERRED_GIDX_MAINT_JOB to clean up all global indexes. This job is scheduled to run at 2:00 A.M. on a daily basis by default. You can run this job at any time using DBMS_SCHEDULER.RUN_JOB if you want to proactively clean up the indexes. You can also modify the job to run with a different schedule based on your specific requirements. However, Oracle recommends that you do not drop the job.

You can also force cleanup of an index needing maintenance using one of the following options:

  • DBMS_PART.CLEANUP_GIDX - This PL/SQL procedure gathers the list of global indexes in the system that may require cleanup and runs the operations necessary to restore the indexes to a clean state.

  • ALTER INDEX REBUILD [PARTITION] -- This SQL statement rebuilds the entire index or index partition as is done in releases previous to Oracle Database 12c Release 1 (12.1). The resulting index (partition) does not contain any stale entries.

  • ALTER INDEX [PARTITION] COALESCE CLEANUP -- This SQL statement cleans up any orphaned entries in index blocks.

异步GIDX的条件:

There are a few situations under which asynchronous GIDX will not run:

There is a domain index on the table (unsupported for async index maintenance)

The #_of_table_segments_truncated * #_of_global_index_partitions is > 125000 (reference unpublished Bug 19017670].

The DBA has set the hidden parameter "_fast_index_maintenance" = FALSE to disable asynchronous GIDX maintenance (not recommended).

-- 查看隐含参数: _fast_index_maintenance 为true

复制代码
SYS@cdbtest SQL> select a.ksppinm name,b.ksppstvl value,a.ksppdesc description     
  from x$ksppi a,x$ksppcv b
 where a.inst_id = USERENV ('Instance')
   and b.inst_id = USERENV ('Instance')
   and a.indx = b.indx
and upper(a.ksppinm) LIKE upper('%_fast_index_maintenance%')
   order by name  2    3    4    5    6    7  
  8  ;

NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
DESCRIPTION
--------------------------------------------------------------------------------
_fast_index_maintenance
TRUE
fast global index maintenance during PMOPs


SYS@cdbtest SQL>  

-- 查看MO_DEFERRED_GIDX_MAINT_SCHED,修改为每天8点开始运行,默认为凌晨两点开始运行(方便测试,晚上要关闭测试机)

复制代码
begin
dbms_scheduler.set_attribute (
name => 'SYS.PMO_DEFERRED_GIDX_MAINT_SCHED',
attribute => 'REPEAT_INTERVAL',
value => 'FREQ=DAILY; BYHOUR=8; BYMINUTE=0; BYSECOND=0'
);
end;
/ 

-- 查看修改后的结果

复制代码
SYS@cdbtest SQL>  select start_date,last_start_date,next_run_date from dba_scheduler_jobs where job_name='PMO_DEFERRED_GIDX_MAINT_JOB';

START_DATE
---------------------------------------------------------------------------
LAST_START_DATE
---------------------------------------------------------------------------
NEXT_RUN_DATE
---------------------------------------------------------------------------
03-JUL-24 08.00.00.882192 AM PST8PDT
01-JUL-24 04.41.01.939138 PM PST8PDT
03-JUL-24 08.00.00.882192 AM PST8PDT


SYS@cdbtest SQL> 

-- 创建测试用的分区表和索引

复制代码
CREATE TABLE mytesttable
(deptno number, secondcol varchar2(80))
PARTITION BY RANGE (deptno)
(
PARTITION p1 VALUES LESS THAN (100001),
PARTITION p2 VALUES LESS THAN (250001),
PARTITION p3 VALUES LESS THAN (350001),
PARTITION p4 VALUES LESS THAN (450001),
PARTITION p5 VALUES LESS THAN (550001)
);

-- insert rows
begin
for i in 1..550000 loop
insert into mytesttable values (i, rpad('x',80,'x'));
end loop;
commit;
end;
/
/
/

-- create global index
create index deptno_idx on mytesttable (deptno) global;

-- truncate或者drop掉一个分区,这里使用update index,而不是使用update global index。 不要使用update global index,不然达不到测试效果

两者的区别:

The following is a sample to verify that 'UPDATE INDEXES' will update both global and local index during partition move.

复制代码
ALTER TABLE mytesttable TRUNCATE PARTITIONS p2,p3 update indexes;
ALTER TABLE mytesttable TRUNCATE PARTITIONS p1 update indexes;
--alter table mytesttable drop partition p3 update global indexes;

-- 查看是否有orphaned_entries,orphaned_entries=yes,即达到测试目的

复制代码
SYS@cdbtest SQL> select table_name,
index_name,
status,
orphaned_entries
from dba_indexes
where orphaned_entries='YES';  2    3    4    5    6  

TABLE_NAME
--------------------------------------------------------------------------------
INDEX_NAME
--------------------------------------------------------------------------------
STATUS   ORP
-------- ---
MYTESTTABLE
DEPTNO_IDX
VALID    YES


SYS@cdbtest SQL> 

-- 查看MO_DEFERRED_GIDX_MAINT_SCHED是否运行。这里设置了8:00开始运行,但是实际运行是下午4点多(这个地方比较奇怪,以为设置为8点就8点准时运行,实际上看,是在下午空闲时间运行了)

复制代码
SYS@cdbtest SQL> select start_date,last_start_date,next_run_date from dba_scheduler_jobs where job_name='PMO_DEFERRED_GIDX_MAINT_JOB';

START_DATE
---------------------------------------------------------------------------
LAST_START_DATE
---------------------------------------------------------------------------
NEXT_RUN_DATE
---------------------------------------------------------------------------
03-JUL-24 08.00.00.882192 AM PST8PDT
01-JUL-24 04.41.01.939138 PM PST8PDT
03-JUL-24 08.00.00.882192 AM PST8PDT


SYS@cdbtest SQL> 

SYS@cdbtest SQL> select start_date,last_start_date,next_run_date from dba_scheduler_jobs where job_name='PMO_DEFERRED_GIDX_MAINT_JOB';

START_DATE
---------------------------------------------------------------------------
LAST_START_DATE
---------------------------------------------------------------------------
NEXT_RUN_DATE
---------------------------------------------------------------------------
03-JUL-24 08.00.00.882192 AM PST8PDT
03-JUL-24 04.36.32.500768 PM PST8PDT
04-JUL-24 08.00.00.021273 AM PST8PDT


SYS@cdbtest SQL>

-- 运行完毕后,再次查看,是否还有orphaned_entries,已经没有orphaned_entries了

复制代码
SYS@cdbtest SQL>  select table_name,
index_name,
status,
orphaned_entries
from dba_indexes
where orphaned_entries='YES';  2    3    4    5    6

no rows selected

SYS@cdbtest SQL>

END

相关推荐
amao99887 小时前
数据库管理系统DBMS
数据库·oracle
Warren989 小时前
datagrip新建oracle连接教程
数据库·windows·云原生·oracle·容器·kubernetes·django
嘟嘟w10 小时前
SQL注入是什么
数据库·sql·oracle
surtr110 小时前
数据库基础(数据库原理和应用)
数据库·sql·mysql·oracle·database
DBA小马哥11 小时前
Oracle迁移金仓全攻略:工业IOT场景下的易用性与安全保障
数据库·物联网·安全·oracle
繁星星繁12 小时前
【Mysql】数据库的操作
数据库·mysql·oracle
我科绝伦(Huanhuan Zhou)12 小时前
Oracle索引技术:理论与实操全解析
数据库·oracle
sc.溯琛12 小时前
MySQL 实战:表数据维护核心技能(插入 / 更新 / 删除全解析)
数据库·oracle
云和恩墨13 小时前
告别“头痛医头”:SQL性能优化的闭环构建,从被动修复到主动掌控
数据库·oracle
p&f°13 小时前
PostgreSQL 执行计划控制参数详解
数据库·postgresql·oracle