Re: Support prepared statement invalidation when result types change

From: Jelte Fennema-Nio <me(at)jeltef(dot)nl>
To: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Support prepared statement invalidation when result types change
Date: 2023-09-18 11:30:48
Message-ID: CAGECzQT75nXBpODkBjLM6BvAWr=TxFQtxuF8d==X9huVjeX0-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

@Euler thanks for the review. I addressed the feedback.

On Fri, 15 Sept 2023 at 01:41, Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> wrote:
> What if a client has *cached* an old version of RowDescription
> and the server changed it to something new and sent resultdata
> with the new RowDescription. Will the client still be able to work
> expectly?

It depends a bit on the exact change. For instance a column being
added to the end of the resultdata shouldn't be a problem. And that is
actually quite a common case for this issue:
1. PREPARE p as (SELECT * FROM t);
2. ALTER TABLE t ADD COLUMN ...
3. EXECUTE p

But type changes of existing columns might cause issues when the
RowDescription is cached. But such changes also cause issues now.
Currently the prepared statement becomes unusable when this happens
(returning errors every time). With this patch it's at least possible
to have prepared statements continue working in many cases.
Furthermore caching RowDescription is also not super useful, most
clients request it every time because it does not require an extra
round trip, so there's almost no overhead in requesting it.

Clients caching ParameterDescription seems more useful because
fetching the parameter types does require an extra round trip. So
caching it could cause errors with 0003. But right now if the argument
types need to change it gives an error every time when executing the
prepared statement. So I believe 0003 is still an improvement over the
status quo, because there are many cases where the client knows that
the types might have changed and it thus needs to re-fetch the
ParameterDescription: the most common case is changing the
search_path. And there's also cases where even a cached
ParamaterDescription will work fine: e.g. the type is changed but the
encoding stays the same (e.g. drop + create an enum, or text/varchar,
or the text encoding of int and bigint)

Attachment Content-Type Size
v5-0003-Support-changing-argument-types-of-prepared-state.patch application/octet-stream 18.5 KB
v5-0002-Completely-remove-fixed_result-from-CachedPlanSou.patch application/octet-stream 7.4 KB
v5-0001-Support-prepared-statement-invalidation-when-resu.patch application/octet-stream 8.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2023-09-18 11:39:35 Re: Infinite Interval
Previous Message Zhijie Hou (Fujitsu) 2023-09-18 11:16:41 RE: [PoC] pg_upgrade: allow to upgrade publisher node