From 538d3e8ef2281b5380d536f4346857cdd8d99371 Mon Sep 17 00:00:00 2001 From: Anthonin Bonnefoy Date: Mon, 16 Sep 2024 08:38:20 +0200 Subject: [PATCH 1/4] Removed unecessary column names in utility test --- expected/utility.out | 4 ++-- sql/utility.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/expected/utility.out b/expected/utility.out index bb08d36..469ca73 100644 --- a/expected/utility.out +++ b/expected/utility.out @@ -59,8 +59,8 @@ CREATE EXTENSION pg_tracing; SET pg_tracing.sample_rate = 0.0; -- View displaying spans with their nested level CREATE VIEW peek_spans_with_level AS - WITH RECURSIVE list_trace_spans(trace_id, parent_id, span_id, query_id, span_type, span_operation, span_start, span_end, sql_error_code, userid, dbid, pid, subxact_count, plan_startup_cost, plan_total_cost, plan_rows, plan_width, rows, nloops, shared_blks_hit, shared_blks_read, shared_blks_dirtied, shared_blks_written, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, blk_read_time, blk_write_time, temp_blks_read, temp_blks_written, temp_blk_read_time, temp_blk_write_time, wal_records, wal_fpi, wal_bytes, jit_functions, jit_generation_time, jit_inlining_time, jit_optimization_time, jit_emission_time, startup, parameters, deparse_info, lvl) AS ( - SELECT p.*, 1 + WITH RECURSIVE list_trace_spans AS ( + SELECT p.*, 1 as lvl FROM pg_tracing_peek_spans p where not parent_id=ANY(SELECT span_id from pg_tracing_peek_spans) UNION ALL SELECT s.*, lvl + 1 diff --git a/sql/utility.sql b/sql/utility.sql index ed64486..bfd21a6 100644 --- a/sql/utility.sql +++ b/sql/utility.sql @@ -67,8 +67,8 @@ SET pg_tracing.sample_rate = 0.0; -- View displaying spans with their nested level CREATE VIEW peek_spans_with_level AS - WITH RECURSIVE list_trace_spans(trace_id, parent_id, span_id, query_id, span_type, span_operation, span_start, span_end, sql_error_code, userid, dbid, pid, subxact_count, plan_startup_cost, plan_total_cost, plan_rows, plan_width, rows, nloops, shared_blks_hit, shared_blks_read, shared_blks_dirtied, shared_blks_written, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, blk_read_time, blk_write_time, temp_blks_read, temp_blks_written, temp_blk_read_time, temp_blk_write_time, wal_records, wal_fpi, wal_bytes, jit_functions, jit_generation_time, jit_inlining_time, jit_optimization_time, jit_emission_time, startup, parameters, deparse_info, lvl) AS ( - SELECT p.*, 1 + WITH RECURSIVE list_trace_spans AS ( + SELECT p.*, 1 as lvl FROM pg_tracing_peek_spans p where not parent_id=ANY(SELECT span_id from pg_tracing_peek_spans) UNION ALL SELECT s.*, lvl + 1 From 2ba3110e0cfcfa1d5306e52db6463596eb592b29 Mon Sep 17 00:00:00 2001 From: Anthonin Bonnefoy Date: Mon, 16 Sep 2024 08:52:49 +0200 Subject: [PATCH 2/4] Rename node to planstate --- src/pg_tracing_planstate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pg_tracing_planstate.c b/src/pg_tracing_planstate.c index fdb576c..855d583 100644 --- a/src/pg_tracing_planstate.c +++ b/src/pg_tracing_planstate.c @@ -177,7 +177,7 @@ drop_traced_planstates(void) * It will track the time of the first node call needed to place the planstate span. */ static TupleTableSlot * -ExecProcNodeFirstPgTracing(PlanState *node) +ExecProcNodeFirstPgTracing(PlanState *planstate) { uint64 span_id; @@ -201,7 +201,7 @@ ExecProcNodeFirstPgTracing(PlanState *node) max_planstart * sizeof(TracedPlanstate)); } - switch (nodeTag(node)) + switch (nodeTag(planstate)) { case T_GatherState: case T_GatherMergeState: @@ -218,7 +218,7 @@ ExecProcNodeFirstPgTracing(PlanState *node) } /* Register planstate start */ - traced_planstates[index_planstart].planstate = node; + traced_planstates[index_planstart].planstate = planstate; traced_planstates[index_planstart].node_start = GetCurrentTimestamp(); traced_planstates[index_planstart].span_id = span_id; traced_planstates[index_planstart].nested_level = nested_level; @@ -226,8 +226,8 @@ ExecProcNodeFirstPgTracing(PlanState *node) exit: /* Restore previous exec proc */ - node->ExecProcNode = previous_ExecProcNode; - return node->ExecProcNode(node); + planstate->ExecProcNode = previous_ExecProcNode; + return planstate->ExecProcNode(planstate); } /* From 486dfc7f73d63b2e5654e90c7ccda005f2cf53fc Mon Sep 17 00:00:00 2001 From: Anthonin Bonnefoy Date: Mon, 16 Sep 2024 09:15:01 +0200 Subject: [PATCH 3/4] Rename executor_run in PerLevelInfos --- src/pg_tracing.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pg_tracing.c b/src/pg_tracing.c index c500994..b8ba8f5 100644 --- a/src/pg_tracing.c +++ b/src/pg_tracing.c @@ -95,8 +95,8 @@ typedef struct PerLevelInfos * level. Executor run is used as * parent for spans generated from * planstate */ - TimestampTz executor_start; - TimestampTz executor_end; + TimestampTz executor_run_start; + TimestampTz executor_run_end; } PerLevelInfos; /* GUC variables */ @@ -1067,7 +1067,7 @@ process_query_desc(const Traceparent * traceparent, const QueryDesc *queryDesc, if (pg_tracing_planstate_spans) { uint64 parent_id = per_level_infos[nested_level].executor_run_span_id; - TimestampTz parent_start = per_level_infos[nested_level].executor_start; + TimestampTz parent_start = per_level_infos[nested_level].executor_run_start; uint64 query_id = queryDesc->plannedstmt->queryId; process_planstate(traceparent, queryDesc, sql_error_code, @@ -1881,7 +1881,7 @@ pg_tracing_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 cou executor_run_span = push_child_active_span(pg_tracing_mem_ctx, &span_context, SPAN_EXECUTOR_RUN); per_level_infos[nested_level].executor_run_span_id = executor_run_span->span_id; - per_level_infos[nested_level].executor_start = executor_run_span->start; + per_level_infos[nested_level].executor_run_start = executor_run_span->start; /* * If this query starts parallel worker, push the trace context for the @@ -1956,7 +1956,7 @@ pg_tracing_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 cou nested_level--; /* End ExecutorRun span and store it */ pop_and_store_active_span(span_end_time); - per_level_infos[nested_level].executor_end = span_end_time; + per_level_infos[nested_level].executor_run_end = span_end_time; } /* @@ -2087,7 +2087,7 @@ pg_tracing_ExecutorEnd(QueryDesc *queryDesc) * We're at the end of the Executor for this level, generate spans from * the planstate if needed */ - parent_end = per_level_infos[nested_level].executor_end; + parent_end = per_level_infos[nested_level].executor_run_end; process_query_desc(traceparent, queryDesc, 0, pg_tracing_deparse_plan, parent_end); /* No need to increment nested level here */ From dd323df36c6c919ab100b4d0541f11fbc17f2dd5 Mon Sep 17 00:00:00 2001 From: Anthonin Bonnefoy Date: Mon, 16 Sep 2024 09:38:53 +0200 Subject: [PATCH 4/4] Remove unused fields in Span struct --- src/pg_tracing.h | 3 --- src/pg_tracing_planstate.c | 3 --- src/pg_tracing_span.c | 2 -- 3 files changed, 8 deletions(-) diff --git a/src/pg_tracing.h b/src/pg_tracing.h index 9a2364c..d0a17ed 100644 --- a/src/pg_tracing.h +++ b/src/pg_tracing.h @@ -197,9 +197,6 @@ typedef struct Span SpanType type; /* Type of the span. Used to generate the * span's name */ - bool parallel_aware; - bool async_capable; - int8 nested_level; /* Nested level of this span this span. * Internal usage only */ int8 parent_planstate_index; /* Index to the parent planstate of diff --git a/src/pg_tracing_planstate.c b/src/pg_tracing_planstate.c index 855d583..d436795 100644 --- a/src/pg_tracing_planstate.c +++ b/src/pg_tracing_planstate.c @@ -602,9 +602,6 @@ create_span_node(PlanState *planstate, const planstateTraceContext * planstateTr const char *operation_name; int len_operation_name; - span.parallel_aware = plan->parallel_aware; - span.async_capable = plan->async_capable; - operation_name = plan_to_rel_name(planstateTraceContext, planstate); len_operation_name = strlen(operation_name); if (len_operation_name > 0) diff --git a/src/pg_tracing_span.c b/src/pg_tracing_span.c index cd65ab2..be97716 100644 --- a/src/pg_tracing_span.c +++ b/src/pg_tracing_span.c @@ -41,8 +41,6 @@ begin_span(TraceId trace_id, Span * span, SpanType type, else span->span_id = pg_prng_uint64(&pg_global_prng_state); - span->parallel_aware = false; - span->async_capable = false; span->worker_id = -1; span->operation_name_offset = -1; span->num_parameters = 0;