1
+ -- this script
2
+ -- (re)creates partitioned versions of ORDERS and ORDER_ITEMS tables
3
+ -- (re)creates hybrid partitioned versions of ORDERS and ORDER_ITEMS tables
4
+ -- loads data to both sets of tables using tables created in lab01.sql
5
+ -- compares the performance of queries executed on internal and hybrid partitioned tables
6
+
7
+ alter session set nls_language= american;
8
+ alter session set nls_territory= america;
9
+ alter session set nls_date_format= ' YYYY-MM-DD' ;
10
+ alter session set nls_timestamp_format= ' YYYY-MM-DD' ;
11
+
12
+ drop table orders_part cascade constraints;
13
+ drop table order_items_part cascade constraints;
14
+
15
+ create table orders_part
16
+ partition by range(order_id)
17
+ ( partition o_p01 values less than (250000 ),
18
+ partition o_p02 values less than (500000 ),
19
+ partition o_p03 values less than (750000 ),
20
+ partition o_p04 values less than (1000000 ),
21
+ partition o_p05 values less than (1250000 ),
22
+ partition o_p06 values less than (1500000 ),
23
+ partition o_p07 values less than (1750000 ),
24
+ partition o_p08 values less than (maxvalue))
25
+ as select * from orders;
26
+
27
+ create table order_items_part
28
+ partition by range(order_id)
29
+ ( partition oi_p01 values less than (250000 ),
30
+ partition oi_p02 values less than (500000 ),
31
+ partition oi_p03 values less than (750000 ),
32
+ partition oi_p04 values less than (1000000 ),
33
+ partition oi_p05 values less than (1250000 ),
34
+ partition oi_p06 values less than (1500000 ),
35
+ partition oi_p07 values less than (1750000 ),
36
+ partition oi_p08 values less than (maxvalue))
37
+ as select * from order_items;
38
+
39
+ drop table orders_hpart cascade constraints;
40
+ drop table order_items_hpart cascade constraints;
41
+
42
+ begin
43
+ dbms_cloud .create_hybrid_part_table (
44
+ table_name => ' ORDERS_HPART' ,
45
+ credential_name => ' DBMS_CLOUD_CREDENTIAL' ,
46
+ format => json_object(' ignoremissingcolumns' value ' true' ,
47
+ ' removequotes' value ' true' ,
48
+ ' skipheaders' value ' 1' ,
49
+ ' delimiter' value ' ;' ,
50
+ ' timestampformat' value ' YYYY-MM-DD' ),
51
+ column_list => ' ORDER_ID number(10),
52
+ ORDER_DATE timestamp(9),
53
+ ORDER_MODE varchar2(30),
54
+ CUSTOMER_ID number(10),
55
+ ORDER_STATUS number(10),
56
+ ORDER_TOTAL number(10,2),
57
+ SALES_REP_ID number(10),
58
+ PROMOTION_ID number(10)' ,
59
+ partitioning_clause => ' partition by range (order_id) (
60
+ partition o_hp01 values less than (250000),
61
+ partition o_hp02 values less than (500000),
62
+ partition o_hp03 values less than (750000),
63
+ partition o_hp04 values less than (1000000),
64
+ partition o_hp05 values less than (1250000),
65
+ partition o_hp06 values less than (1500000),
66
+ partition o_hp07 values less than (1750000) external location (
67
+ ' ' https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/orders_p07.dat' ' ),
68
+ partition o_hp08 values less than (maxvalue) external location (
69
+ ' ' https://https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/orders_p08.dat' ' )
70
+ )'
71
+ );
72
+ end;
73
+ /
74
+
75
+ begin
76
+ dbms_cloud .validate_external_table (' orders_hpart' );
77
+ end;
78
+ /
79
+
80
+ begin
81
+ dbms_cloud .create_hybrid_part_table (
82
+ table_name => ' order_items_hpart' ,
83
+ credential_name => ' DBMS_CLOUD_CREDENTIAL' ,
84
+ format => json_object(' ignoremissingcolumns' value ' true' ,
85
+ ' removequotes' value ' true' ,
86
+ ' skipheaders' value ' 1' ,
87
+ ' delimiter' value ' ;' ),
88
+ column_list => ' ORDER_ID number(10),
89
+ LINE_ITEM_ID number(10),
90
+ PRODUCT_ID number(10),
91
+ UNIT_PRICE number(10,2),
92
+ QUANTITY number(10)' ,
93
+ partitioning_clause => ' partition by range (order_id) (
94
+ partition oi_hp01 values less than (250000),
95
+ partition oi_hp02 values less than (500000),
96
+ partition oi_hp03 values less than (750000),
97
+ partition oi_hp04 values less than (1000000),
98
+ partition oi_hp05 values less than (1250000),
99
+ partition oi_hp06 values less than (1500000),
100
+ partition oi_hp07 values less than (1750000) external location (
101
+ ' ' https://https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/order_items_p07.dat' ' ),
102
+ partition oi_hp08 values less than (maxvalue) external location (
103
+ ' ' https://https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/order_items_p08.dat' ' )
104
+ )'
105
+ );
106
+ end;
107
+ /
108
+
109
+ begin
110
+ dbms_cloud .validate_external_table (' order_items_hpart' );
111
+ end;
112
+ /
113
+
114
+ insert into orders_hpart
115
+ select *
116
+ from ORDERS
117
+ where order_id < 1500000 ;
118
+
119
+ insert into order_items_hpart
120
+ select *
121
+ from ORDER_ITEMS
122
+ where order_id < 1500000 ;
123
+
124
+ commit ;
125
+
126
+ set timing on
127
+
128
+ prompt " calculating number of rows in ORDERS_PART table"
129
+ select count (* ) from orders_part;
130
+
131
+ prompt " calculating number of rows in ORDERS_HPART table"
132
+ select count (* ) from orders_hpart;
133
+
134
+ prompt " calculating number of rows in ORDER_ITEMS_PART table"
135
+ select count (* ) from order_items_part;
136
+
137
+ prompt " calculating number of rows in ORDER_ITEMS_HPART table"
138
+ select count (* ) from order_items_HPART;
139
+
140
+ set timing off
0 commit comments