Re: BUG: pg_stat_statements query normalization issues with combined queries

Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>

From: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
To: robertmhaas@gmail.com
Cc: coelho@cri.ensmp.fr, pgsql-hackers@postgresql.org
Date: 2016-12-21T05:19:47Z
Lists: pgsql-hackers
At Tue, 20 Dec 2016 22:42:48 -0500, Robert Haas <robertmhaas@gmail.com> wrote in <CA+TgmoZT94brLAGK7gCmxB4mO=C-Cdz1N8KN8Xen4sexHozN=Q@mail.gmail.com>
> On Tue, Dec 20, 2016 at 6:18 AM, Fabien COELHO <coelho@cri.ensmp.fr> wrote:
> > Would this approach be acceptable, or is modifying Nodes a no-go area?
> >
> > If it is acceptable, I can probably put together a patch and submit it.
> >
> > If not, I suggest to update the documentation to tell that
> > pg_stat_statements does not work properly with combined queries.
> 
> I think you've found a bug, but I'm a little doubtful about your
> proposed fix.  However, I haven't studied the code, so I don't know
> what other approach might be better.

That will work and doable, but the more fundamental issue here
seems to be that post_parse_analyze_hook or other similar hooks
are called with a Query incosistent with query_debug_string. It
is very conveniently used but the name seems to me to be
suggesting that such usage is out of purpose. I'm not sure,
though.

A similar behavior is shown in error messages but this harms far
less than the case of pg_stat_statements.

ERROR:  column "b" does not exist
LINE 1: ...elect * from t where a = 1; select * from t where b = 2; com...
                                                             ^


1. Let all of the parse node have location in
  debug_query_string. (The original proposal)

2. Let the parser return once for each statement (like psql
   parser) and corresponding query string is stored in a
   varialble other than debug_query_string.

...


regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center




Commits

  1. Teach contrib/pg_stat_statements to handle multi-statement commands better.

  2. Change representation of statement lists, and add statement location info.

  3. Revert my bad decision of about a year ago to make PortalDefineQuery