标签云
asm恢复 bbed bootstrap$ dul In Memory kcbzib_kcrsds_1 kccpb_sanity_check_2 MySQL恢复 ORA-00312 ORA-00607 ORA-00704 ORA-00742 ORA-01110 ORA-01555 ORA-01578 ORA-01595 ORA-08103 ORA-600 2131 ORA-600 2662 ORA-600 3020 ORA-600 4000 ORA-600 4137 ORA-600 4193 ORA-600 4194 ORA-600 16703 ORA-600 kcbzib_kcrsds_1 ORA-600 KCLCHKBLK_4 ORA-15042 ORA-15196 ORACLE 12C oracle dul ORACLE PATCH Oracle Recovery Tools oracle加密恢复 oracle勒索 oracle勒索恢复 oracle异常恢复 Oracle 恢复 ORACLE恢复 ORACLE数据库恢复 oracle 比特币 OSD-04016 YOUR FILES ARE ENCRYPTED 勒索恢复 比特币加密文章分类
- Others (2)
- 中间件 (2)
- WebLogic (2)
- 操作系统 (103)
- 数据库 (1,743)
- DB2 (22)
- MySQL (75)
- Oracle (1,591)
- Data Guard (52)
- EXADATA (8)
- GoldenGate (24)
- ORA-xxxxx (162)
- ORACLE 12C (72)
- ORACLE 18C (6)
- ORACLE 19C (15)
- ORACLE 21C (3)
- Oracle 23ai (8)
- Oracle ASM (68)
- Oracle Bug (8)
- Oracle RAC (54)
- Oracle 安全 (6)
- Oracle 开发 (28)
- Oracle 监听 (28)
- Oracle备份恢复 (582)
- Oracle安装升级 (95)
- Oracle性能优化 (62)
- 专题索引 (5)
- 勒索恢复 (84)
- PostgreSQL (28)
- pdu工具 (5)
- PostgreSQL恢复 (9)
- SQL Server (30)
- SQL Server恢复 (11)
- TimesTen (7)
- 达梦数据库 (2)
- 生活娱乐 (2)
- 至理名言 (11)
- 虚拟化 (2)
- VMware (2)
- 软件开发 (37)
- Asp.Net (9)
- JavaScript (12)
- PHP (2)
- 小工具 (20)
-
最近发表
- PostgreSQL运行日志管理
- ora-600 kdsgrp1 错误描述
- GAM、SGAM 或 PFS 页上存在页错误处理
- ORA-600 krhpfh_03-1208
- VMware勒索加密恢复(vmdk勒索恢复)
- ORA-39773: parse of metadata stream failed故障处理
- sql数据库备份失败—失败: 23(数据错误(循环冗余检查)
- vmdk文件被加密恢复(虚拟机文件加密)
- 差点被误操作的ORA-600 kcratr_nab_less_than_odr故障
- win平台19c 打patch遭遇2个小问题汇总
- pg单个数据库目录恢复-pdu恢复单个数据库目录数据
- pg删除数据恢复—pdu恢复pg delete数据
- .[OnlyBuy@cyberfear.com].REVRAC勒索mysql恢复
- 表dml操作权限授权给public,导致只读用户失效
- 21c数据库恢复遭遇ora-600 ktugct: corruption detected
- pg_control丢失/损坏处理
- 当前主流数据库版本服务支持周期-202503
- pg启动报invalid checkpoint record处理
- 删除redo导致ORA-00313 ORA-00312故障处理
- Navicat连接postgresql时出现column “datlastsysoid” does not exist错误解决
标签归档:ORACLE 12C
ORACLE 12C Windows-Linux 部署DATAGURAD
环境描述
win 64中的ORACLE 12C(primary)与Linux 64中的ORACLE 12C(standby)搭建datagurad
primary force logging
C:\Users\XIFENFEI>sqlplus / as sysdba SQL*Plus: Release 12.1.0.1.0 Production on 星期六 8月 24 16:59:53 2013 Copyright (c) 1982, 2013, Oracle. All rights reserved. 连接到: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options CDB_CDB$ROOT@SYS> select banner from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production PL/SQL Release 12.1.0.1.0 - Production CORE 12.1.0.1.0 Production TNS for 64-bit Windows: Version 12.1.0.1.0 - Production NLSRTL Version 12.1.0.1.0 - Production CDB_CDB$ROOT@SYS> alter database force logging ; 数据库已更改。
primary rman backup
backup filesperset = 5 as compressed backupset database format 'd:/backup/rman/full_%U.rman';
primary 生成standby controlfile
CDB_CDB$ROOT@SYS> ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'c:/control01.ctl'; 数据库已更改。 CDB_CDB$ROOT@SYS> create pfile='e:/pfile.txt' from spfile; 文件已创建。
standby 参数文件
DB_CREATE_FILE_DEST='+DATA' db_create_online_log_dest_1='+DATA' db_unique_name='cdb_dg' service_names='cdb' log_archive_dest_1='LOCATION=/u02/app/oracle/archivelog/ valid_for=(all_logfiles,all_roles)' log_archive_dest_2='service=primary lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=cdb' log_archive_config='dg_config=(cdb,cdb_dg)' standby_file_management=auto db_file_name_convert='E:\APP\XIFENFEI\ORADATA\','+DATA\CDB_DG\DATAFILE\' log_file_name_convert='E:\APP\XIFENFEI\ORADATA\','+DATA\CDB_DG\LOGFILE\' fal_server=primary
primary 修改参数
CDB_CDB$ROOT@SYS> alter system set log_archive_config='dg_config=(cdb,cdb_dg)'; 系统已更改。 CDB_CDB$ROOT@SYS> alter system set log_archive_dest_2=' 2 service=standby lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=cdb_dg'; 系统已更改。 CDB_CDB$ROOT@SYS> alter system set log_archive_dest_1= 2 'LOCATION=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles)'; 系统已更改。 CDB_CDB$ROOT@SYS> alter system set fal_server=standby; 系统已更改。 CDB_CDB$ROOT@SYS> alter system set standby_file_management=auto; 系统已更改。 CDB_CDB$ROOT@SYS> alter system set db_file_name_convert='+DATA\CDB_DG\DATAFILE\','E:\APP\XIFENFEI\ORADATA\' scope=spfile; 系统已更改。 CDB_CDB$ROOT@SYS> alter system set log_file_name_convert='+DATA\CDB_DG\LOGFILE\','E:\APP\XIFENFEI\ORADATA\' scope=spfile; 系统已更改。
primary and standby tns
STANDBY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.30.32 )(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb) ) ) PRIMARY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.30.1 )(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb) ) )
standby restore controlfile
ASMCMD> cp /tmp/CONTROL01.CTL control01.ctl copying /tmp/CONTROL01.CTL -> +data/cdb/control01.ctl
standby password file
[oracle@xifenfei dbs]$ pwd /u01/app/oracle/product/12.1/db_1/dbs [oracle@xifenfei dbs]$ cp /tmp/rman/PWDcdb.ora orapwcdb
standby mount
SYS% cdb> create spfile from pfile='initcdb.ora'; File created. SYS% cdb> startup mount; ORACLE instance started. Total System Global Area 521936896 bytes Fixed Size 2290264 bytes Variable Size 314576296 bytes Database Buffers 197132288 bytes Redo Buffers 7938048 bytes Database mounted. SYS% cdb> select banner from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production PL/SQL Release 12.1.0.1.0 - Production CORE 12.1.0.1.0 Production TNS for Linux: Version 12.1.0.1.0 - Production NLSRTL Version 12.1.0.1.0 - Production SYS% cdb> select name from v$datafile; NAME -------------------------------------------------------------------------------- E:\APP\XIFENFEI\ORADATA\CDB\SYSTEM01.DBF E:\APP\XIFENFEI\ORADATA\CDB\PDBSEED\SYSTEM01.DBF E:\APP\XIFENFEI\ORADATA\CDB\SYSAUX01.DBF E:\APP\XIFENFEI\ORADATA\CDB\PDBSEED\SYSAUX01.DBF E:\APP\XIFENFEI\ORADATA\CDB\UNDOTBS01.DBF E:\APP\XIFENFEI\ORADATA\CDB\USERS01.DBF E:\APP\XIFENFEI\ORADATA\CDB\PDB\SYSTEM01.DBF E:\APP\XIFENFEI\ORADATA\CDB\PDB\SYSAUX01.DBF E:\APP\XIFENFEI\ORADATA\CDB\PDB\PDB_USERS01.DBF 9 rows selected.
standby rman restore
--清理控制文件中的备份集垃圾 DELETE noprompt OBSOLETE; crosscheck backup; delete noprompt expired backup; --注册新备份集 catalog start with '/tmp/rman/'; --还原数据文件 run { set newname for database to '+data'; restore database; switch datafile all; }
standby clear redo
SYS% cdb> select group# from v$log; GROUP# ---------- 4 6 5 SYS% cdb> alter database clear logfile group 4; Database altered. SYS% cdb> alter database clear logfile group 5; Database altered. SYS% cdb> alter database clear logfile group 6; Database altered.
standby add standby redolog
SYS% cdb> ALTER DATABASE ADD STANDBY LOGFILE GROUP 10 size 50M; Database altered. SYS% cdb> ALTER DATABASE ADD STANDBY LOGFILE GROUP 11 size 50M; Database altered. SYS% cdb> ALTER DATABASE ADD STANDBY LOGFILE GROUP 12 size 50M; Database altered. SYS% cdb> ALTER DATABASE ADD STANDBY LOGFILE GROUP 13 size 50M; Database altered.
primary add standby redolog
CDB_CDB$ROOT@SYS> ALTER DATABASE ADD STANDBY LOGFILE GROUP 10 'E:\APP\XIFENFEI\ORADATA\CDB\std_redo10.log' size 50M; 数据库已更改。 CDB_CDB$ROOT@SYS> ALTER DATABASE ADD STANDBY LOGFILE GROUP 11 'E:\APP\XIFENFEI\ORADATA\CDB\std_redo11.log' size 50M; 数据库已更改。 CDB_CDB$ROOT@SYS> ALTER DATABASE ADD STANDBY LOGFILE GROUP 12 'E:\APP\XIFENFEI\ORADATA\CDB\std_redo12.log' size 50M; 数据库已更改。 CDB_CDB$ROOT@SYS> ALTER DATABASE ADD STANDBY LOGFILE GROUP 13 'E:\APP\XIFENFEI\ORADATA\CDB\std_redo13.log' size 50M; 数据库已更改。
standby readonly
SYS% cdb> ALTER DATABASE OPEN READ ONLY; Database altered.
standby start mrp
SYS% cdb> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION; Database altered.
DATAGURAD 是否正常检查
--primary CDB_CDB$ROOT@SYS> archive log list; 数据库日志模式 存档模式 自动存档 启用 存档终点 USE_DB_RECOVERY_FILE_DEST 最早的联机日志序列 374 下一个存档日志序列 376 当前日志序列 376 --standby Mon Aug 12 13:56:51 2013 All non-current ORLs have been archived. Mon Aug 12 13:56:53 2013 Media Recovery Log /u02/app/oracle/archivelog/1_370_820595806.dbf Mon Aug 12 13:56:57 2013 Media Recovery Log /u02/app/oracle/archivelog/1_371_820595806.dbf Mon Aug 12 13:57:02 2013 Media Recovery Log /u02/app/oracle/archivelog/1_372_820595806.dbf Mon Aug 12 13:57:04 2013 Media Recovery Log /u02/app/oracle/archivelog/1_373_820595806.dbf Mon Aug 12 13:57:05 2013 Media Recovery Log /u02/app/oracle/archivelog/1_374_820595806.dbf Media Recovery Waiting for thread 1 sequence 375 Mon Aug 12 13:57:19 2013 Primary database is in MAXIMUM PERFORMANCE mode RFS[2]: Assigned to RFS process (PID:26114) RFS[2]: No standby redo logfiles created for thread 1 RFS[2]: Opened log for thread 1 sequence 376 dbid 1937199326 branch 820595806 Mon Aug 12 13:57:19 2013 RFS[3]: Assigned to RFS process (PID:26118) RFS[3]: Opened log for thread 1 sequence 375 dbid 1937199326 branch 820595806 Mon Aug 12 13:57:19 2013 Archived Log entry 16 added for thread 1 sequence 375 rlc 820595806 ID 0x7377d8de dest 2: Mon Aug 12 13:57:22 2013 Media Recovery Log /u02/app/oracle/archivelog/1_375_820595806.dbf Media Recovery Waiting for thread 1 sequence 376 (in transit)
ORACLE 12C Partial Global/Local Indexes for Partitioned Tables
以前我有个想法,我只想对其中的某个或者某几个分区上创建索引,其他分区不想创建,在12C之前的版本,无论是Local还是Global index,都不能实现该需求,但是从ORACLE 12C开始引进了Partial Global/Local Indexes for Partitioned Tables,解决了该问题,可以在指定的分区上创建本地索引或者全局索引,主要语法是在表或者分区,子分区级别设置[INDEXING { ON | OFF }]
创建测试表
CDB_PDB@CHF> SELECT BANNER FROM V$VERSION; BANNER -------------------------------------------------------------------------------- Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production PL/SQL Release 12.1.0.1.0 - Production CORE 12.1.0.1.0 Production TNS for 64-bit Windows: Version 12.1.0.1.0 - Production NLSRTL Version 12.1.0.1.0 - Production CDB_PDB@CHF> CREATE TABLE xifenfei_orders ( 2 order_id NUMBER(12), 3 order_address varchar2(100), 4 order_mode VARCHAR2(20)) 5 INDEXING OFF 6 PARTITION BY RANGE (order_id) 7 (PARTITION ord_p1 VALUES LESS THAN (100) INDEXING ON, 8 PARTITION ord_p2 VALUES LESS THAN (200) INDEXING OFF, 9 PARTITION ord_p3 VALUES LESS THAN (300) INDEXING ON, 10 PARTITION ord_p4 VALUES LESS THAN (400), 11 PARTITION ord_p5 VALUES LESS THAN (500)); 表已创建。
创建LOCAL INDEX
CDB_PDB@CHF> CREATE INDEX ind_lox on xifenfei_orders(order_address) LOCAL INDEXING PARTIAL; 索引已创建。 CDB_PDB@CHF> COL INDEX_NAME FOR A10 CDB_PDB@CHF> COL PARTITION_NAME FOR A15 CDB_PDB@CHF> select index_name, partition_name,STATUS 2 from user_ind_partitions 3 where index_name = 'IND_LOX'; INDEX_NAME PARTITION_NAME STATUS ---------- --------------- -------- IND_LOX ORD_P5 UNUSABLE IND_LOX ORD_P4 UNUSABLE IND_LOX ORD_P3 USABLE IND_LOX ORD_P2 UNUSABLE IND_LOX ORD_P1 USABLE --设置INDEXING OFF对应的index 状态为UNUSABLE,分区继承表 CDB_PDB@CHF> select partition_name,indexing from user_tab_partitions where table_name='XIFENFEI_ORDERS'; PARTITION_NAME INDE --------------- ---- ORD_P5 OFF ORD_P4 OFF ORD_P3 ON ORD_P2 OFF ORD_P1 ON --因为segment 延迟,无数据,所以无分区和索引记录 CDB_PDB@CHF> SELECT PARTITION_NAME,SEGMENT_NAME FROM USER_SEGMENTS WHERE SEGMENT_NAME='IND_LOX'; 未选定行 CDB_PDB@CHF> SELECT PARTITION_NAME,SEGMENT_NAME FROM USER_SEGMENTS WHERE SEGMENT_NAME='XIFENFEI_ORDERS'; 未选定行 CDB_PDB@CHF> begin 2 for i in 1 .. 449 loop 3 insert into xifenfei_orders 4 values 5 (i,'www.xifenfei.com'||i,'惜分飞'||i); 6 end loop; 7 commit; 8 end; 9 / PL/SQL 过程已成功完成。 --插入记录后,分区表有相关记录 CDB_PDB@CHF> SELECT PARTITION_NAME,SEGMENT_NAME,blocks FROM USER_SEGMENTS WHERE SEGMENT_NAME='XIFENFEI_ORDERS'; PARTITION_NAME SEGMENT_NAME BLOCKS --------------- --------------- ---------- ORD_P5 XIFENFEI_ORDERS 1024 ORD_P4 XIFENFEI_ORDERS 1024 ORD_P3 XIFENFEI_ORDERS 1024 ORD_P2 XIFENFEI_ORDERS 1024 ORD_P1 XIFENFEI_ORDERS 1024 --注意:这里只有user_tab_partitions.indexing为on的有记录,也就是说,至于这些分区的索引被创建,其他的未被创建 CDB_PDB@CHF> SELECT PARTITION_NAME,SEGMENT_NAME FROM USER_SEGMENTS WHERE SEGMENT_NAME='IND_LOX'; PARTITION_NAME SEGMENT_NAME --------------- --------------- ORD_P1 IND_LOX ORD_P3 IND_LOX
分析执行计划
CDB_PDB@CHF> EXEC DBMS_STATS.GATHER_TABLE_STATS(USER,'XIFENFEI_ORDERS',CASCADE=>TRUE); PL/SQL 过程已成功完成。 CDB_PDB@CHF> SET AUTOT TRACE CDB_PDB@CHF> SELECT ORDER_MODE FROM XIFENFEI_ORDERS WHERE ORDER_ADDRESS='www.xifenfei.com99'; 未选定行 执行计划 ---------------------------------------------------------- Plan hash value: 2800545636 ------------------------------------------------------------------------------------------------------------------------ -------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ------------------------------------------------------------------------------------------------------------------------ -------- | 0 | SELECT STATEMENT | | 1 | 30 | 40 (0)| 00:00:01 | | | | 1 | VIEW | VW_TE_2 | 2 | 24 | 40 (0)| 00:00:01 | | | | 2 | UNION-ALL | | | | | | | | | 3 | PARTITION RANGE OR | | 1 | 34 | 1 (0)| 00:00:01 |KEY(OR)| KEY(OR)| |* 4 | TABLE ACCESS BY LOCAL INDEX ROWID BATCHED| XIFENFEI_ORDERS | 1 | 34 | 1 (0)| 00:00:01 |KEY(OR)| KEY(OR)| |* 5 | INDEX RANGE SCAN | IND_LOX | 1 | | 1 (0)| 00:00:01 |KEY(OR)| KEY(OR)| | 6 | PARTITION RANGE OR | | 1 | 34 | 39 (0)| 00:00:01 |KEY(OR)| KEY(OR)| |* 7 | TABLE ACCESS FULL | XIFENFEI_ORDERS | 1 | 34 | 39 (0)| 00:00:01 |KEY(OR)| KEY(OR)| ------------------------------------------------------------------------------------------------------------------------ -------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("XIFENFEI_ORDERS"."ORDER_ID"<100 OR "XIFENFEI_ORDERS"."ORDER_ID">=200 AND "XIFENFEI_ORDERS"."ORDER_ID"<300) 5 - access("ORDER_ADDRESS"='www.xifenfei.com99') 7 - filter("ORDER_ADDRESS"='www.xifenfei.com99' AND ("XIFENFEI_ORDERS"."ORDER_ID">=300 AND "XIFENFEI_ORDERS"."ORDER_ID"<500 OR "XIFENFEI_ORDERS"."ORDER_ID"<200 AND "XIFENFEI_ORDERS"."ORDER_ID">=100)) --这里可以看到,当我们没有指定分区范围的时候,显示的执行计划是有分区index的部分直接走index,没有分区index的部分是扫描分区 统计信息 ---------------------------------------------------------- 34 recursive calls 0 db block gets 120 consistent gets 1 physical reads 0 redo size 347 bytes sent via SQL*Net to client 533 bytes received via SQL*Net from client 1 SQL*Net roundtrips to/from client 5 sorts (memory) 0 sorts (disk) 0 rows processed CDB_PDB@CHF> SELECT ORDER_MODE FROM XIFENFEI_ORDERS t WHERE ORDER_ADDRESS='www.xifenfei.com499' and order_id>200 and ord er_id<300; 未选定行 执行计划 ---------------------------------------------------------- Plan hash value: 3337708912 ------------------------------------------------------------------------------------------------------------------------ ------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| P stop | ------------------------------------------------------------------------------------------------------------------------ ------ | 0 | SELECT STATEMENT | | 1 | 34 | 2 (0)| 00:00:01 | | | | 1 | PARTITION RANGE SINGLE | | 1 | 34 | 2 (0)| 00:00:01 | 3 | 3 | |* 2 | TABLE ACCESS BY LOCAL INDEX ROWID BATCHED| XIFENFEI_ORDERS | 1 | 34 | 2 (0)| 00:00:01 | 3 | 3 | |* 3 | INDEX RANGE SCAN | IND_LOX | 1 | | 1 (0)| 00:00:01 | 3 | 3 | ------------------------------------------------------------------------------------------------------------------------ ------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter("ORDER_ID">200) 3 - access("ORDER_ADDRESS"='www.xifenfei.com499') --指定分区查询,可以明确的看到,该sql直接使用了分区索引 统计信息 ---------------------------------------------------------- 1 recursive calls 0 db block gets 1 consistent gets 0 physical reads 0 redo size 347 bytes sent via SQL*Net to client 533 bytes received via SQL*Net from client 1 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 0 rows processed CDB_PDB@CHF> SELECT ORDER_MODE FROM XIFENFEI_ORDERS t WHERE ORDER_ADDRESS='www.xifenfei.com499' and order_id>300 and ord er_id<400; 未选定行 执行计划 ---------------------------------------------------------- Plan hash value: 2072227240 ---------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ---------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 34 | 14 (0)| 00:00:01 | | | | 1 | PARTITION RANGE SINGLE| | 1 | 34 | 14 (0)| 00:00:01 | 4 | 4 | |* 2 | TABLE ACCESS FULL | XIFENFEI_ORDERS | 1 | 34 | 14 (0)| 00:00:01 | 4 | 4 | ---------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter("ORDER_ADDRESS"='www.xifenfei.com499' AND "ORDER_ID">300) --当指定的分区无index之时,直接判断走全表扫描 统计信息 ---------------------------------------------------------- 1 recursive calls 0 db block gets 22 consistent gets 0 physical reads 0 redo size 347 bytes sent via SQL*Net to client 533 bytes received via SQL*Net from client 1 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 0 rows processed
创建Global index
CDB_PDB@CHF> ALTER INDEX ind_lox INVISIBLE; 索引已更改。 CDB_PDB@CHF> CREATE INDEX IND_G_LOX ON XIFENFEI_ORDERS(ORDER_ADDRESS) Global INDEXING PARTIAL; 索引已创建。 CDB_PDB@CHF> select index_name,indexing from dba_indexes where index_name='IND_G_LOX'; INDEX_NAME INDEXIN ---------- ------- IND_G_LOX PARTIAL
执行计划
CDB_PDB@CHF> SELECT ORDER_MODE FROM XIFENFEI_ORDERS t WHERE ORDER_ADDRESS='www.xifenfei.com99'; 未选定行 执行计划 ---------------------------------------------------------- Plan hash value: 1912382893 ------------------------------------------------------------------------------------------------------------------------ -------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ------------------------------------------------------------------------------------------------------------------------ -------- | 0 | SELECT STATEMENT | | 1 | 30 | 41 (0)| 00:00:01 | | | | 1 | VIEW | VW_TE_2 | 2 | 24 | 41 (0)| 00:00:01 | | | | 2 | UNION-ALL | | | | | | | | |* 3 | TABLE ACCESS BY GLOBAL INDEX ROWID BATCHED| XIFENFEI_ORDERS | 1 | 34 | 2 (0)| 00:00:01 | ROWID | ROWID | |* 4 | INDEX RANGE SCAN | IND_G_LOX | 1 | | 1 (0)| 00:00:01 | | | | 5 | PARTITION RANGE OR | | 1 | 34 | 39 (0)| 00:00:01 |KEY(OR)| KEY(OR)| |* 6 | TABLE ACCESS FULL | XIFENFEI_ORDERS | 1 | 34 | 39 (0)| 00:00:01 |KEY(OR)| KEY(OR)| ------------------------------------------------------------------------------------------------------------------------ -------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter("T"."ORDER_ID"<100 OR "T"."ORDER_ID">=200 AND "T"."ORDER_ID"<300) 4 - access("ORDER_ADDRESS"='www.xifenfei.com99') 6 - filter("ORDER_ADDRESS"='www.xifenfei.com99' AND ("T"."ORDER_ID">=300 AND "T"."ORDER_ID"<500 OR "T"."ORDER_ID"<200 AND "T"."ORDER_ID">=100)) --这里可以看到因为没有指定分区范围,该sql在含index的分区使用全局index,在没有index的分区直接使用全表扫描 统计信息 ---------------------------------------------------------- 1 recursive calls 0 db block gets 67 consistent gets 0 physical reads 0 redo size 347 bytes sent via SQL*Net to client 533 bytes received via SQL*Net from client 1 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 0 rows processed CDB_PDB@CHF> SELECT ORDER_MODE FROM XIFENFEI_ORDERS t WHERE ORDER_ADDRESS='www.xifenfei.com99' and order_id<100; 执行计划 ---------------------------------------------------------- Plan hash value: 3717359654 ------------------------------------------------------------------------------------------------------------------------ ------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| P stop | ------------------------------------------------------------------------------------------------------------------------ ------ | 0 | SELECT STATEMENT | | 1 | 31 | 2 (0)| 00:00:01 | | | |* 1 | TABLE ACCESS BY GLOBAL INDEX ROWID BATCHED| XIFENFEI_ORDERS | 1 | 31 | 2 (0)| 00:00:01 | 1 | 1 | |* 2 | INDEX RANGE SCAN | IND_G_LOX | 1 | | 1 (0)| 00:00:01 | | | ------------------------------------------------------------------------------------------------------------------------ ------ Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("ORDER_ID"<100) 2 - access("ORDER_ADDRESS"='www.xifenfei.com99') --指定了分区范围,而且该分区又有index,直接使用全局index 统计信息 ---------------------------------------------------------- 1 recursive calls 0 db block gets 2 consistent gets 0 physical reads 0 redo size 551 bytes sent via SQL*Net to client 544 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed CDB_PDB@CHF> SELECT ORDER_MODE FROM XIFENFEI_ORDERS t WHERE ORDER_ADDRESS='www.xifenfei.com99' and order_id>400 未选定行 执行计划 ---------------------------------------------------------- Plan hash value: 2072227240 ---------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ---------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 34 | 14 (0)| 00:00:01 | | | | 1 | PARTITION RANGE SINGLE| | 1 | 34 | 14 (0)| 00:00:01 | 5 | 5 | |* 2 | TABLE ACCESS FULL | XIFENFEI_ORDERS | 1 | 34 | 14 (0)| 00:00:01 | 5 | 5 | ---------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter("ORDER_ADDRESS"='www.xifenfei.com99' AND "ORDER_ID">400) --指定了分区范围,但是该分区无index,直接使用全表扫描 统计信息 ---------------------------------------------------------- 1 recursive calls 0 db block gets 22 consistent gets 0 physical reads 0 redo size 347 bytes sent via SQL*Net to client 533 bytes received via SQL*Net from client 1 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 0 rows processed
结论
通过测试,证明Partial Global/Local Indexes for Partitioned Tables确实能够实现对部分分区创建index。
1)如果查询条件确定的分区无index,那直接走全表扫描;
2)如果查询条件可以确定的分区范围内有index,会直接使用index(无论是Local还是GLobal);
3)如果查询条件未确定分区范围(含index和无index分区情况),那该sql会在有index分区使用index,在没有index区域走全表扫描