Skip to content

Commit 171a4e6

Browse files
Add files via upload
1 parent 9a7d1d8 commit 171a4e6

File tree

5 files changed

+336
-0
lines changed

5 files changed

+336
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
-- this script
2+
-- (re)creates credentials
3+
-- (re)creates non-partitioned ORDERS and ORDER_ITEMS table
4+
-- loads data to above table from object storage by executing DBMS_CLOUD.COPY_DATA procedure
5+
-- creates external tables with exactly the same data
6+
7+
8+
alter session set nls_language=american;
9+
alter session set nls_territory=america;
10+
alter session set nls_date_format='YYYY-MM-DD';
11+
alter session set nls_timestamp_format='YYYY-MM-DD';
12+
13+
drop table orders cascade constraints;
14+
drop table order_items cascade constraints;
15+
16+
create table orders
17+
( ORDER_ID number(10),
18+
ORDER_DATE timestamp(9),
19+
ORDER_MODE varchar2(30),
20+
CUSTOMER_ID number(10),
21+
ORDER_STATUS number(10),
22+
ORDER_TOTAL number(10,2),
23+
SALES_REP_ID number(10),
24+
PROMOTION_ID number(10) );
25+
26+
create table order_items
27+
( ORDER_ID number(10),
28+
LINE_ITEM_ID number(10),
29+
PRODUCT_ID number(10),
30+
UNIT_PRICE number(10,2),
31+
QUANTITY number(10) );
32+
33+
begin
34+
dbms_credential.drop_credential(credential_name=>'DBMS_CLOUD_CREDENTIAL');
35+
end;
36+
/
37+
38+
begin
39+
dbms_credential.create_credential(credential_name=>'DBMS_CLOUD_CREDENTIAL',
40+
username=>'<tenancy_user_name>',
41+
password=>'<token>');
42+
end;
43+
/
44+
45+
select *
46+
from dbms_cloud.list_objects(
47+
credential_name => 'DBMS_CLOUD_CREDENTIAL',
48+
location_uri => 'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/');
49+
50+
begin
51+
dbms_cloud.copy_data(
52+
table_name =>'ORDERS',
53+
credential_name =>'DBMS_CLOUD_CREDENTIAL',
54+
file_uri_list =>'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/orders.dat',
55+
format => json_object('ignoremissingcolumns' value 'true',
56+
'removequotes' value 'true',
57+
'skipheaders' value '1',
58+
'delimiter' value ';',
59+
'timestampformat' value 'YYYY-MM-DD')
60+
);
61+
end;
62+
/
63+
64+
begin
65+
dbms_cloud.copy_data(
66+
table_name =>'ORDER_ITEMS',
67+
credential_name =>'DBMS_CLOUD_CREDENTIAL',
68+
file_uri_list =>'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/order_items.dat',
69+
format => json_object('ignoremissingcolumns' value 'true',
70+
'removequotes' value 'true',
71+
'skipheaders' value '1',
72+
'delimiter' value ';',
73+
'timestampformat' value 'YYYY-MM-DD')
74+
);
75+
end;
76+
/
77+
78+
drop table orders_ext;
79+
drop table order_items_ext;
80+
81+
begin
82+
dbms_cloud.create_external_table(
83+
table_name => 'ORDERS_EXT',
84+
credential_name => 'DBMS_CLOUD_CREDENTIAL',
85+
file_uri_list => 'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/orders.dat',
86+
column_list => 'ORDER_ID number(10),
87+
ORDER_DATE timestamp(9),
88+
ORDER_MODE varchar2(30),
89+
CUSTOMER_ID number(10),
90+
ORDER_STATUS number(10),
91+
ORDER_TOTAL number(10,2),
92+
SALES_REP_ID number(10),
93+
PROMOTION_ID number(10)',
94+
format => json_object('ignoremissingcolumns' value 'true',
95+
'removequotes' value 'true',
96+
'skipheaders' value '1',
97+
'delimiter' value ';',
98+
'timestampformat' value 'YYYY-MM-DD')
99+
);
100+
end;
101+
/
102+
103+
begin
104+
dbms_cloud.validate_external_table('orders_ext');
105+
end;
106+
/
107+
108+
begin
109+
dbms_cloud.create_external_table(
110+
table_name => 'ORDER_ITEMS_EXT',
111+
credential_name => 'DBMS_CLOUD_CREDENTIAL',
112+
file_uri_list => 'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/order_items.dat',
113+
column_list => 'ORDER_ID number(10),
114+
LINE_ITEM_ID number(10),
115+
PRODUCT_ID number(10),
116+
UNIT_PRICE number(10,2),
117+
QUANTITY number(10)',
118+
format => json_object('ignoremissingcolumns' value 'true',
119+
'removequotes' value 'true',
120+
'skipheaders' value '1',
121+
'delimiter' value ';',
122+
'timestampformat' value 'YYYY-MM-DD')
123+
);
124+
end;
125+
/
126+
127+
begin
128+
dbms_cloud.validate_external_table('order_items_ext');
129+
end;
130+
/
131+
132+
set timing on
133+
134+
prompt "calculating number of rows in ORDERS table"
135+
select count(*) from orders;
136+
137+
prompt "calculating number of rows in ORDERS_EXT table"
138+
select count(*) from orders_ext;
139+
140+
prompt "calculating number of rows in ORDER_ITEMS table"
141+
select count(*) from order_items;
142+
143+
prompt "calculating number of rows in ORDER_ITEMS_EXT table"
144+
select count(*) from order_items_ext;
145+
146+
set timing off
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- this script
2+
-- presents differences in execution plans end statistisc for
3+
-- queries reading data from internal and external tables
4+
5+
alter session set nls_language=american;
6+
alter session set nls_territory=america;
7+
alter session set nls_date_format='YYYY-MM-DD';
8+
alter session set nls_timestamp_format='YYYY-MM-DD';
9+
10+
set autotrace on
11+
12+
select count(*)
13+
from ORDERS;
14+
15+
select count(*)
16+
from ORDERS_EXT;
17+
18+
select count(*)
19+
from ORDER_ITEMS;
20+
21+
select count(*)
22+
from ORDER_ITEMS_EXT;
23+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- this script
2+
-- presents differences in execution plans end statistisc for
3+
-- queries reading data from internal and external partitions
4+
5+
alter session set nls_language=american;
6+
alter session set nls_territory=america;
7+
alter session set nls_date_format='YYYY-MM-DD';
8+
alter session set nls_timestamp_format='YYYY-MM-DD';
9+
10+
set autotrace on
11+
12+
select count(*)
13+
from ORDERS_HPART
14+
where order_id < 1500000;
15+
16+
select count(*)
17+
from ORDERS_HPART
18+
where order_id >= 1500000;
19+
20+
select count(*)
21+
from ORDER_ITEMS_HPART
22+
where order_id < 1500000;
23+
24+
select count(*)
25+
from ORDER_ITEMS_HPART
26+
where order_id >= 1500000;
27+

0 commit comments

Comments
 (0)