Oracle 21版Database In-Memory LivaLabs实验(下)
Posted dingdingfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle 21版Database In-Memory LivaLabs实验(下)相关的知识,希望对你有一定的参考价值。
实验 11: In-Memory 并行执行
实验前,需要执行以下:
. ~/.set-env-db.sh CDB1
进入im-parallel目录,登录数据库:
cd /home/oracle/labs/inmemory/im-parallel
sqlplus ssb/Ora_DB4U@localhost:1521/pdb1
此实验的主要脚本执行序列如下,后面会详述:
01_parallel_status.sql
02_ssb_tables.sql
03_im_populated.sql
04_serial_single.sql
05_parallel_single.sql
06_serial_join.sql
07_parallel_join.sql
08_serial_vgb.sql
09_parallel_vgb.sql
10_imds.sql
首先查看并行的参数设置:
SQL> @01_parallel_status.sql
Connected.
SQL>
SQL> show parameters parallel
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
awr_pdb_max_parallel_slaves integer 10
containers_parallel_degree integer 65535
fast_start_parallel_rollback string LOW
max_datapump_parallel_per_job string 50
optimizer_ignore_parallel_hints boolean FALSE
parallel_adaptive_multi_user boolean FALSE
parallel_degree_limit string CPU
parallel_degree_policy string MANUAL
parallel_execution_message_size integer 16384
parallel_force_local boolean FALSE
parallel_instance_group string
parallel_max_servers integer 80
parallel_min_degree string 1
parallel_min_percent integer 0
parallel_min_servers integer 8
parallel_min_time_threshold string AUTO
parallel_servers_target integer 32
parallel_threads_per_cpu integer 1
recovery_parallelism integer 0
发布lineorder表:
SQL> @02_ssb_tables.sql
SQL> @../imlogin.sql
SQL> connect ssb/Ora_DB4U@pdb1
Connected.
SQL>
SQL> set pages 9999
SQL> set lines 150
SQL> set echo on
SQL>
SQL> alter table LINEORDER inmemory priority high;
Table altered.
SQL> exec dbms_inmemory.populate('SSB','LINEORDER');
PL/SQL procedure successfully completed.
查看发布状态:
SQL> @03_im_populated.sql
Connected.
SQL>
SQL> -- Query the view v$IM_SEGMENTS to shows what objects are in the column store
SQL> -- and how much of the objects were populated. When the BYTES_NOT_POPULATED is 0
SQL> -- it indicates the entire table was populated.
SQL>
SQL> select owner, segment_name, partition_name, populate_status, bytes,
2 inmemory_size, bytes_not_populated
3 from v$im_segments
4 where owner not in ('AUDSYS','SYS')
5 order by owner, segment_name, partition_name;
In-Memory Bytes
OWNER SEGMENT_NAME PARTITION_NAME POPULATE_STATUS Disk Size Size Not Populated
---------- -------------------- --------------- --------------- ---------------- ---------------- ----------------
SSB CUSTOMER COMPLETED 24,928,256 23,199,744 0
SSB DATE_DIM COMPLETED 122,880 1,179,648 0
SSB LINEORDER PART_1994 COMPLETED 563,609,600 478,281,728 0
SSB LINEORDER PART_1995 COMPLETED 563,470,336 478,281,728 0
SSB LINEORDER PART_1996 COMPLETED 565,018,624 480,378,880 0
SSB LINEORDER PART_1997 COMPLETED 563,322,880 479,330,304 0
SSB LINEORDER PART_1998 COMPLETED 329,015,296 280,690,688 0
SSB PART COMPLETED 56,893,440 16,973,824 0
SSB SUPPLIER COMPLETED 1,769,472 2,228,224 0
9 rows selected.
串行,单表查询:
SQL> @04_serial_single.sql
-- 耗时
Elapsed: 00:00:00.02
-- 执行计划
----------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 4376 (100)| | | |
| 1 | SORT AGGREGATE | | 1 | 9 | | | | |
| 2 | PARTITION RANGE ALL | | 41M| 358M| 4376 (27)| 00:00:01 | 1 | 5 |
| 3 | TABLE ACCESS INMEMORY FULL| LINEORDER | 41M| 358M| 4376 (27)| 00:00:01 | 1 | 5 |
----------------------------------------------------------------------------------------------------------
并行(通过设置parallel_degree_policy为AUTO),单表查询:
SQL> @05_parallel_single.sql
SQL> alter session set parallel_degree_policy=auto;
-- 耗时
Elapsed: 00:00:00.07
-- 执行计划
------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1216 (100)| | | | | | |
| 1 | SORT AGGREGATE | | 1 | 9 | | | | | | | |
| 2 | PX COORDINATOR | | | | | | | | | | |
| 3 | PX SEND QC (RANDOM) | :TQ10000 | 1 | 9 | | | | | Q1,00 | P->S | QC (RAND) |
| 4 | SORT AGGREGATE | | 1 | 9 | | | | | Q1,00 | PCWP | |
| 5 | PX BLOCK ITERATOR | | 41M| 358M| 1216 (27)| 00:00:01 | 1 | 5 | Q1,00 | PCWC | |
|* 6 | TABLE ACCESS INMEMORY FULL| LINEORDER | 41M| 358M| 1216 (27)| 00:00:01 | 1 | 5 | Q1,00 | PCWP | |
------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
6 - inmemory(:Z>=:Z AND :Z<=:Z)
Note
-----
- automatic DOP: Computed Degree of Parallelism is 4 because of degree limit
执行计划显示启用了4并行,Cost也降低了。但执行时间看不出有提升,可能因为表太小。
串行,多表的联结查询。由于有提示NO_VECTOR_TRANSFORM,因此用的是Bloom filter:
SQL> 06_serial_join.sql
-- 耗时
Elapsed: 00:00:00.16
-- 执行计划
----------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 5280 (100)| | | |
| 1 | HASH GROUP BY | | 1000 | 77000 | 5280 (38)| 00:00:01 | | |
|* 2 | HASH JOIN | | 98430 | 7401K| 5275 (38)| 00:00:01 | | |
| 3 | JOIN FILTER CREATE | :BF0001 | 365 | 4380 | 1 (0)| 00:00:01 | | |
| 4 | PART JOIN FILTER CREATE | :BF0000 | 365 | 4380 | 1 (0)| 00:00:01 | | |
|* 5 | TABLE ACCESS INMEMORY FULL | DATE_DIM | 365 | 4380 | 1 (0)| 00:00:01 | | |
|* 6 | HASH JOIN | | 451K| 28M| 5272 (38)| 00:00:01 | | |
| 7 | JOIN FILTER CREATE | :BF0002 | 4102 | 73836 | 4 (25)| 00:00:01 | | |
|* 8 | TABLE ACCESS INMEMORY FULL | SUPPLIER | 4102 | 73836 | 4 (25)| 00:00:01 | | |
|* 9 | HASH JOIN | | 2216K| 99M| 5256 (38)| 00:00:01 | | |
| 10 | JOIN FILTER CREATE | :BF0003 | 31882 | 716K| 97 (27)| 00:00:01 | | |
|* 11 | TABLE ACCESS INMEMORY FULL | PART | 31882 | 716K| 97 (27)| 00:00:01 | | |
| 12 | JOIN FILTER USE | :BF0001 | 41M| 955M| 4928 (35)| 00:00:01 | | |
| 13 | JOIN FILTER USE | :BF0002 | 41M| 955M| 4928 (35)| 00:00:01 | | |
| 14 | JOIN FILTER USE | :BF0003 | 41M| 955M| 4928 (35)| 00:00:01 | | |
| 15 | PARTITION RANGE JOIN-FILTER| | 41M| 955M| 4928 (35)| 00:00:01 |:BF0000|:BF0000|
|* 16 | TABLE ACCESS INMEMORY FULL| LINEORDER | 41M| 955M| 4928 (35)| 00:00:01 |:BF0000|:BF0000|
----------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("L"."LO_ORDERDATE"="D"."D_DATEKEY")
5 - inmemory("D"."D_YEAR"=1997)
filter("D"."D_YEAR"=1997)
6 - access("L"."LO_SUPPKEY"="S"."S_SUPPKEY")
8 - inmemory("S"."S_REGION"='AMERICA')
filter("S"."S_REGION"='AMERICA')
9 - access("L"."LO_PARTKEY"="P"."P_PARTKEY")
11 - inmemory("P"."P_CATEGORY"='MFGR#12')
filter("P"."P_CATEGORY"='MFGR#12')
16 - inmemory(SYS_OP_BLOOM_FILTER_LIST(SYS_OP_BLOOM_FILTER(:BF0003,"L"."LO_PARTKEY"),SYS_OP_BLOOM_FILT
ER(:BF0002,"L"."LO_SUPPKEY"),SYS_OP_BLOOM_FILTER(:BF0001,"L"."LO_ORDERDATE")))
filter(SYS_OP_BLOOM_FILTER_LIST(SYS_OP_BLOOM_FILTER(:BF0003,"L"."LO_PARTKEY"),SYS_OP_BLOOM_FILTER
(:BF0002,"L"."LO_SUPPKEY"),SYS_OP_BLOOM_FILTER(:BF0001,"L"."LO_ORDERDATE")))
并行,多表联结查询。
SQL> @07_parallel_join.sql
-- 耗时
Elapsed: 00:00:00.09
-- 执行计划
--------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1464 (100)| | | | | | |
| 1 | PX COORDINATOR | | | | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10002 | 1000 | 77000 | 1464 (38)| 00:00:01 | | | Q1,02 | P->S | QC (RAND) |
| 3 | HASH GROUP BY | | 1000 | 77000 | 1464 (38)| 00:00:01 | | | Q1,02 | PCWP | |
| 4 | PX RECEIVE | | 1000 | 77000 | 1464 (38)| 00:00:01 | | | Q1,02 | PCWP | |
| 5 | PX SEND HASH | :TQ10001 | 1000 | 77000 | 1464 (38)| 00:00:01 | | | Q1,01 | P->P | HASH |
| 6 | HASH GROUP BY | | 1000 | 77000 | 1464 (38)| 00:00:01 | | | Q1,01 | PCWP | |
|* 7 | HASH JOIN | | 97986 | 7368K| 1462 (38)| 00:00:01 | | | Q1,01 | PCWP | |
| 8 | JOIN FILTER CREATE | :BF0001 | 365 | 4380 | 2 (0)| 00:00:01 | | | Q1,01 | PCWP | |
| 9 | PART JOIN FILTER CREATE | :BF0000 | 365 | 4380 | 2 (0)| 00:00:01 | | | Q1,01 | PCWP | |
| 10 | PX RECEIVE | | 365 | 4380 | 2 (0)| 00:00:01 | | | Q1,01 | PCWP | |
| 11 | PX SEND BROADCAST | :TQ10000 | 365 | 4380 | 2 (0)| 00:00:01 | | | Q1,00 | P->P | BROADCAST |
| 12 | PX BLOCK ITERATOR | | 365 | 4380 | 2 (0)| 00:00:01 | | | Q1,00 | PCWC | |
|* 13 | TABLE ACCESS INMEMORY FULL | DATE_DIM | 365 | 4380 | 2 (0)| 00:00:01 | | | Q1,00 | PCWP | |
|* 14 | HASH JOIN | | 449K| 27M| 1459 (38)| 00:00:01 | | | Q1,01 | PCWP | |
| 15 | JOIN FILTER CREATE | :BF0002 | 4102 | 73836 | 2 (0)| 00:00:01 | | | Q1,01 | PCWP | |
|* 16 | TABLE ACCESS INMEMORY FULL | SUPPLIER | 4102 | 73836 | 2 (0)| 00:00:01 | | | Q1,01 | PCWP | |
|* 17 | HASH JOIN | | 2206K| 98M| 1454 (38)| 00:00:01 | | | Q1,01 | PCWP | |
| 18 | JOIN FILTER CREATE | :BF0003 | 31738 | 712K| 27 (26)| 00:00:01 | | | Q1,01 | PCWP | |
|* 19 | TABLE ACCESS INMEMORY FULL | PART | 31738 | 712K| 27 (26)| 00:00:01 | | | Q1,01 | PCWP | |
| 20 | JOIN FILTER USE | :BF0001 | 41M| 955M| 1369 (35)| 00:00:01 | | | Q1,01 | PCWP | |
| 21 | JOIN FILTER USE | :BF0002 | 41M| 955M| 1369 (35)| 00:00:01 | | | Q1,01 | PCWP | |
| 22 | JOIN FILTER USE | :BF0003 | 41M| 955M| 1369 (35)| 00:00:01 | | | Q1,01 | PCWP | |
| 23 | PX BLOCK ITERATOR ADAPTIVE | | 41M| 955M| 1369 (35)| 00:00:01 |:BF0000|:BF0000| Q1,01 | PCWC | |
|* 24 | TABLE ACCESS INMEMORY FULL| LINEORDER | 41M| 955M| 1369 (35)| 00:00:01 |:BF0000|:BF0000| Q1,01 | PCWP | |
--------------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
7 - access("L"."LO_ORDERDATE"="D"."D_DATEKEY")
13 - inmemory(:Z>=:Z AND :Z<=:Z AND "D"."D_YEAR"=1997)
filter("D"."D_YEAR"=1997)
14 - access("L"."LO_SUPPKEY"="S"."S_SUPPKEY")
16 - inmemory("S"."S_REGION"='AMERICA')
filter("S"."S_REGION"='AMERICA')
17 - access("L"."LO_PARTKEY"="P"."P_PARTKEY")
19 - inmemory("P"."P_CATEGORY"='MFGR#12')
filter("P"."P_CATEGORY"='MFGR#12')
24 - inmemory(:Z>=:Z AND :Z<=:Z AND SYS_OP_BLOOM_FILTER_LIST(SYS_OP_BLOOM_FILTER(:BF0003,"L"."LO_PARTKEY"),SYS_OP_BLOOM_FILTER(:BF0002,"
L"."LO_SUPPKEY"),SYS_OP_BLOOM_FILTER(:BF0001,"L"."LO_ORDERDATE")))
filter(SYS_OP_BLOOM_FILTER_LIST(SYS_OP_BLOOM_FILTER(:BF0003,"L"."LO_PARTKEY"),SYS_OP_BLOOM_FILTER(:BF0002,"L"."LO_SUPPKEY"),SYS_OP_
BLOOM_FILTER(:BF0001,"L"."LO_ORDERDATE")))
Note
-----
- dynamic statistics used: dynamic sampling (level=AUTO (SYSTEM))
- automatic DOP: Computed Degree of Parallelism is 4 because of degree limit
执行计划显示启用了4并行。
Cost确实降低了。执行时间有微小提升。
串行,多表联结,使用向量转换,即Vector Group By, 之前都是Bloom filter:
SQL> @08_serial_vgb.sql
-- 耗时
Elapsed: 00:00:00.12
-- 执行计划
--------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 5043 (100)| | | |
| 1 | TEMP TABLE TRANSFORMATION | | | | | | | |
| 2 | LOAD AS SELECT (CURSOR DURATION MEMORY)| SYS_TEMP_0FD9D6649_53CF1A | | | | | | |
| 3 | HASH GROUP BY | | 1 | 16 | 2 (50)| 00:00:01 | | |
| 4 | KEY VECTOR CREATE BUFFERED | :KV0000 | 1 | 16 | 1 (0)| 00:00:01 | | |
|* 5 | TABLE ACCESS INMEMORY FULL | DATE_DIM | 365 | 4380 | 1 (0)| 00:00:01 | | |
| 6 | LOAD AS SELECT (CURSOR DURATION MEMORY)| SYS_TEMP_0FD9D6647_53CF1A | | | | | | |
| 7 | HASH GROUP BY | | 1000 | 27000 | 100 (29)| 00:00:01 | | |
| 8 | KEY VECTOR CREATE BUFFERED | :KV0001 | 1000 | 27000 | 98 (28)| 00:00:01 | | |
|* 9 | TABLE ACCESS INMEMORY FULL | PART | 31882 | 716K| 97 (27)| 00:00:01 | | |
| 10 | LOAD AS SELECT (CURSOR DURATION MEMORY)| SYS_TEMP_0FD9D6648_53CF1A | | | | | | |
| 11 | HASH GROUP BY | | 1 | 22 | 5 (40)| 00:00:01 | | |
| 12 | KEY VECTOR CREATE BUFFERED | :KV0002 | 1 | 22 | 4 (25)| 00:00:01 | | |
|* 13 | TABLE ACCESS INMEMORY FULL | SUPPLIER | 4102 | 73836 | 4 (25)| 00:00:01 | | |
| 14 | HASH GROUP BY | | 500 | 49500 | 4937 (35)| 00:00:01 | | |
|* 15 | HASH JOIN | | 500 | 49500 | 4936 (35)| 00:00:01 | | |
| 16 | VIEW | VW_VT_80F21617 | 500 | 19000 | 4929 (35)| 00:00:01 | | |
| 17 | VECTOR GROUP BY | | 500 | 18000 | 4929 (35)| 00:00:01 | | |
| 18 | HASH GROUP BY | | 500 | 18000 | 4929 (35)| 00:00:01 | | |
| 19 | KEY VECTOR USE | :KV0000 | 98430 | 3460K| 4929 (35)| 00:00:01 | | |
| 20 | KEY VECTOR USE | :KV0002 | 451K| 13M| 4929 (35)| 00:00:01 | | |
| 21 | KEY VECTOR USE | :KV0001 | 2216K| 59M| 4928 (35)| 00:00:01 | | |
| 22 | PARTITION RANGE ITERATOR | | 41M| 955M| 4928 (35)| 00:00:01 |:KV0000|:KV0000|
|* 23 | TABLE ACCESS INMEMORY FULL | LINEORDER | 41M| 955M| 4928 (35)| 00:00:01 |:KV0000|:KV0000|
| 24 | MERGE JOIN CARTESIAN | | 1000 | 61000 | 7 (0)| 00:00:01 | | |
| 25 | MERGE JOIN CARTESIAN | | 1 | 38 | 4 (0)| 00:00:01 | | |
| 26 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6649_53CF1A | 1 | 16 | 2 (0)| 00:00:01 | | |
| 27 | BUFFER SORT | | 1 | 22 | 2 (0)| 00:00:01 | | |
| 28 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6648_53CF1A | 1 | 22 | 2 (0)| 00:00:01 | | |
| 29 | BUFFER SORT | | 1000 | 23000 | 5 (0)| 00:00:01 | | |
| 30 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6647_53CF1A | 1000 | 23000 | 3 (0)| 00:00:01 | | |
--------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - inmemory("D"."D_YEAR"=1997)
filter("D"."D_YEAR"=1997)
9 - inmemory("P"."P_CATEGORY"='MFGR#12')
filter("P"."P_CATEGORY"='MFGR#12')
13 - inmemory("S"."S_REGION"='AMERICA')
filter("S"."S_REGION"='AMERICA')
15 - access("ITEM_10"=INTERNAL_FUNCTION("C0") AND "ITEM_12"=INTERNAL_FUNCTION("C0") AND "ITEM_11"=INTERNAL_FUNCTION("C0"))
23 - inmemory((SYS_OP_KEY_VECTOR_FILTER("L"."LO_PARTKEY",:KV0001) AND SYS_OP_KEY_VECTOR_FILTER("L"."LO_SUPPKEY",:KV0002)
AND SYS_OP_KEY_VECTOR_FILTER("L"."LO_ORDERDATE",:KV0000)))
filter((SYS_OP_KEY_VECTOR_FILTER("L"."LO_PARTKEY",:KV0001) AND SYS_OP_KEY_VECTOR_FILTER("L"."LO_SUPPKEY",:KV0002) AND
SYS_OP_KEY_VECTOR_FILTER("L"."LO_ORDERDATE",:KV0000)))
Note
-----
- vector transformation used for this statement
注意执行计划中的Note部分,表示使用了vector transformation。比Bloom filter快一点点。
并行,多表联结,使用向量转换:
SQL> @09_parallel_vgb.sql
SQL> alter session set parallel_degree_policy=auto;
SQL> alter session set parallel_min_time_threshold=0;
SQL>
-- 耗时
Elapsed: 00:00:00.11
-- 执行计划
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1411 (100)| | | | | | |
| 1 | TEMP TABLE TRANSFORMATION | | | | | | | | | | |
| 2 | LOAD AS SELECT (CURSOR DURATION MEMORY) | SYS_TEMP_0FD9D6655_53CF1A | | | | | | | | | |
| 3 | PX COORDINATOR | | | | | | | | | | |
| 4 | PX SEND QC (RANDOM) | :TQ10001 | 1 | 16 | 3 (34)| 00:00:01 | | | Q1,01 | P->S | QC (RAND) |
| 5 | HASH GROUP BY | | 1 | 16 | 3 (34)| 00:00:01 | | | Q1,01 | PCWP | |
| 6 | PX RECEIVE | | 1 | 16 | 2 (0)| 00:00:01 | | | Q1,01 | PCWP | |
| 7 | PX SEND HASH | :TQ10000 | 1 | 16 | 2 (0)| 00:00:01 | | | Q1,00 | P->P | HASH |
| 8 | KEY VECTOR CREATE BUFFERED | :KV0000 | 1 | 16 | 2 (0)| 00:00:01 | | | Q1,00 | PCWC | |
| 9 | PX BLOCK ITERATOR | | 365 | 4380 | 2 (0)| 00:00:01 | | | Q1,00 | PCWC | |
|* 10 | TABLE ACCESS INMEMORY FULL | DATE_DIM | 365 | 4380 | 2 (0)| 00:00:01 | | | Q1,00 | PCWP | |
| 11 | LOAD AS SELECT (CURSOR DURATION MEMORY) | SYS_TEMP_0FD9D6653_53CF1A | | | | | | | | | |
| 12 | PX COORDINATOR | | | | | | | | | | |
| 13 | PX SEND QC (RANDOM) | :TQ20001 | 1000 | 27000 | 28 (29)| 00:00:01 | | | Q2,01 | P->S | QC (RAND) |
| 14 | HASH GROUP BY | | 1000 | 27000 | 28 (29)| 00:00:01 | | | Q2,01 | PCWP | |
| 15 | PX RECEIVE | | 1000 | 27000 | 27 (26)| 00:00:01 | | | Q2,01 | PCWP | |
| 16 | PX SEND HASH | :TQ20000 | 1000 | 27000 | 27 (26)| 00:00:01 | | | Q2,00 | P->P | HASH |
| 17 | KEY VECTOR CREATE BUFFERED | :KV0001 | 1000 | 27000 | 27 (26)| 00:00:01 | | | Q2,00 | PCWC | |
| 18 | PX BLOCK ITERATOR | | 31738 | 712K| 27 (26)| 00:00:01 | | | Q2,00 | PCWC | |
|* 19 | TABLE ACCESS INMEMORY FULL | PART | 31738 | 712K| 27 (26)| 00:00:01 | | | Q2,00 | PCWP | |
| 20 | LOAD AS SELECT (CURSOR DURATION MEMORY) | SYS_TEMP_0FD9D6654_53CF1A | | | | | | | | | |
| 21 | PX COORDINATOR | | | | | | | | | | |
| 22 | PX SEND QC (RANDOM) | :TQ30001 | 1 | 22 | 3 (34)| 00:00:01 | | | Q3,01 | P->S | QC (RAND) |
| 23 | HASH GROUP BY | | 1 | 22 | 3 (34)| 00:00:01 | | | Q3,01 | PCWP | |
| 24 | PX RECEIVE | | 1 | 22 | 2 (0)| 00:00:01 | | | Q3,01 | PCWP | |
| 25 | PX SEND HASH | :TQ30000 | 1 | 22 | 2 (0)| 00:00:01 | | | Q3,00 | P->P | HASH |
| 26 | KEY VECTOR CREATE BUFFERED | :KV0002 | 1 | 22 | 2 (0)| 00:00:01 | | | Q3,00 | PCWC | |
| 27 | PX BLOCK ITERATOR | | 4102 | 73836 | 2 (0)| 00:00:01 | | | Q3,00 | PCWC | |
|* 28 | TABLE ACCESS INMEMORY FULL | SUPPLIER | 4102 | 73836 | 2 (0)| 00:00:01 | | | Q3,00 | PCWP | |
| 29 | PX COORDINATOR | | | | | | | | | | |
| 30 | PX SEND QC (RANDOM) | :TQ40003 | 500 | 49500 | 1375 (35)| 00:00:01 | | | Q4,03 | P->S | QC (RAND) |
|* 31 | HASH JOIN BUFFERED | | 500 | 49500 | 1375 (35)| 00:00:01 | | | Q4,03 | PCWP | |
| 32 | PX RECEIVE | | 500 | 38000 | 1373 (35)| 00:00:01 | | | Q4,03 | PCWP | |
| 33 | PX SEND HYBRID HASH | :TQ40001 | 500 | 38000 | 1373 (35)| 00:00:01 | | | Q4,01 | P->P | HYBRID HASH|
| 34 | STATISTICS COLLECTOR | | | | | | | | Q4,01 | PCWC | |
|* 35 | HASH JOIN | | 500 | 38000 | 1373 (35)| 00:00:01 | | | Q4,01 | PCWP | |
| 36 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6654_53CF1A | 1 | 22 | 2 (0)| 00:00:01 | | | Q4,01 | PCWP | |
|* 37 | HASH JOIN | | 500 | 27000 | 1371 (35)| 00:00:01 | | | Q4,01 | PCWP | |
| 38 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6655_53CF1A | 1 | 16 | 2 (0)| 00:00:01 | | | Q4,01 | PCWP | |
| 39 | VIEW | VW_VT_80F21617 | 500 | 19000 | 1369 (35)| 00:00:01 | | | Q4,01 | PCWP | |
| 40 | HASH GROUP BY | | 500 | 18000 | 1369 (35)| 00:00:01 | | | Q4,01 | PCWP | |
| 41 | PX RECEIVE | | 500 | 18000 | 1369 (35)| 00:00:01 | | | Q4,01 | PCWP | |
| 42 | PX SEND HASH | :TQ40000 | 500 | 18000 | 1369 (35)| 00:00:01 | | | Q4,00 | P->P | HASH |
| 43 | VECTOR GROUP BY | | 500 | 18000 | 1369 (35)| 00:00:01 | | | Q4,00 | PCWP | |
| 44 | HASH GROUP BY | | 500 | 18000 | 1369 (35)| 00:00:01 | | | Q4,00 | PCWP | |
| 45 | KEY VECTOR USE | :KV0000 | 98430 | 3460K| 1369 (35)| 00:00:01 | | | Q4,00 | PCWC | |
| 46 | KEY VECTOR USE | :KV0002 | 451K| 13M| 1369 (35)| 00:00:01 | | | Q4,00 | PCWC | |
| 47 | KEY VECTOR USE | :KV0001 | 2216K| 59M| 1369 (35)| 00:00:01 | | | Q4,00 | PCWC | |
| 48 | PX BLOCK ITERATOR | | 41M| 955M| 1369 (35)| 00:00:01 |:KV0000|:KV0000| Q4,00 | PCWC | |
|* 49 | TABLE ACCESS INMEMORY FULL| LINEORDER | 41M| 955M| 1369 (35)| 00:00:01 |:KV0000|:KV0000| Q4,00 | PCWP | |
| 50 | PX RECEIVE | | 1000 | 23000 | 2 (0)| 00:00:01 | | | Q4,03 | PCWP | |
| 51 | PX SEND HYBRID HASH | :TQ40002 | 1000 | 23000 | 2 (0)| 00:00:01 | | | Q4,02 | P->P | HYBRID HASH|
| 52 | PX BLOCK ITERATOR | | 1000 | 23000 | 2 (0)| 00:00:01 | | | Q4,02 | PCWC | |
|* 53 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6653_53CF1A | 1000 | 23000 | 2 (0)| 00:00:01 | | | Q4,02 | PCWP | |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
10 - inmemory(:Z>=:Z AND :Z<=:Z AND "D"."D_YEAR"=1997)
filter("D"."D_YEAR"=1997)
19 - inmemory(:Z>=:Z AND :Z<=:Z AND "P"."P_CATEGORY"='MFGR#12')
filter("P"."P_CATEGORY"='MFGR#12')
28 - inmemory(:Z>=:Z AND :Z<=:Z AND "S"."S_REGION"='AMERICA')
filter("S"."S_REGION"='AMERICA')
31 - access("ITEM_12"=INTERNAL_FUNCTION("C0"))
35 - access("ITEM_11"=INTERNAL_FUNCTION("C0"))
37 - access("ITEM_10"=INTERNAL_FUNCTION("C0"))
49 - inmemory(:Z>=:Z AND :Z<=:Z AND (SYS_OP_KEY_VECTOR_FILTER("L"."LO_PARTKEY",:KV0001) AND SYS_OP_KEY_VECTOR_FILTER("L"."LO_SUPPKEY",:KV0002) AND
SYS_OP_KEY_VECTOR_FILTER("L"."LO_ORDERDATE",:KV0000)))
filter((SYS_OP_KEY_VECTOR_FILTER("L"."LO_PARTKEY",:KV0001) AND SYS_OP_KEY_VECTOR_FILTER("L"."LO_SUPPKEY",:KV0002) AND
SYS_OP_KEY_VECTOR_FILTER("L"."LO_ORDERDATE",:KV0000)))
53 - access(:Z>=:Z AND :Z<=:Z)
Note
-----
- dynamic statistics used: dynamic sampling (level=AUTO (SYSTEM))
- automatic DOP: Computed Degree of Parallelism is 4 because of degree limit
- vector transformation used for this statement
执行计划Note部分显示并行和vector transformation都用了。性能提升不明显。
In-Memory Dynamic Scan,这里是通过隐含参数强制执行的:
SQL> @10_imds.sql
SQL> -- IMDS requires at least CPU_COUNT>=24 and a RESOURCE_MANAGER_PLAN
SQL> --
SQL> alter session set "_inmemory_dynamic_scans"=force;
-- 耗时
Elapsed: 00:00:00.00
-- 执行计划
----------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 4376 (100)| | | |
| 1 | SORT AGGREGATE | | 1 | 9 | | | | |
| 2 | PARTITION RANGE ALL | | 41M| 358M| 4376 (27)| 00:00:01 | 1 | 5 |
| 3 | TABLE ACCESS INMEMORY FULL| LINEORDER | 41M| 358M| 4376 (27)| 00:00:01 | 1 | 5 |
----------------------------------------------------------------------------------------------------------
-- 会话统计信息
NAME VALUE
-------------------------------------------------- --------------------
CPU used by this session 4
IM scan (dynamic) multi-threaded scans 1
IM scan (dynamic) rows 41760941
IM scan CUs columns accessed 156
IM scan CUs memcompress for query low 78
IM scan CUs pcode aggregation pushdown 156
IM scan rows 41760941
IM scan rows pcode aggregated 41760941
IM scan rows projected 7
IM scan rows valid 41760941
session logical reads 315588
session logical reads - IM 315483
session pga memory 18090288
table scans (IM) 5
14 rows selected.
注意会话统计信息中的IM scan (dynamic)
关键字。
实验 11: In-Memory ADO (Automatic Data Optimization)
ADO属于Oracle数据库生命周期管理。ADO在DBIM之前就有了。详见这个实验。
实验前,需要执行以下:
. ~/.set-env-db.sh CDB1
进入ado目录,登录数据库:
cd /home/oracle/labs/inmemory/ado
sqlplus ssb/Ora_DB4U@localhost:1521/pdb1
此实验的主要脚本执行序列如下,后面会详述:
01_ado_setup.sql
02_hm_stats.sql
03_compression_policy.sql
04_im_populated.sql
05_evaluate_policy.sql
06_part_default.sql
07_im_populated.sql
08_gen_hm_stats.sql
09_hm_stats.sql
10_evict_policy.sql
11_evaluate_policy.sql
12_ado_cleanup.sql
首先,启用ADO:
SQL> @01_ado_setup.sql
Connected.
SQL>
SQL> show parameters heat_map
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
heat_map string ON
SQL>
SQL> col name format a20;
SQL> select * from dba_ilmparameters;
NAME VALUE
-------------------- ----------
ENABLED 1
RETENTION TIME 30
JOB LIMIT 2
EXECUTION MODE 2
EXECUTION INTERVAL 15
TBS PERCENT USED 85
TBS PERCENT FREE 25
POLICY TIME 0
8 rows selected.
SQL>
SQL> exec dbms_ilm_admin.customize_ilm(dbms_ilm_admin.POLICY_TIME, dbms_ilm_admin.ILM_POLICY_IN_SECONDS);
PL/SQL procedure successfully completed.
SQL>
SQL> select * from dba_ilmparameters;
NAME VALUE
-------------------- ----------
ENABLED 1
RETENTION TIME 30
JOB LIMIT 2
EXECUTION MODE 2
EXECUTION INTERVAL 15
TBS PERCENT USED 85
TBS PERCENT FREE 25
POLICY TIME 1
8 rows selected.
查看热图(Heat Map)的信息:
SQL> @02_hm_stats.sql
Connected.
SEG SEG FULL LOOKUP NUM FULL NUM LOOKUP NUM SEG
OWNER OBJECT_NAME SUBOBJECT_NAME TRACK_TIME WRITE READ SCAN SCAN SCAN SCAN WRITE
---------- -------------------- --------------- ---------------- ---------- ---------- ---------- ---------- --------- ---------- ---------
SSB CUSTOMER 11/09/2022 10:25 NO NO YES NO 4 0 0
SSB DATE_DIM 11/09/2022 10:25 NO NO YES NO 4 0 0
SSB LINEORDER PART_1994 11/09/2022 10:25 NO NO YES NO 13 0 0
SSB LINEORDER PART_1995 11/09/2022 10:25 NO NO YES NO 13 0 0
SSB LINEORDER PART_1996 11/09/2022 10:25 NO NO YES NO 17 0 0
SSB LINEORDER PART_1997 11/09/2022 10:25 NO NO YES NO 13 0 0
SSB LINEORDER PART_1998 11/09/2022 10:25 NO NO YES NO 15 0 0
SSB PART 11/09/2022 10:25 NO NO YES NO 4 0 0
SSB SUPPLIER 11/09/2022 10:25 NO NO YES NO 4 0 0
SSB DATE_DIM 11/09/2022 11:23 NO YES YES NO 13 0 0
SSB LINEORDER PART_1994 11/09/2022 11:23 NO YES YES NO 7 0 0
SSB LINEORDER PART_1995 11/09/2022 11:23 NO YES YES NO 7 0 0
SSB LINEORDER PART_1996 11/09/2022 11:23 NO YES YES NO 7 0 0
SSB LINEORDER PART_1997 11/09/2022 11:23 NO YES YES NO 20 0 0
SSB LINEORDER PART_1998 11/09/2022 11:23 NO YES YES NO 7 0 0
SSB PART 11/09/2022 11:23 NO YES YES NO 13 0 0
SSB SUPPLIER 11/09/2022 11:23 NO YES YES NO 13 0 0
17 rows selected.
为supplier表设置压缩ILM策略,如果5天没有修改就提高压缩级:
SQL> @03_compression_policy.sql
Connected.
SQL>
SQL> alter table supplier ilm delete_all;
Table altered.
SQL> alter table supplier inmemory memcompress for query low;
Table altered.
SQL> -- exec dbms_inmemory.populate(USER, 'SUPPLIER');
SQL> select count(*) from supplier;
COUNT(*)
----------
20000
SQL> alter table supplier ilm add policy modify inmemory memcompress for capacity high after 5 days of no modification;
Table altered.
SQL>
SQL> set echo off
Hit enter ...
SQL>
SQL> select policy_name, object_owner, object_name, object_type, inherited_from, enabled, deleted
2 from user_ilmobjects;
POLICY_NAM OBJECT_OWN OBJECT_NAME OBJECT_TYP INHERITED_FROM ENABLED DELETED
---------- ---------- -------------------- ---------- -------------------- -------- --------
P1 SSB SUPPLIER TABLE POLICY NOT INHERITED YES NO
SQL>
SQL> pause Hit enter ...
Hit enter ...
SQL>
SQL> select policy_name, action_type, scope, compression_level, condition_type, condition_days,
2 policy_subtype, action_clause
3 from user_ilmdatamovementpolicies;
POLICY_NAM ACTION_TYPE SCOPE COMPRESSION_LEVEL CONDITION_TYPE CONDITION_DAYS POLICY_SUB
---------- ----------- ------- ------------------------------ ---------------------- -------------- ----------
ACTION_CLAUSE
--------------------------------------------------------------------------------
P1 COMPRESSION SEGMENT MEMCOMPRESS FOR CAPACITY HIGH LAST MODIFICATION TIME 5 INMEMORY
inmemory memcompress for capacity high
查看发布状态:
SQL> @04_im_populated.sql
Connected.
SQL>
SQL> -- Query the view v$IM_SEGMENTS to shows what objects are in the column store
SQL> -- and how much of the objects were populated. When the BYTES_NOT_POPULATED is 0
SQL> -- it indicates the entire table was populated.
SQL>
SQL> select owner, segment_name, partition_name, populate_status, bytes,
2 inmemory_size, bytes_not_populated
3 from v$im_segments
4 order by owner, segment_name, partition_name;
In-Memory Bytes
OWNER SEGMENT_NAME PARTITION_NAME POPULATE_STATUS Disk Size Size Not Populated
---------- -------------------- --------------- --------------- ---------------- ---------------- ----------------
SSB CUSTOMER COMPLETED 24,928,256 23,199,744 0
SSB DATE_DIM COMPLETED 122,880 1,179,648 0
SSB LINEORDER PART_1994 COMPLETED 563,609,600 478,281,728 0
SSB LINEORDER PART_1995 COMPLETED 563,470,336 478,281,728 0
SSB LINEORDER PART_1996 COMPLETED 565,018,624 480,378,880 0
SSB LINEORDER PART_1997 COMPLETED 563,322,880 479,330,304 0
SSB LINEORDER PART_1998 COMPLETED 329,015,296 280,690,688 0
SSB PART COMPLETED 56,893,440 16,973,824 0
SSB SUPPLIER COMPLETED 1,769,472 2,228,224 0
9 rows selected.
执行ILM策略,发现表的压缩级确实变了。
SQL> @05_evaluate_policy.sql
Connected.
-- 将热图统计信息从内存冲刷到磁盘
SQL> exec dbms_ilm.flush_all_segments;
PL/SQL procedure successfully completed.
SQL>
SQL> select table_name, inmemory, inmemory_priority, inmemory_compression
2 from user_tables where table_name = 'SUPPLIER';
TABLE_NAME INMEMORY priority compression
--------------- -------- -------- -----------------
SUPPLIER ENABLED NONE FOR QUERY LOW
SQL>
SQL> set echo off
In-Memory Bytes
OWNER SEGMENT_NAME PARTITION_NAME POPULATE_STATUS Disk Size Size Not Populated
---------- -------------------- --------------- --------------- ---------------- ---------------- ----------------
SSB CUSTOMER COMPLETED 24,928,256 23,199,744 0
SSB DATE_DIM COMPLETED 122,880 1,179,648 0
SSB LINEORDER PART_1994 COMPLETED 563,609,600 478,281,728 0
SSB LINEORDER PART_1995 COMPLETED 563,470,336 478,281,728 0
SSB LINEORDER PART_1996 COMPLETED 565,018,624 480,378,880 0
SSB LINEORDER PART_1997 COMPLETED 563,322,880 479,330,304 0
SSB LINEORDER PART_1998 COMPLETED 329,015,296 280,690,688 0
SSB PART COMPLETED 56,893,440 16,973,824 0
SSB SUPPLIER COMPLETED 1,769,472 2,228,224 0
9 rows selected.
Hit enter ...
SQL> col policy_name new_value pnam format a10;
SQL> select policy_name from user_ilmobjects
2 where object_name = 'SUPPLIER' and object_type = 'TABLE';
POLICY_NAM
----------
P1
-- 默认是在维护窗口评估的,但这里我们主动进行评估
SQL>
SQL> variable v_execid number;
SQL>
SQL> declare
2 v_execid number;
3 begin
4 DBMS_ILM.EXECUTE_ILM (
5 owner => 'SSB',
6 object_name => 'SUPPLIER',
7 task_id => :v_execid,
8 policy_name => '&pnam',
9 execution_mode => dbms_ilm.ilm_execution_online);
10 end;
11 /
old 8: policy_name => '&pnam',
new 8: policy_name => 'P1',
PL/SQL procedure successfully completed.
SQL> set echo off
Hit enter ...
TASK_ID STATE START_TIME COMPLETION_TIME
---------- --------- ------------------------------ ------------------------------
1 COMPLETED 09-NOV-22 11.27.07.107466 AM 09-NOV-22 11.27.09.177734 AM
TASK_ID POLICY_NAM SELECTED_FOR_EXECUTION
---------- ---------- ------------------------------------------
1 P1 SELECTED FOR EXECUTION
TABLE_NAME INMEMORY priority compression
--------------- -------- -------- -----------------
SUPPLIER ENABLED NONE FOR CAPACITY HIGH
In-Memory Bytes
OWNER SEGMENT_NAME PARTITION_NAME POPULATE_STATUS Disk Size Size Not Populated
---------- -------------------- --------------- --------------- ---------------- ---------------- ----------------
SSB CUSTOMER COMPLETED 24,928,256 23,199,744 0
SSB DATE_DIM COMPLETED 122,880 1,179,648 0
SSB LINEORDER PART_1994 COMPLETED 563,609,600 478,281,728 0
SSB LINEORDER PART_1995 COMPLETED 563,470,336 478,281,728 0
SSB LINEORDER PART_1996 COMPLETED 565,018,624 480,378,880 0
SSB LINEORDER PART_1997 COMPLETED 563,322,880 479,330,304 0
SSB LINEORDER PART_1998 COMPLETED 329,015,296 280,690,688 0
SSB PART COMPLETED 56,893,440 16,973,824 0
SSB SUPPLIER COMPLETED 1,769,472 1,179,648 0
9 rows selected.
发布LINEORDER表,这是一个RANGE分区表:
SQL> @06_part_default.sql
Connected.
SQL> alter table lineorder inmemory;
Table altered.
SQL> set echo off
SQL> select pt.TABLE_NAME, pt.PARTITIONING_TYPE, pk.column_name, pt.PARTITION_COUNT, pt.STATUS, pt.DEF_INMEMORY
2 from user_part_tables pt, user_part_key_columns pk
3 where pt.table_name = pk.name
4 and pt.table_name = 'LINEORDER';
TABLE_NAME PART TYPE PART KEY COUNT STATUS DEF_INMEMORY
---------- --------------- --------------- ------ ---------- --------------------
LINEORDER RANGE LO_ORDERDATE 5 VALID ENABLED
SQL>
SQL> exec dbms_inmemory.populate(USER, 'LINEORDER');
PL/SQL procedure successfully completed.
确认已完全发布:
SQL> @07_im_populated.sql
Connected.
SQL>
SQL> -- Query the view v$IM_SEGMENTS to shows what objects are in the column store
SQL> -- and how much of the objects were populated. When the BYTES_NOT_POPULATED is 0
SQL> -- it indicates the entire table was populated.
SQL>
SQL> select owner, segment_name, partition_name, populate_status, bytes,
2 inmemory_size, bytes_not_populated
3 from v$im_segments
4 order by owner, segment_name, partition_name;
In-Memory Bytes
OWNER SEGMENT_NAME PARTITION_NAME POPULATE_STATUS Disk Size Size Not Populated
---------- -------------------- --------------- --------------- ---------------- ---------------- ----------------
SSB CUSTOMER COMPLETED 24,928,256 23,199,744 0
SSB DATE_DIM COMPLETED 122,880 1,179,648 0
SSB LINEORDER PART_1994 COMPLETED 563,609,600 478,281,728 0
SSB LINEORDER PART_1995 COMPLETED 563,470,336 478,281,728 0
SSB LINEORDER PART_1996 COMPLETED 565,018,624 480,378,880 0
SSB LINEORDER PART_1997 COMPLETED 563,322,880 479,330,304 0
SSB LINEORDER PART_1998 COMPLETED 329,015,296 280,690,688 0
SSB PART COMPLETED 56,893,440 16,973,824 0
SSB SUPPLIER COMPLETED 1,769,472 1,179,648 0
9 rows selected.
执行针对lineorder表各分区的查询,以产生热图统计信息:
SQL> @08_gen_hm_stats.sql
Connected.
j: 1
data between: 01/01/1995 and 12/31/1995
Query count h: 1 for 01/01/1995
Query count h: 2 for 01/01/1995
Query count h: 3 for 01/01/1995
Query count h: 4 for 01/01/1995
Query count h: 5 for 01/01/1995
j: 2
data between: 01/01/1996 and 12/31/1996
Query count h: 1 for 01/01/1996
Query count h: 2 for 01/01/1996
Query count h: 3 for 01/01/1996
Query count h: 4 for 01/01/1996
Query count h: 5 for 01/01/1996
Query count h: 6 for 01/01/1996
Query count h: 7 for 01/01/1996
Query count h: 8 for 01/01/1996
Query count h: 9 for 01/01/1996
Query count h: 10 for 01/01/1996
j: 3
data between: 01/01/1997 and 12/31/1997
Query count h: 1 for 01/01/1997
Query count h: 2 for 01/01/1997
Query count h: 3 for 01/01/1997
Query count h: 4 for 01/01/1997
Query count h: 5 for 01/01/1997
Query count h: 6 for 01/01/1997
Query count h: 7 for 01/01/1997
Query count h: 8 for 01/01/1997
Query count h: 9 for 01/01/1997
Query count h: 10 for 01/01/1997
Query count h: 11 for 01/01/1997
Query count h: 12 for 01/01/1997
Query count h: 13 for 01/01/1997
Query count h: 14 for 01/01/1997
Query count h: 15 for 01/01/1997
j: 4
data between: 01/01/1998 and 12/31/1998
Query count h: 1 for 01/01/1998
Query count h: 2 for 01/01/1998
Query count h: 3 for 01/01/1998
Query count h: 4 for 01/01/1998
Query count h: 5 for 01/01/1998
Query count h: 6 for 01/01/1998
Query count h: 7 for 01/01/1998
Query count h: 8 for 01/01/1998
Query count h: 9 for 01/01/1998
Query count h: 10 for 01/01/1998
Query count h: 11 for 01/01/1998
Query count h: 12 for 01/01/1998
Query count h: 13 for 01/01/1998
Query count h: 14 for 01/01/1998
Query count h: 15 for 01/01/1998
Query count h: 16 for 01/01/1998
Query count h: 17 for 01/01/1998
Query count h: 18 for 01/01/1998
Query count h: 19 for 01/01/1998
Query count h: 20 for 01/01/1998
PL/SQL procedure successfully completed.
SQL> exec dbms_ilm.flush_all_segments;
PL/SQL procedure successfully completed.
这个生成查询的脚本如下,唯独没有查询1994年的分区:
declare
v_part_date date := to_date('01/01/1995','MM/DD/YYYY');
v_part_count number := 4;
v_increment pls_integer := 12;
v_monthcnt pls_integer := 0;
v_query_cnt pls_integer := 5;
v_totprice number;
begin
for j in 1..v_part_count loop
dbms_output.put_line('j: ' || j);
dbms_output.put_line('data between: ' || to_char(add_months( v_part_date, v_monthcnt), 'MM/DD/YYYY') || ' and ' ||
to_char( add_months( v_part_date + 30, v_monthcnt + 11), 'MM/DD/YYYY') );
--
for h in 1..(j * v_query_cnt) loop
dbms_output.put_line('Query count h: ' || h || ' for '|| to_char( add_months( v_part_date, v_monthcnt ), 'MM/DD/YYYY' ) );
select sum(lo_ordtotalprice) into v_totprice
from lineorder lo
where lo_orderdate between add_months( v_part_date, v_monthcnt ) and add_months( v_part_date + 30, v_monthcnt + 11 );
end loop;
--
v_monthcnt := v_monthcnt + v_increment;
end loop;
end;
/
--
set echo on
exec dbms_ilm.flush_all_segments;
set echo off
查看热图:
SQL> @09_hm_stats.sql
Connected.
SEG SEG FULL LOOKUP NUM FULL NUM LOOKUP NUM SEG
OWNER OBJECT_NAME SUBOBJECT_NAME TRACK_TIME WRITE READ SCAN SCAN SCAN SCAN WRITE
---------- -------------------- --------------- ---------------- ---------- ---------- ---------- ---------- --------- ---------- ---------
SSB CUSTOMER 11/09/2022 10:25 NO NO YES NO 4 0 0
SSB DATE_DIM 11/09/2022 10:25 NO NO YES NO 17 0 0
SSB LINEORDER PART_1994 11/09/2022 10:25 NO NO YES NO 20 0 0
SSB LINEORDER PART_1995 11/09/2022 10:25 NO NO YES NO 21 0 0
SSB LINEORDER PART_1996 11/09/2022 10:25 NO NO YES NO 25 0 0
SSB LINEORDER PART_1997 11/09/2022 10:25 NO NO YES NO 34 0 0
SSB LINEORDER PART_1998 11/09/2022 10:25 NO NO YES NO 23 0 0
SSB PART 11/09/2022 10:25 NO NO YES NO 17 0 0
SSB SUPPLIER 11/09/2022 10:25 NO NO YES NO 18 0 0
SSB LINEORDER PART_1995 11/09/2022 11:41 NO YES YES NO 4 0 0
SSB LINEORDER PART_1996 11/09/2022 11:41 NO YES YES NO 9 0 0
SSB LINEORDER PART_1997 11/09/2022 11:41 NO YES YES NO 14 0 0
SSB LINEORDER PART_1998 11/09/2022 11:41 NO YES YES NO 19 0 0
13 rows selected.
为lineorder表定义evict策略,分区LINEORDER(PART_1994)被从IMCS中清除。
SQL> @10_evict_policy.sql
Connected.
SQL>
SQL> -- This example assumes that the LINEORDER partition PART_1994 has not been accessed in the last 30 seconds
SQL>
SQL> alter table lineorder ilm delete_all;
Table altered.
SQL> --
SQL> -- NOTE: This policy uses 30 days to represent 30 seconds
SQL> --
SQL> alter table lineorder ilm add policy no inmemory after 30 days of no access;
Table altered.
SQL>
SQL> set echo off
Hit enter ...
SQL>
SQL> select policy_name, object_owner, object_name, object_type, inherited_from, enabled, deleted
2 from user_ilmobjects;
POLICY_NAME OWNER OBJECT_NAME OBJECT_TYPE INHERITED_FROM ENABLED DELETED
----------- ---------- --------------- --------------- -------------------- -------- --------
P1 SSB SUPPLIER TABLE POLICY NOT INHERITED NO NO
P21 SSB LINEORDER TABLE POLICY NOT INHERITED YES NO
P21 SSB LINEORDER TABLE PARTITION TABLE YES NO
P21 SSB LINEORDER TABLE PARTITION TABLE YES NO
P21 SSB LINEORDER TABLE PARTITION TABLE YES NO
P21 SSB LINEORDER TABLE PARTITION TABLE YES NO
P21 SSB LINEORDER TABLE PARTITION TABLE YES NO
7 rows selected.
SQL>
SQL> pause Hit enter ...
Hit enter ...
SQL>
SQL> select policy_name, action_type, scope, compression_level, condition_type, condition_days,
2 policy_subtype, action_clause
3 from user_ilmdatamovementpolicies;
POLICY_NAME ACTION_TYPE SCOPE COMPRESSION_LEVEL CONDITION_TYPE CONDITION_DAYS POLICY_SUB ACTION_CLAUSE
----------- ----------- ------- ------------------------------ ---------------------- -------------- ---------- --------------------
P1 COMPRESSION SEGMENT MEMCOMPRESS FOR CAPACITY HIGH LAST MODIFICATION TIME 5 INMEMORY inmemory memcompress
for capacity high
P21 EVICT SEGMENT LAST ACCESS TIME 30 INMEMORY no inmemory
评估evict策略:
SQL> @11_evaluate_policy.sql
Connected.
In-Memory Bytes
OWNER SEGMENT_NAME PARTITION_NAME POPULATE_STATUS Disk Size Size Not Populated
---------- -------------------- --------------- --------------- ---------------- ---------------- ----------------
SSB CUSTOMER COMPLETED 24,928,256 23,199,744 0
SSB DATE_DIM COMPLETED 122,880 1,179,648 0
SSB LINEORDER PART_1994 COMPLETED 563,609,600 478,281,728 0
SSB LINEORDER PART_1995 COMPLETED 563,470,336 478,281,728 0
SSB LINEORDER PART_1996 COMPLETED 565,018,624 480,378,880 0
SSB LINEORDER PART_1997 COMPLETED 563,322,880 479,330,304 0
SSB LINEORDER PART_1998 COMPLETED 329,015,296 280,690,688 0
SSB PART COMPLETED 56,893,440 16,973,824 0
SSB SUPPLIER COMPLETED 1,769,472 1,179,648 0
9 rows selected.
Hit enter ...
POLICY_NAM
----------
P21
SQL>
SQL> variable v_execid number;
SQL>
SQL> declare
2 v_execid number;
3 begin
4 DBMS_ILM.EXECUTE_ILM (
5 owner => 'SSB',
6 object_name => 'LINEORDER',
7 task_id => :v_execid,
8 policy_name => '&pnam',
9 execution_mode => dbms_ilm.ilm_execution_online);
10 end;
11 /
old 8: policy_name => '&pnam',
new 8: policy_name => 'P21',
PL/SQL procedure successfully completed.
SQL> set echo off
Hit enter ...
TASK_ID STATE START_TIME COMPLETION_TIME
---------- --------- ------------------------------ ------------------------------
2 COMPLETED 09-NOV-22 11.46.09.099598 AM 09-NOV-22 11.46.09.329048 AM
TASK_ID POLICY_NAM SELECTED_FOR_EXECUTION
---------- ---------- ------------------------------------------
2 P21 SELECTED FOR EXECUTION
以上是关于Oracle 21版Database In-Memory LivaLabs实验(下)的主要内容,如果未能解决你的问题,请参考以下文章
Oracle 21版Database In-Memory LivaLabs实验(下)
Oracle 21版Database In-Memory LivaLabs实验(下)
Oracle Database 12c 第 1 版 与Oracle Database 11g 第 2 版 有啥区别 啊!???
[译] Oracle Database 21c 中的 Attention 日志
[译] Data Guard:Oracle Database 21c 中的 PREPARE DATABASE FOR DATA GUARD 命令