-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathselect.out
More file actions
242 lines (219 loc) · 16.4 KB
/
Copy pathselect.out
File metadata and controls
242 lines (219 loc) · 16.4 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
-- Only trace queries with sample flag
SET pg_tracing.sample_rate = 0.0;
SET pg_tracing.caller_sample_rate = 1.0;
-- Run a simple query
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000001-0000000000000001-01'*/ SELECT 1;
?column?
----------
1
(1 row)
-- Get top span id
SELECT span_id AS top_span_id from pg_tracing_peek_spans where parent_id='0000000000000001' and span_type='Select query' \gset
-- Check parameters
SELECT parameters from pg_tracing_peek_spans where span_id=:'top_span_id';
parameters
------------
{1}
(1 row)
-- Check the number of children
SELECT count(*) from pg_tracing_peek_spans where parent_id=:'top_span_id';
count
-------
2
(1 row)
-- Check span_operation
SELECT span_type, span_operation from pg_tracing_peek_spans where trace_id='00000000000000000000000000000001' order by span_start, span_end desc;
span_type | span_operation
--------------+----------------
Select query | SELECT $1
Planner | Planner
ExecutorRun | ExecutorRun
Result | Result
(4 rows)
-- Check userid
SELECT userid = (SELECT usesysid FROM pg_user WHERE usename = current_user) FROM pg_tracing_peek_spans GROUP BY userid;
?column?
----------
t
(1 row)
-- Check dbid
SELECT dbid = (SELECT oid FROM pg_database WHERE datname = (SELECT current_database())) FROM pg_tracing_peek_spans GROUP BY dbid;
?column?
----------
t
(1 row)
-- Check count of query_id
SELECT count(distinct query_id) from pg_tracing_consume_spans where trace_id='00000000000000000000000000000001';
count
-------
1
(1 row)
-- Get initial number of traces reported
SELECT processed_traces from pg_tracing_info \gset
-- Trace a statement with function call
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000003-0000000000000003-01'*/ SELECT count(*) from current_database();
count
-------
1
(1 row)
-- Check the generated span span_type, span_operation and order of function call
SELECT span_type, span_operation, lvl FROM peek_ordered_spans where trace_id='00000000000000000000000000000003';
span_type | span_operation | lvl
--------------+------------------------------------------+-----
Select query | SELECT count(*) from current_database(); | 0
Planner | Planner | 1
ExecutorRun | ExecutorRun | 1
Aggregate | Aggregate | 2
FunctionScan | FunctionScan on current_database | 3
(5 rows)
-- Check expected reported number of trace
SELECT processed_traces = :processed_traces + 1 from pg_tracing_info;
?column?
----------
t
(1 row)
-- Trace a more complex query with multiple function calls
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000004-0000000000000004-01'*/ SELECT s.relation_size + s.index_size as relation_size
FROM (SELECT
pg_relation_size(C.oid) as relation_size,
pg_indexes_size(C.oid) as index_size
FROM pg_class C) as s limit 1 \gset
-- Check the nested level of spans for a query with multiple function calls
SELECT span_type, span_operation, lvl FROM peek_ordered_spans where trace_id='00000000000000000000000000000004';
span_type | span_operation | lvl
--------------+--------------------------------------------------------+-----
Select query | SELECT s.relation_size + s.index_size as relation_size+| 0
| FROM (SELECT +|
| pg_relation_size(C.oid) as relation_size, +|
| pg_indexes_size(C.oid) as index_size +|
| FROM pg_class C) as s limit $1 |
Planner | Planner | 1
ExecutorRun | ExecutorRun | 1
Limit | Limit | 2
SubqueryScan | SubqueryScan on s | 3
SeqScan | SeqScan on pg_class c | 4
(6 rows)
-- Check that we're in a correct state after a timeout
set statement_timeout=200;
-- Trace query triggering a statement timeout
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000007-0000000000000007-01'*/ select * from pg_sleep(10);
ERROR: canceling statement due to statement timeout
SELECT span_type, span_operation, sql_error_code, lvl FROM peek_ordered_spans where trace_id='00000000000000000000000000000007';
span_type | span_operation | sql_error_code | lvl
--------------+----------------------------+----------------+-----
Select query | select * from pg_sleep($1) | 57014 | 0
Planner | Planner | 00000 | 1
ExecutorRun | ExecutorRun | 57014 | 1
FunctionScan | FunctionScan on pg_sleep | 57014 | 2
(4 rows)
-- Cleanup statement setting
set statement_timeout=0;
-- Trace a working query after the timeout to check we're in a consistent state
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000008-0000000000000008-01'*/ select 1;
?column?
----------
1
(1 row)
-- Check the spans order and error code
SELECT span_type, span_operation, sql_error_code, lvl FROM peek_ordered_spans where trace_id='00000000000000000000000000000008';
span_type | span_operation | sql_error_code | lvl
--------------+----------------+----------------+-----
Select query | select $1 | 00000 | 0
Planner | Planner | 00000 | 1
ExecutorRun | ExecutorRun | 00000 | 1
Result | Result | 00000 | 2
(4 rows)
-- Cleanup
SET plan_cache_mode TO DEFAULT;
-- Run a statement with node not executed
/*dddbs='postgres.db',traceparent='00-0000000000000000000000000000000b-000000000000000b-01'*/ select 1 limit 0;
?column?
----------
(0 rows)
SELECT span_operation, parameters, lvl from peek_ordered_spans where trace_id='0000000000000000000000000000000b';
span_operation | parameters | lvl
--------------------+------------+-----
select $1 limit $2 | {1,0} | 0
Planner | | 1
ExecutorRun | | 1
Limit | | 2
(4 rows)
CALL clean_spans();
-- Check standalone trace
SET pg_tracing.sample_rate = 1.0;
SELECT 1;
?column?
----------
1
(1 row)
-- Make sure we have unique span ids
SELECT count(distinct span_id) from pg_tracing_consume_spans;
count
-------
4
(1 row)
CALL clean_spans();
-- Trigger a planner error
SELECT '\xDEADBEEF'::bytea::text::int;
ERROR: invalid input syntax for type integer: "\xdeadbeef"
-- Check planner error
SELECT span_type, span_operation, parameters, sql_error_code, lvl from peek_ordered_spans;
span_type | span_operation | parameters | sql_error_code | lvl
--------------+-----------------------------+-------------------+----------------+-----
Select query | SELECT $1::bytea::text::int | {"'\\xDEADBEEF'"} | 22P02 | 0
Planner | Planner | | 22P02 | 1
(2 rows)
CALL clean_spans();
-- Check spans generated by lazy functions
CREATE OR REPLACE FUNCTION lazy_function(IN anyarray, OUT x anyelement)
RETURNS SETOF anyelement
LANGUAGE sql
AS 'select * from pg_catalog.generate_series(array_lower($1, 1), array_upper($1, 1), 1)';
SELECT lazy_function('{1,2,3,4}'::int[]) FROM (VALUES (1,2)) as t;
lazy_function
---------------
1
2
3
4
(4 rows)
SELECT span_type, span_operation, parameters, lvl from peek_ordered_spans;
span_type | span_operation | parameters | lvl
-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----
Utility query | CREATE OR REPLACE FUNCTION lazy_function(IN anyarray, OUT x anyelement) RETURNS SETOF anyelement LANGUAGE sql AS 'select * from pg_catalog.generate_series(array_lower($1, 1), array_upper($1, 1), 1)'; | | 0
ProcessUtility | ProcessUtility | | 1
TransactionCommit | TransactionCommit | | 0
Select query | SELECT lazy_function($1::int[]) FROM (VALUES ($2,$3)) as t | {"'{1,2,3,4}'",1,2} | 0
Planner | Planner | | 1
ExecutorRun | ExecutorRun | | 1
ProjectSet | ProjectSet | | 2
Result | Result | | 3
Select query | select * from pg_catalog.generate_series(array_lower($1, $2), array_upper($1, $3), $4) | {"{1,2,3,4}","select * from pg_catalog.generate_series(array_lower($1, $2), array_upper($1, $3), $4)","SELECT lazy_function($1::int[]) FROM (VALUES ($2,$3)) as t",T;} | 3
Planner | Planner | | 4
(10 rows)
CALL clean_spans();
-- Check function calls that don't have sources in pg_proc
SELECT information_schema._pg_truetypid(a, t) FROM pg_attribute a, pg_type t limit 1;
_pg_truetypid
---------------
26
(1 row)
SELECT span_type, span_operation, parameters, lvl from peek_ordered_spans;
span_type | span_operation | parameters | lvl
--------------+---------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----
Select query | SELECT information_schema._pg_truetypid(a, t) FROM pg_attribute a, pg_type t limit $1 | {1} | 0
Planner | Planner | | 1
ExecutorRun | ExecutorRun | | 1
Limit | Limit | | 2
NestedLoop | NestedLoop | | 3
SeqScan | SeqScan on pg_attribute a | | 4
Materialize | Materialize | | 4
SeqScan | SeqScan on pg_type t | | 5
Select query | Select query | {"(1255,oid,26,4,1,-1,0,t,i,p,\"\",t,f,f,\"\",\"\",f,t,0,0,,,,,)","(16,bool,11,10,1,t,b,B,t,t,\",\",0,-,0,1000,boolin,boolout,boolrecv,boolsend,-,-,-,c,p,f,0,-1,0,0,,,)"} | 2
Planner | Planner | | 3
ExecutorRun | ExecutorRun | | 3
Result | Result | | 4
(12 rows)
CALL clean_spans();
-- Cleanup
CALL reset_settings();