diff --git a/common.mk b/common.mk index 59e62b4..77889fe 100644 --- a/common.mk +++ b/common.mk @@ -8,7 +8,7 @@ PG_CONFIG = pg_config PG_CONFIG_EXISTS := $(shell command -v $(PG_CONFIG) 2> /dev/null) ifdef PG_CONFIG_EXISTS # Default to pg_config's advertised version -PG_VERSION ?= $(shell $(PG_CONFIG) --version | cut -d' ' -f2 | cut -d'.' -f1 | tr -d 'devel') +PG_VERSION ?= $(shell $(PG_CONFIG) --version | sed 's/PostgreSQL \([0-9]*\).*/\1/g') else # pg_config is not present, let's assume we are packaging and use the latest PG version PG_VERSION ?= $(lastword $(PG_VERSIONS)) diff --git a/regress/18/expected/cursor.out b/regress/18/expected/cursor.out index 19dd661..2b746d7 100644 --- a/regress/18/expected/cursor.out +++ b/regress/18/expected/cursor.out @@ -147,19 +147,19 @@ SELECT span_type, span_operation, lvl from peek_ordered_spans where trace_id='00 ProcessUtility | ProcessUtility | 2 Utility query | DECLARE c CURSOR FOR SELECT * from pg_tracing_test; | 1 ProcessUtility | ProcessUtility | 2 - Select query | SELECT * from pg_tracing_test; | 3 + Select query | DECLARE c CURSOR FOR SELECT * from pg_tracing_test; | 3 Planner | Planner | 4 Utility query | FETCH FORWARD 20 from c | 1 ProcessUtility | ProcessUtility | 2 - Select query | SELECT * from pg_tracing_test; | 3 + Select query | DECLARE c CURSOR FOR SELECT * from pg_tracing_test; | 3 ExecutorRun | ExecutorRun | 4 Utility query | FETCH BACKWARD 10 from c | 1 ProcessUtility | ProcessUtility | 2 - Select query | SELECT * from pg_tracing_test; | 3 + Select query | DECLARE c CURSOR FOR SELECT * from pg_tracing_test; | 3 ExecutorRun | ExecutorRun | 4 Utility query | CLOSE c; | 1 ProcessUtility | ProcessUtility | 2 - Select query | SELECT * from pg_tracing_test; | 3 + Select query | DECLARE c CURSOR FOR SELECT * from pg_tracing_test; | 3 Utility query | COMMIT; | 1 ProcessUtility | ProcessUtility | 2 (20 rows) diff --git a/regress/18/expected/planstate_bitmap.out b/regress/18/expected/planstate_bitmap.out index 48fa301..413c2e8 100644 --- a/regress/18/expected/planstate_bitmap.out +++ b/regress/18/expected/planstate_bitmap.out @@ -24,11 +24,11 @@ SELECT span_operation, deparse_info, parameters, pos_start, pos_end, lvl from pe SELECT * from pg_tracing_test where a=$1 OR b=$2 OR c=$3 | | {1,'2',3} | 1 | 11 | 0 Planner | | | 2 | 3 | 1 ExecutorRun | | | 4 | 10 | 1 - BitmapHeapScan on pg_tracing_test | Recheck Cond: ((c = 3) OR (b = '2'::bpchar) OR (a = 1)) | | 5 | 9 | 2 + BitmapHeapScan on pg_tracing_test | Recheck Cond: ((a = 1) OR (b = '2'::bpchar) OR (c = 3)) | | 5 | 9 | 2 BitmapOr | | | 5 | 8 | 3 - BitmapIndexScan on pg_tracing_index_c | Index Cond: (c = 3) | | 5 | 6 | 4 + BitmapIndexScan on pg_tracing_index_a | Index Cond: (a = 1) | | 5 | 6 | 4 BitmapIndexScan on pg_tracing_index_b | Index Cond: (b = '2'::bpchar) | | 6 | 7 | 4 - BitmapIndexScan on pg_tracing_index_a | Index Cond: (a = 1) | | 7 | 8 | 4 + BitmapIndexScan on pg_tracing_index_c | Index Cond: (c = 3) | | 7 | 8 | 4 (8 rows) -- Clean created spans diff --git a/regress/18/expected/planstate_projectset.out b/regress/18/expected/planstate_projectset.out index 8dc61b4..e7a236c 100644 --- a/regress/18/expected/planstate_projectset.out +++ b/regress/18/expected/planstate_projectset.out @@ -14,7 +14,7 @@ SELECT span_operation, deparse_info, parameters, lvl from peek_ordered_spans whe ExecutorRun | | | 1 ProjectSet | | | 2 Result | | | 3 - SELECT * FROM pg_catalog.unnest($1) WITH ORDINALITY | | | 3 + SELECT * FROM pg_catalog.unnest($1) WITH ORDINALITY | | {"{0,1,2}"} | 3 Planner | | | 4 (7 rows) diff --git a/regress/18/expected/select.out b/regress/18/expected/select.out index f440caa..d7bcd1e 100644 --- a/regress/18/expected/select.out +++ b/regress/18/expected/select.out @@ -198,18 +198,18 @@ SELECT lazy_function('{1,2,3,4}'::int[]) FROM (VALUES (1,2)) as t; (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,1,1} | 3 - Planner | Planner | | 4 + 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(); @@ -221,20 +221,20 @@ SELECT information_schema._pg_truetypid(a, t) FROM pg_attribute a, pg_type t lim (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 | | 2 - Planner | Planner | | 3 - ExecutorRun | ExecutorRun | | 3 - Result | Result | | 4 + 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(); diff --git a/regress/18/expected/trigger.out b/regress/18/expected/trigger.out index d3faf14..c7f323e 100644 --- a/regress/18/expected/trigger.out +++ b/regress/18/expected/trigger.out @@ -288,12 +288,12 @@ SELECT trace_id, span_type, span_operation, lvl from peek_ordered_spans where tr ----------------------------------+-------------------+--------------------------------------------------------------------------+----- 00000000000000000000000000000005 | Utility query | copy (insert into copydml_test (t) values ('f') returning id) to stdout; | 0 00000000000000000000000000000005 | ProcessUtility | ProcessUtility | 1 - 00000000000000000000000000000005 | Insert query | insert into copydml_test (t) values ($1) returning id | 2 + 00000000000000000000000000000005 | Insert query | copy (insert into copydml_test (t) values ($1) returning id) to stdout | 2 00000000000000000000000000000005 | Planner | Planner | 3 00000000000000000000000000000005 | ExecutorRun | ExecutorRun | 3 00000000000000000000000000000005 | Insert | Insert on copydml_test | 4 00000000000000000000000000000005 | Result | Result | 5 - 00000000000000000000000000000005 | Select query | tg_op in ($7, $8) | 4 + 00000000000000000000000000000005 | Select query | tg_op in ($7, 'UPDATE') | 4 00000000000000000000000000000005 | Planner | Planner | 5 00000000000000000000000000000005 | TransactionCommit | TransactionCommit | 0 (10 rows) @@ -308,12 +308,12 @@ SELECT trace_id, span_type, span_operation, lvl from peek_ordered_spans where tr (2 rows) SELECT trace_id, span_type, span_operation, lvl from peek_ordered_spans where trace_id='fed00000000000000000000000000006'; - trace_id | span_type | span_operation | lvl -----------------------------------+----------------+-----------------------------------------------------+----- - fed00000000000000000000000000006 | Utility query | explain INSERT INTO before_trigger_table VALUES($1) | 0 - fed00000000000000000000000000006 | ProcessUtility | ProcessUtility | 1 - fed00000000000000000000000000006 | Insert query | INSERT INTO before_trigger_table VALUES($1) | 2 - fed00000000000000000000000000006 | Planner | Planner | 3 + trace_id | span_type | span_operation | lvl +----------------------------------+----------------+------------------------------------------------------+----- + fed00000000000000000000000000006 | Utility query | explain INSERT INTO before_trigger_table VALUES($1) | 0 + fed00000000000000000000000000006 | ProcessUtility | ProcessUtility | 1 + fed00000000000000000000000000006 | Insert query | explain INSERT INTO before_trigger_table VALUES($1); | 2 + fed00000000000000000000000000006 | Planner | Planner | 3 (4 rows) -- Cleanup diff --git a/regress/18/expected/utility.out b/regress/18/expected/utility.out index 36def42..decbab4 100644 --- a/regress/18/expected/utility.out +++ b/regress/18/expected/utility.out @@ -283,10 +283,10 @@ select span_operation, parameters, lvl from peek_ordered_spans; -----------------------------------------------------------+------------+----- PREPARE test_prepared_one_param_2 (integer) AS SELECT $1; | | 0 ProcessUtility | | 1 - SELECT $1; | | 2 + PREPARE test_prepared_one_param_2 (integer) AS SELECT $1; | | 2 EXECUTE test_prepared_one_param_2(100); | | 0 ProcessUtility | | 1 - SELECT $1; | {100} | 2 + PREPARE test_prepared_one_param_2 (integer) AS SELECT $1; | {100} | 2 Planner | | 3 ExecutorRun | | 3 Result | | 4 @@ -306,16 +306,16 @@ PREPARE test_insert (integer, text) AS INSERT INTO pg_tracing_test(a, b) VALUES /*dddbs='postgres.db',traceparent='00-00000000000000000000000000000001-0000000000000001-01'*/ EXECUTE test_insert(100, '2'); -- Check spans of test_insert execution select trace_id, span_operation, parameters, lvl from peek_ordered_spans WHERE trace_id='00000000000000000000000000000001'; - trace_id | span_operation | parameters | lvl -----------------------------------+----------------------------------------------------+------------+----- - 00000000000000000000000000000001 | EXECUTE test_insert(100, '2'); | | 0 - 00000000000000000000000000000001 | ProcessUtility | | 1 - 00000000000000000000000000000001 | INSERT INTO pg_tracing_test(a, b) VALUES ($1, $2); | {100,2} | 2 - 00000000000000000000000000000001 | Planner | | 3 - 00000000000000000000000000000001 | ExecutorRun | | 3 - 00000000000000000000000000000001 | Insert on pg_tracing_test | | 4 - 00000000000000000000000000000001 | Result | | 5 - 00000000000000000000000000000001 | TransactionCommit | | 0 + trace_id | span_operation | parameters | lvl +----------------------------------+-------------------------------------------------------------------------------------------+------------+----- + 00000000000000000000000000000001 | EXECUTE test_insert(100, '2'); | | 0 + 00000000000000000000000000000001 | ProcessUtility | | 1 + 00000000000000000000000000000001 | PREPARE test_insert (integer, text) AS INSERT INTO pg_tracing_test(a, b) VALUES ($1, $2); | {100,2} | 2 + 00000000000000000000000000000001 | Planner | | 3 + 00000000000000000000000000000001 | ExecutorRun | | 3 + 00000000000000000000000000000001 | Insert on pg_tracing_test | | 4 + 00000000000000000000000000000001 | Result | | 5 + 00000000000000000000000000000001 | TransactionCommit | | 0 (8 rows) -- We should have only two query_ids @@ -351,15 +351,15 @@ select count(distinct(trace_id)) from pg_tracing_peek_spans; -- Check spans of test_prepared_one_param execution select span_operation, parameters, lvl from peek_ordered_spans; - span_operation | parameters | lvl ----------------------------------------+------------+----- - EXECUTE test_prepared_one_param(200); | | 0 - ProcessUtility | | 1 - SELECT $1; | | 2 - ExecutorRun | | 3 - Result | | 4 - SET plan_cache_mode TO DEFAULT; | | 0 - ProcessUtility | | 1 + span_operation | parameters | lvl +---------------------------------------------------------+------------+----- + EXECUTE test_prepared_one_param(200); | | 0 + ProcessUtility | | 1 + PREPARE test_prepared_one_param (integer) AS SELECT $1; | | 2 + ExecutorRun | | 3 + Result | | 4 + SET plan_cache_mode TO DEFAULT; | | 0 + ProcessUtility | | 1 (7 rows) -- Check the top span (standalone top span has trace_id=parent_id) @@ -423,7 +423,7 @@ LANGUAGE plpgsql; /*dddbs='postgres.db',traceparent='00-00000000000000000000000000000004-0000000000000004-01'*/ select function_with_error('{1,2,3}'::int[]); ERROR: return type mismatch in function declared to return record DETAIL: Final statement returns too few columns. -CONTEXT: SQL function "function_with_error" during startup +CONTEXT: SQL function "function_with_error" statement 1 -- Check lazy function call with error select trace_id, span_type, span_operation, sql_error_code, lvl from peek_ordered_spans where trace_id='00000000000000000000000000000004'; trace_id | span_type | span_operation | sql_error_code | lvl diff --git a/src/pg_tracing.c b/src/pg_tracing.c index 7bb47f0..8935c4a 100644 --- a/src/pg_tracing.c +++ b/src/pg_tracing.c @@ -265,13 +265,12 @@ static PlannedStmt *pg_tracing_planner_hook(Query *query, const char *query_string, int cursorOptions, ParamListInfo params); -#if (PG_VERSION_NUM < 180000) static void pg_tracing_ExecutorStart(QueryDesc *queryDesc, int eflags); +#if (PG_VERSION_NUM < 180000) static void pg_tracing_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once); #else -static bool pg_tracing_ExecutorStart(QueryDesc *queryDesc, int eflags); static void pg_tracing_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count); @@ -1761,19 +1760,12 @@ pg_tracing_planner_hook(Query *query, const char *query_string, int cursorOption * random sample_rate. * If query is sampled, start the top span if it doesn't already exist. */ -#if (PG_VERSION_NUM < 180000) static void -#else -static bool -#endif pg_tracing_ExecutorStart(QueryDesc *queryDesc, int eflags) { SpanContext span_context; bool is_lazy_function; Traceparent *traceparent = &executor_traceparent; -#if (PG_VERSION_NUM >= 180000) - bool res; -#endif if (nested_level == 0) { @@ -1834,17 +1826,10 @@ pg_tracing_ExecutorStart(QueryDesc *queryDesc, int eflags) if (pg_tracing_planstate_spans && !within_declare_cursor) queryDesc->instrument_options = INSTRUMENT_ALL; -#if (PG_VERSION_NUM >= 180000) - if (prev_ExecutorStart) - res = prev_ExecutorStart(queryDesc, eflags); - else - res = standard_ExecutorStart(queryDesc, eflags); -#else if (prev_ExecutorStart) prev_ExecutorStart(queryDesc, eflags); else standard_ExecutorStart(queryDesc, eflags); -#endif /* Allocate totaltime instrumentation in the per-query context */ if (queryDesc->totaltime == NULL) @@ -1855,10 +1840,6 @@ pg_tracing_ExecutorStart(QueryDesc *queryDesc, int eflags) queryDesc->totaltime = InstrAlloc(1, INSTRUMENT_ALL, false); MemoryContextSwitchTo(oldcxt); } - -#if (PG_VERSION_NUM >= 180000) - return res; -#endif } /*