In the previous
post we discussed, how AI can now create a non-partitioned index, if deemed
to be the most effective index structure, a non-partitioned index is indeed
likely the most effective index structure if the underlying table has many
partitions and the associated SQL equality predicates only reference
non-partitioned key columns. A non-partitioned index ensure Oracle only need to
scan the single index structure and not all the partitions of the local index.
But what if got SQL that reference the column
by which the underlying table is partitioned?
The following SQL has an equality
predicate on the RELEASE_DATE column, the column by which the table got
partitioned.
ai_demo@PDB19> set
autotrace traceonly exp statistics
ai_demo@PDB19> select * from demo023 where release_dt = sysdate;
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 2198382565
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3517 | 370K| 2878 (1)| 00:00:01 | | |
| 1 | PARTITION RANGE SINGLE | | 3517 | 370K| 2878 (1)| 00:00:01 | KEY | KEY |
|* 2 | TABLE ACCESS STORAGE FULL| DEMO023 | 3517 | 370K| 2878 (1)| 00:00:01 | KEY | KEY |
------------------------------------------------------------------------------------------------------
Predicate Information
(identified by operation id):
---------------------------------------------------
2 -
storage("RELEASE_DT"=SYSDATE@!)
filter("RELEASE_DT"=SYSDATE@!)
if we look at the subsequent AI report:
ai_demo@PDB19> select * from demo023 where release_dt = sysdate;
----------------------------------------------------------
Plan hash value: 2198382565
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3517 | 370K| 2878 (1)| 00:00:01 | | |
| 1 | PARTITION RANGE SINGLE | | 3517 | 370K| 2878 (1)| 00:00:01 | KEY | KEY |
|* 2 | TABLE ACCESS STORAGE FULL| DEMO023 | 3517 | 370K| 2878 (1)| 00:00:01 | KEY | KEY |
------------------------------------------------------------------------------------------------------
---------------------------------------------------
filter("RELEASE_DT"=SYSDATE@!)
-------------------------------------------------------------------------------
Index candidates : 2
Indexes created (visible / invisible) : 1 (1 / 0)
Space used (visible / invisible) : 137.36 MB (137.36 MB / 0 B)
Indexes dropped : 0
SQL statements verified : 1
SQL statements improved (improvement factor) : 1 (10504.7x)
SQL plan baselines created : 0
Overall improvement factor : 10504.7x
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Unused indexes : 0
Space used : 0 B
Unusable indexes : 0
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
1. The following indexes were created:
*: invisible
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
| Owner | Table | Index | Key | Type | Properties |
-------------------------------------------------------------------------------
| AI_DEMO | DEMO023 | SYS_AI_11muvn2pw0ym6 | RELEASE_DT | B-TREE | LOCAL |
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
1. The performance of the following statements improved:
-------------------------------------------------------------------------------
Parsing Schema Name : AI_DEMO
SQL ID : ctv01z9wf6q7h
SQL Text : select * from demo023 where release_dt = sysdate
Improvement Factor : 10504.7x
-----------------------------
Original Plan Auto Index Plan
---------------------------- ----------------------------
Elapsed Time (s): 786346 1191
CPU Time (s): 533290 1582
Buffer Gets: 31740 3
Optimizer Cost: 2878 4
Disk Reads: 10424 2
Direct Writes: 0 0
Rows Processed: 0 0
Executions: 3 1
---------------------------------------------------------------------------------------------
-----------------------------
Plan Hash Value : 2198382565
| Id | Operation | Name | Rows | Bytes | Cost | Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2878 | |
| 1 | PARTITION RANGE SINGLE | | 3517 | 379836 | 2878 | 00:00:01 |
| 2 | TABLE ACCESS STORAGE FULL | DEMO023 | 3517 | 379836 | 2878 | 00:00:01 |
---------------------------------------------------------------------------------
-----------------------------
Plan Hash Value : 1782259668
| Id | Operation | Name | Rows | Bytes | Cost | Time |
--------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 216 | 4 | 00:00:01 |
| 1 | PARTITION RANGE SINGLE | | 2 | 216 | 4 | 00:00:01 |
| 2 | TABLE ACCESS BY LOCAL INDEX ROWID BATCHED | DEMO023 | 2 | 216 | 4 | 00:00:01 |
| * 3 | INDEX RANGE SCAN | SYS_AI_11muvn2pw0ym6 | 1 | | 3 | 00:00:01 |
--------------------------------------------------------------------------------------------------------------
------------------------------------------
* 3 - access("RELEASE_DT"=SYSDATE@!)
-----
- Dynamic sampling used for this statement ( level = 11 )
2 status,visibility,clustering_factor,leaf_blocks
3 from all_indexes
4 where table_name ='DEMO023'
5 and owner ='AI_DEMO';
---------- ------------------------- ------- --- --- -------- --------- ----------------- -----------
AI_DEMO SYS_AI_g4dwbmutt3xqu FULL YES NO VALID VISIBLE 9999423 21374
AI_DEMO SYS_AI_11muvn2pw0ym6 FULL YES YES N/A VISIBLE 10000000 15374
2 from user_ind_columns
3 where table_name ='DEMO023'
4 order by 1,3;
------------------------- ---------- ---------------
SYS_AI_11muvn2pw0ym6 RELEASE_DT 1
SYS_AI_g4dwbmutt3xqu SALES_AMT 1
2 from user_ind_partitions ip,
3 user_indexes i
4 where ip.index_name = i.index_name
5 and i.table_name ='DEMO023';
------------------------- --------------- -------- -------------
SYS_AI_11muvn2pw0ym6 P2010 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145010 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145011 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145012 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145013 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145014 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145015 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145016 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145017 USABLE ADVANCED LOW
SYS_AI_11muvn2pw0ym6 SYS_P145018 USABLE ADVANCED LOW
No comments:
Post a Comment