[PATCH] Use $ parameters as replacement characters for pg_stat_statements

From: Lukas Fittl <lukas(at)fittl(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Use $ parameters as replacement characters for pg_stat_statements
Date: 2017-03-01 01:01:29
Message-ID: CAP53PkxeaCuwYmF-A4J5z2-qk5fYFo5_NH3gpXGJJBxv1DMwEw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-hackers

Hi,

Currently pg_stat_statements replaces constant values with ? characters.
I've seen this be a problem on multiple occasions, in particular since it
conflicts with the use of ? as an operator.

I'd like to propose changing the replacement character from ? to instead be
a parameter (like $1).

My main motiviation is to aid external tools that parse pg_stat_statements
output (like [0]), and currently have to resort to complex parser patches
to distinguish operators from replacement characters.

First of all, attached 0001_pgss_additional_regression_tests.v1.patch which
increases regression test coverage for a few scenarios relevant to this
discussion.

Then, there is two variants I've prepared, only one of the two to be
committed:

A) 0002_pgss_mask_with_incrementing_params.v1.patch: Replace constants with
$1, $2, $3 (etc) in the normalized query, whilst respecting any existing
params in the counting

B) 0003_pgss_mask_with_zero_param.v1.patch: Replace constants with $0 in
the normalized query

Ideally I'd see A turn into something we can commit, but it involves a bit
more computation to get the parameter numbers right. The benefit is that we
could use PREPARE/EXECUTE with pg_stat_statements output.

B is intentionally simple, and would address the primary issue at hand
(distinguishing from the ? operator).

I'm also adding this patch to the commitfest starting tomorrow.

Best,
Lukas

[0] https://github.com/lfittl/pg_query#parsing-a-normalized-query

--
Lukas Fittl

Attachment Content-Type Size
0001_pgss_additional_regression_tests.v1.patch application/octet-stream 6.7 KB
0002_pgss_mask_with_incrementing_params.v1.patch application/octet-stream 12.0 KB
0003_pgss_mask_with_zero_param.v1.patch application/octet-stream 10.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2017-03-01 01:36:24 Re: Declarative partitioning optimization for large amount of partitions
Previous Message Rahila Syed 2017-03-01 00:59:28 Adding support for Default partition in partitioning