Skip to content

Commit

Permalink
Simplify parameter extraction in normalise query
Browse files Browse the repository at this point in the history
  • Loading branch information
bonnefoa committed Aug 26, 2024
1 parent 9ffce21 commit 349df92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/pg_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ extern TimestampTz

/* pg_tracing_query_process.c */
extern const char *normalise_query_parameters(const SpanContext * span_context, Span * span,
int query_loc, int *query_len_p,
StringInfo parameters_buffer);
int query_loc, int *query_len_p);
extern void extract_trace_context_from_query(Traceparent * traceparent, const char *query);
extern ParseTraceparentErr parse_trace_context(Traceparent * traceparent, const char *trace_context_str, int trace_context_len);
extern char *parse_code_to_err(ParseTraceparentErr err);
Expand Down
13 changes: 1 addition & 12 deletions src/pg_tracing_active_spans.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,9 @@ begin_active_span(const SpanContext * span_context, Span * span,
if (span_context->jstate && span_context->jstate->clocations_count > 0 && query != NULL)
{
/* jstate is available, normalise query and extract parameters' values */
StringInfo parameters_buffer = NULL;

if (span_context->max_parameter_size)

/*
* We want parameters' value, propagate parameters_buffer
* StringInfo
*/
parameters_buffer = span_context->parameters_buffer;

query_len = query->stmt_len;
normalised_query = normalise_query_parameters(span_context, span,
query->stmt_location, &query_len,
parameters_buffer);
query->stmt_location, &query_len);
}
else
{
Expand Down
14 changes: 7 additions & 7 deletions src/pg_tracing_query_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ comp_location(const void *a, const void *b)
*/
const char *
normalise_query_parameters(const SpanContext * span_context, Span * span,
int query_loc, int *query_len_p,
StringInfo parameters_buffer)
int query_loc, int *query_len_p)
{
const char *query = span_context->query_text;
const JumbleState *jstate = span_context->jstate;
Expand All @@ -236,10 +235,10 @@ normalise_query_parameters(const SpanContext * span_context, Span * span,
YYLTYPE yylloc;
int bytes_written;
int current_loc = 0;
bool full_buffer = false;
bool extract_parameters = span_context->max_parameter_size > 0;

if (parameters_buffer)
span->parameter_offset = parameters_buffer->len;
if (extract_parameters)
span->parameter_offset = span_context->parameters_buffer->len;

if (query_loc == -1)
{
Expand Down Expand Up @@ -312,7 +311,8 @@ normalise_query_parameters(const SpanContext * span_context, Span * span,
* from foo where bar = -2" will have identical normalized
* query strings.
*/
bytes_written = append_str_to_parameters_buffer("-", 1, false);
if (extract_parameters)
bytes_written = append_str_to_parameters_buffer("-", 1, false);
tok = core_yylex(&yylval, &yylloc, yyscanner);
if (tok == 0)
break; /* out of inner for-loop */
Expand All @@ -324,7 +324,7 @@ normalise_query_parameters(const SpanContext * span_context, Span * span,
n_quer_loc += sprintf(norm_query + n_quer_loc, "$%d",
current_loc + 1 + jstate->highest_extern_param_id);

if (parameters_buffer)
if (extract_parameters)
{
len_parameter = strlen(yyextra.scanbuf + yylloc);

Expand Down

0 comments on commit 349df92

Please sign in to comment.