Skip to content

Commit 26fe165

Browse files
authored
Initial DRA workshop materials (#375)
* initial load of data for DRA workshop Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com>
1 parent f4628c4 commit 26fe165

12 files changed

+516
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
alter table tableset_tables
5+
add constraint pk primary key ( table_name );
6+
7+
alter table table_map
8+
add constraint t1fk foreign key ( table1 )
9+
references tableset_tables ( table_name );
10+
11+
alter table table_map
12+
add constraint t2fk foreign key ( table2 )
13+
references tableset_tables ( table_name );
14+
15+
alter table table_map
16+
add constraint pk2 primary key ( table1, table2 );
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
create or replace procedure compute_affinity_tkdra as
5+
cursor c is
6+
select table_name, schema from tableset_tables;
7+
tblnm varchar2(128);
8+
ins_sql varchar2(4000);
9+
upd_sql varchar2(4000);
10+
begin
11+
for r in c loop
12+
ins_sql:= q'{
13+
insert into tkdradata.table_map
14+
( table_set_name
15+
, table1
16+
, schema1
17+
, table2
18+
, schema2
19+
, join_count
20+
, join_executions
21+
, static_coefficient
22+
, dynamic_coefficient
23+
, total_affinity)
24+
select
25+
'tkdradata' table_set_name,
26+
tbl1,
27+
'tkdradata',
28+
tbl2,
29+
'tkdradata',
30+
join_count,
31+
join_executions,
32+
round(join_count/(all_sql-join_count),5) static_coefficient,
33+
round(join_executions/(all_executions-join_executions),5) dynamic_coefficient,
34+
(round(join_count/(all_sql-join_count),5)*0.5 +
35+
round(join_executions/(all_executions-join_executions),5)*0.5) total_affinity
36+
from (
37+
select
38+
v2.tbl1,
39+
v2.tbl2,
40+
(select sum(total_sql)
41+
from tableset_tables
42+
where table_name=v2.tbl1
43+
or table_name=v2.tbl2 ) all_sql,
44+
(select sum(total_executions)
45+
from tableset_tables
46+
where table_name=v2.tbl1
47+
or table_name=v2.tbl2 ) all_executions,
48+
v2.join_count,
49+
v2.join_executions
50+
from (
51+
select
52+
v1.tbl1,
53+
v1.tbl2,
54+
count(distinct v1.sql_id) join_count,
55+
sum(v1.executions) join_executions
56+
from (
57+
select distinct
58+
v.tbl1,
59+
case when v.operation='INDEX' then v.TABLE_NAME
60+
when v.operation='TABLE ACCESS' then v.tbl2
61+
else NULL end tbl2,
62+
sql_id,
63+
executions
64+
from (
65+
select
66+
'}'||r.table_name||q'{' tbl1,
67+
s.object_name tbl2,
68+
i.table_name table_name,
69+
sql_id,
70+
operation,
71+
executions
72+
from dba_sqlset_plans s, all_indexes i
73+
where sqlset_name='tkdradata'
74+
and object_owner=upper('tkdradata')
75+
and s.object_name = i.index_name(+)
76+
and sql_id in (
77+
select distinct sql_id
78+
from dba_sqlset_plans
79+
where sqlset_name='tkdradata'
80+
and object_name='}'||r.table_name||q'{'
81+
and object_owner=upper('tkdradata')
82+
)
83+
) v
84+
) v1
85+
group by v1.tbl1, v1.tbl2
86+
having v1.tbl2 is not null
87+
and v1.tbl1 <> v1.tbl2
88+
) v2
89+
)
90+
}';
91+
execute immediate ins_sql;
92+
93+
upd_sql:= q'{
94+
update tkdradata.tableset_tables
95+
set tables_joined=(select count(distinct table_name)
96+
from (
97+
select
98+
'tkdradata' table_set_name,
99+
case when v.operation='INDEX' then v.TABLE_NAME
100+
when v.operation='TABLE ACCESS' then v.object_name
101+
else NULL end table_name,
102+
v.object_owner as table_owner,
103+
v.sql_id,
104+
v.executions
105+
from (
106+
select
107+
p.object_name,
108+
p.operation,
109+
p.object_owner,
110+
p.sql_id,
111+
p.executions,
112+
i.table_name
113+
from dba_sqlset_plans p, all_indexes i
114+
where p.object_name=i.index_name(+)
115+
and sqlset_name='tkdradata'
116+
and sql_id in (
117+
select sql_id
118+
from tableset_sql
119+
where table_name='}'||r.table_name||q'{')
120+
and object_owner = upper('tkdradata')
121+
) v
122+
)
123+
) where table_name ='}' || r.table_name || q'{'
124+
}';
125+
execute immediate upd_sql;
126+
end loop;
127+
128+
end;
129+
/
130+
131+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
drop table tableset_tables;
5+
drop table table_map;
6+
7+
create table tableset_tables
8+
( table_set_name varchar2(128)
9+
, schema varchar2(128)
10+
, table_name varchar2(128)
11+
, total_sql number(10)
12+
, total_executions number(10)
13+
, tables_joined number(10));
14+
15+
create table table_map
16+
( table_set_name varchar2(128)
17+
, table1 varchar2(128)
18+
, schema1 varchar2(128)
19+
, table2 varchar2(128)
20+
, schema2 varchar2(128)
21+
, join_count number(10)
22+
, join_executions number(10)
23+
, static_coefficient decimal(10,5)
24+
, dynamic_coefficient decimal(10,5)
25+
, total_affinity decimal(10,5));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
create view tableset_sql as
5+
select distinct table_name, sql_id
6+
from (
7+
select 'tkdradata' table_set_name,
8+
case when v.operation='INDEX' then v.TABLE_NAME
9+
when v.operation='TABLE ACCESS' then v.object_name
10+
else NULL end table_name,
11+
v.object_owner as table_owner,
12+
v.sql_id,
13+
v.executions
14+
from (
15+
select p.object_name, p.operation, p.object_owner,
16+
p.sql_id, p.executions, i.table_name
17+
from dba_sqlset_plans p, all_indexes i
18+
where p.object_name=i.index_name(+)
19+
and sqlset_name='tkdradata'
20+
and object_owner = 'TKDRADATA'
21+
) v
22+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
begin
5+
dbms_sqltune.create_sqlset (
6+
sqlset_name => 'tkdradata',
7+
description => 'SQL data from tkdradata schema'
8+
);
9+
end;
10+
/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
begin
5+
for i in 1..100 loop
6+
execute immediate
7+
'create table dra_' || i || '
8+
( col1 varchar2(256) )
9+
';
10+
end loop;
11+
end;
12+
/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
begin
5+
dbms_sqltune.drop_sqlset (
6+
sqlset_name => 'tkdradata'
7+
);
8+
end;
9+
/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export COMPARTMENT="dra"
2+
export DB_NAME="dradb"
3+
export DB_ADMIN_ASER="admin"
4+
export DB_NORMAL_USER="tkdradata"
5+
export DRA_HOME=${HOME}/microservices-data-refactoring
6+
export TNS_ADMIN=$DRA_HOME/wallet
7+
export DB_ALIAS="dradb_tp"
8+
export SQLCL=/opt/oracle/sqlcl/lib
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
truncate table tableset_tables;
5+
6+
insert into tableset_tables (table_set_name, schema, table_name, total_sql, total_executions)
7+
select table_set_name, table_owner, table_name, count(distinct sql_id), sum(executions)
8+
from (
9+
select distinct table_set_name, table_owner, table_name, sql_id, executions
10+
from (
11+
select 'tkdradata' table_set_name,
12+
case when v.operation='INDEX' then v.TABLE_NAME
13+
when v.operation='TABLE ACCESS' then v.object_name
14+
else NULL end table_name,
15+
v.object_owner as table_owner,
16+
v.sql_id,
17+
v.executions
18+
from (
19+
select p.object_name, p.operation, p.object_owner,
20+
p.sql_id, p.executions, i.table_name
21+
from dba_sqlset_plans p, all_indexes i
22+
where
23+
p.object_name=i.index_name(+) and
24+
sqlset_name='tkdradata' and
25+
object_owner = upper('tkdradata')
26+
) v
27+
)
28+
)
29+
group by table_set_name, table_owner, table_name
30+
having table_name is not null;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
DECLARE
5+
cur DBMS_SQLTUNE.SQLSET_CURSOR;
6+
BEGIN
7+
OPEN cur FOR
8+
SELECT VALUE(P)
9+
FROM table(
10+
DBMS_SQLTUNE.SELECT_CURSOR_CACHE(
11+
'parsing_schema_name=upper(''tkdradata'') and sql_text not like ''%OPT_DYN%''',
12+
NULL, NULL, NULL, NULL, 1, NULL,
13+
'ALL', 'NO_RECURSIVE_SQL')) P;
14+
15+
DBMS_SQLTUNE.LOAD_SQLSET(sqlset_name => 'tkdradata',
16+
populate_cursor => cur,
17+
sqlset_owner => 'tkdradata');
18+
19+
END;
20+
/

0 commit comments

Comments
 (0)