forked from tanelpoder/tpt-oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_sql_profile.sql
44 lines (36 loc) · 1.73 KB
/
create_sql_profile.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
VAR sql_fulltext CLOB
EXEC SELECT sql_fulltext INTO :sql_fulltext FROM v$sql WHERE sql_id = '1ka5g0kh4h6pc' AND rownum = 1;
-- Example 1: Set Join order:
EXEC DBMS_SQLTUNE.IMPORT_SQL_PROFILE(sql_text=>:sql_fulltext, profile=>sys.sqlprof_attr('LEADING(@"SEL$1" "CO"@"SEL$1" "CH"@"SEL$1" "CU"@"SEL$1" "S"@"SEL$1" "P"@"SEL$1")'), name=> 'MANUAL_PROFILE_1k
-- Example 2: Adjust cardinality:
EXEC DBMS_SQLTUNE.IMPORT_SQL_PROFILE(sql_text=>:sql_fulltext, profile=>sys.sqlprof_attr('OPT_ESTIMATE(@"SEL$1", TABLE, "CU"@"SEL$1", SCALE_ROWS=100000)'), name=> 'MANUAL_PROFILE_1ka5g0kh4h6pc');
-- Example 3: Set multiple hints:
DECLARE
hints sys.sqlprof_attr := sys.sqlprof_attr(
('LEADING(@"SEL$1" "CO"@"SEL$1" "CH"@"SEL$1")')
, ('OPT_ESTIMATE(@"SEL$1", TABLE, "CU"@"SEL$1", SCALE_ROWS=100000)')
);
BEGIN
DBMS_SQLTUNE.IMPORT_SQL_PROFILE(sql_text=>:sql_fulltext, profile=> hints, name=> 'MANUAL_PROFILE_1ka5g0kh4h6pc');
END;
/
-- Example 4: SwingBench TPCDS-Like Query 31 skip scan issue (force match)
-- alternative option would be to use opt_param('_optimizer_skip_scan_enabled','false')
DECLARE
hints sys.sqlprof_attr := sys.sqlprof_attr(
('NO_INDEX_SS(@"SEL$26CA4453" "STORE_SALES"@"SEL$1")')
, ('NO_INDEX_SS(@"SEL$2C2C13D8" "WEB_SALES"@"SEL$2")')
);
BEGIN
DBMS_SQLTUNE.IMPORT_SQL_PROFILE(sql_text=>:sql_fulltext, profile=> hints, name=> 'QUERY31_DISABLE_SKIP_SCAN', force_match=> TRUE);
END;
/
DECLARE
hints sys.sqlprof_attr := sys.sqlprof_attr(
('NO_INDEX(@"SEL$26CA4453" "STORE_SALES"@"SEL$1")')
, ('NO_INDEX(@"SEL$2C2C13D8" "WEB_SALES"@"SEL$2")')
);
BEGIN
DBMS_SQLTUNE.IMPORT_SQL_PROFILE(sql_text=>:sql_fulltext, profile=> hints, name=> 'QUERY31_DISABLE_SKIP_SCAN', force_match=> TRUE);
END;
/