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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
| -- DBMS_XPLAN.DISPLAY: NULL-аргументы, свой стол планов, filter_preds.
| -- Пара к sql/oracle/dbms_xplan_display_bounds.sql. Expected совпадает со стендом Oracle 23.5.
|
| SET client_min_messages = notice;
| DROP TABLE IF EXISTS rxp_t;
| DROP TABLE IF EXISTS rxp_u;
| DROP TABLE IF EXISTS rxp_plan;
|
| CREATE TABLE rxp_t (id numeric);
| INSERT INTO rxp_t VALUES (1);
| CREATE TABLE rxp_u (id numeric);
| INSERT INTO rxp_u VALUES (2);
| CREATE TABLE rxp_plan (
| statement_id text,
| plan_id numeric,
| timestamp timestamp,
| remarks text,
| operation text,
| options text,
| object_node text,
| object_owner text,
| object_name text,
| object_alias text,
| object_instance numeric,
| object_type text,
| optimizer text,
| search_columns numeric,
| id numeric,
| parent_id numeric,
| depth numeric,
| position numeric,
| cost numeric,
| cardinality numeric,
| bytes numeric,
| other_tag text,
| partition_start text,
| partition_stop text,
| partition_id numeric,
| other text,
| other_xml text,
| distribution text,
| cpu_cost numeric,
| io_cost numeric,
| temp_space numeric,
| access_predicates text,
| filter_predicates text,
| projection text,
| time numeric,
| qblock_name text
| );
|
| DROP FUNCTION IF EXISTS rxp_hit(text, text, text, text, text);
|
| CREATE FUNCTION rxp_hit(
| p_table text,
| p_sid text,
| p_fmt text,
| p_filter text,
| p_needle text
| ) RETURNS text
| LANGUAGE plpgsql AS $$
| DECLARE
| v_hit text := 'NO';
| r record;
| BEGIN
| FOR r IN
| SELECT plan_table_output AS line
| FROM dbms_xplan_display(p_table, p_sid, p_fmt, p_filter)
| LOOP
| IF r.line IS NOT NULL AND position(upper(p_needle) IN upper(r.line)) > 0 THEN
| v_hit := 'YES';
| END IF;
| END LOOP;
| RETURN v_hit;
| END $$;
| DO $$
|
| DECLARE
| v_hit text;
| BEGIN
| RAISE NOTICE 'Expected: null_tab=YES';
| EXECUTE 'EXPLAIN PLAN SET STATEMENT_ID = ''rxp_stmt'' FOR SELECT * FROM rxp_t';
| v_hit := rxp_hit(NULL, 'rxp_stmt', 'BASIC', NULL, 'RXP_T');
| RAISE NOTICE 'Actual: null_tab=%', v_hit;
| END $$;
| DO $$
|
| DECLARE
| v_hit text;
| BEGIN
| RAISE NOTICE 'Expected: custom=YES';
| EXECUTE 'EXPLAIN PLAN SET STATEMENT_ID = ''rxp_custom'' INTO rxp_plan FOR SELECT * FROM rxp_t';
| v_hit := rxp_hit('rxp_plan', 'rxp_custom', 'BASIC', NULL, 'TABLE ACCESS');
| RAISE NOTICE 'Actual: custom=%', v_hit;
| END $$;
| DO $$
|
| DECLARE
| v_t text;
| v_u text;
| BEGIN
| RAISE NOTICE 'Expected: filter=OK';
| EXECUTE 'EXPLAIN PLAN SET STATEMENT_ID = ''rxp_stmt'' FOR SELECT * FROM rxp_t';
| EXECUTE 'EXPLAIN PLAN SET STATEMENT_ID = ''rxp_other'' FOR SELECT * FROM rxp_u';
| v_t := rxp_hit('PLAN_TABLE', NULL, 'BASIC', 'statement_id = ''rxp_stmt''', 'RXP_T');
| v_u := rxp_hit('PLAN_TABLE', NULL, 'BASIC', 'statement_id = ''rxp_stmt''', 'RXP_U');
| RAISE NOTICE 'Actual: %',
| CASE WHEN v_t = 'YES' AND v_u = 'NO' THEN 'filter=OK' ELSE 'filter=BAD' END;
| END $$;
| DO $$
|
| DECLARE
| v_hit text;
| BEGIN
| RAISE NOTICE 'Expected: null_fmt=TYPICAL';
| EXECUTE 'EXPLAIN PLAN SET STATEMENT_ID = ''rxp_stmt'' FOR SELECT * FROM rxp_t WHERE id = 1';
| v_hit := rxp_hit('PLAN_TABLE', 'rxp_stmt', NULL, NULL, 'COST');
| RAISE NOTICE 'Actual: %',
| CASE v_hit WHEN 'YES' THEN 'null_fmt=TYPICAL' ELSE 'null_fmt=OTHER' END;
| END $$;
| DO $$
|
| DECLARE
| v_hit text;
| BEGIN
| RAISE NOTICE 'Expected: empty_fmt=TYPICAL';
| EXECUTE 'EXPLAIN PLAN SET STATEMENT_ID = ''rxp_stmt'' FOR SELECT * FROM rxp_t WHERE id = 1';
| v_hit := rxp_hit('PLAN_TABLE', 'rxp_stmt', '', NULL, 'COST');
| RAISE NOTICE 'Actual: %',
| CASE v_hit WHEN 'YES' THEN 'empty_fmt=TYPICAL' ELSE 'empty_fmt=OTHER' END;
| END $$;
| DO $$
|
| BEGIN
| DELETE FROM plan_table WHERE statement_id IN ('rxp_stmt', 'rxp_other', 'rxp_custom');
| EXCEPTION
| WHEN SQLSTATE '42P01' THEN
| NULL;
| END $$;
| DROP FUNCTION IF EXISTS rxp_hit(text, text, text, text, text);
| DROP TABLE IF EXISTS rxp_t;
| DROP TABLE IF EXISTS rxp_u;
| DROP TABLE IF EXISTS rxp_plan;
|
|