public inbox for [email protected]  
help / color / mirror / Atom feed
From: Sami Imseih <[email protected]>
To: Julien Rouhaud <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: Cleaning up PREPARE query strings?
Date: Thu, 15 Jan 2026 13:13:36 -0600
Message-ID: <CAA5RZ0sHJ2D2vdhH4nnUVuZKfSqpaywPeP98C9-LkGKG2rPSYg@mail.gmail.com> (raw)
In-Reply-To: <aWhv-ZXEJ3kd-dWa@jrouhaud>
References: <aUwKEWGge5jWtaRX@jrouhaud>
	<[email protected]>
	<aWNWO8wEvu6YQaKN@jrouhaud>
	<CAA5RZ0sswD2h2w8FkVjToA=3oNYUb1mW-zuCD=J6DDK2zuLuZg@mail.gmail.com>
	<aWbMU6wKpYkJHPP5@jrouhaud>
	<CAA5RZ0s4UPJ5uHzcfDqOLOskOFTPFZnUZwZS7e93LTmG8nHVnA@mail.gmail.com>
	<aWhv-ZXEJ3kd-dWa@jrouhaud>

> I only had a quick look at the code but unless I'm missing something it's
> mostly an oversight as I pass "new_query" to CreateCachedPlan() but still pass
> the original query string to pg_analyze_and_rewrite_varparams().  Using
> "new_query" there too should fix the problem?

That will be a fix, but that seems way too invasive for me. Not sure if it may
break other things.

> > I am thinking that storing the statement length and location in the entry
> > of prepared_queries may be the better option. Having that info, the
> > cleaned up query text can be generated on the fly whenever
> > pg_prepared_statement is called.
>
> I don't like this approach as it has more execution time overhead, but also
> doesn't fix at all the memory waste in the prepared statements cache.

ISTM that your proposal will actually use more memory because
pstate->p_sourcetext does not get free'd, but we must now allocate
space for a new "cleaned" query.

As far as execution overhead, this will only be paid when you query
pg_prepared_statement, and we can even optimize this a bit by only
cleaning once and reusing the results.

> FWIW I think that this should belong to pg_stat_statements testing, no the main
> regression tests.  This would also ensure that we see consistent results in
> some other scenarios.

I agree.

--
Sami Imseih
Amazon Web Services (AWS)






view thread (7+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Cleaning up PREPARE query strings?
  In-Reply-To: <CAA5RZ0sHJ2D2vdhH4nnUVuZKfSqpaywPeP98C9-LkGKG2rPSYg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox