Re: Support prepared statement invalidation when result types change

From: Jelte Fennema-Nio <me(at)jeltef(dot)nl>
To: Shay Rojansky <roji(at)roji(dot)org>
Cc: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Support prepared statement invalidation when result types change
Date: 2024-04-03 10:48:02
Message-ID: CAGECzQQJTZAPqLfcLkTg7ftt=WFSJVdZAsfjriOOBwp9GN8KGA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, 7 Jan 2024 at 07:55, vignesh C <vignesh21(at)gmail(dot)com> wrote:
> One of the test has aborted in CFBot at [1] with:

Rebased the patchset and removed patch 0003 since it was causing the
CI issue reported by vignesh and it seems much less useful and more
controversial to me anyway (due to the extra required roundtrip).

On Sun, 7 Jan 2024 at 09:17, Shay Rojansky <roji(at)roji(dot)org> wrote:
> Just to point out, FWIW, that the .NET Npgsql driver does indeed cache RowDescriptions... The whole point of preparation is to optimize things as much as possible for repeated execution of the query; I get that the value there is much lower than e.g. doing another network roundtrip, but that's still extra work that's better off being cut if it can be.

Hmm, interesting. I totally agree that it's always good to do less
when possible. The problem is that in the face of server side prepared
statement invalidations due to DDL changes to the table or search path
changes, the row types might change. Or the server needs to constantly
throw an error, like it does now, but that seems worse imho.

I'm wondering though if we can create a middleground, where a client
can still cache the RowDescription client side when no DDL or
search_patch changes are happening. But still tell the client about a
new RowDescription when they do happen.

The only way of doing that I can think of is changing the Postgres
protocol in a way similar to this: Allow Execute to return a
RowDescription too, but have the server only do so when the previously
received RowDescription for this prepared statement is now invalid.

This would definitely require some additional tracking at PgBouncer to
make it work, i.e. per client and per server it should now keep track
of the last RowDescription for each prepared statement. But that's
definitely something we could do.

This would make this patch much more involved though, as now it would
suddenly involve an actual protocol change, and that basically depends
on this patch moving forward[1].

[1]: https://www.postgresql.org/message-id/flat/CAGECzQTg2hcmb5GaU53uuWcdC7gCNJFLL6mnW0WNhWHgq9UTgw(at)mail(dot)gmail(dot)com

Attachment Content-Type Size
v6-0002-Completely-remove-fixed_result-from-CachedPlanSou.patch application/octet-stream 7.4 KB
v6-0001-Support-prepared-statement-invalidation-when-resu.patch application/octet-stream 8.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2024-04-03 10:49:46 Re: Introduce XID age and inactive timeout based replication slot invalidation
Previous Message Nazir Bilal Yavuz 2024-04-03 10:31:00 Re: Use streaming read API in ANALYZE