Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rqFPU-00BNDB-Cx for pgsql-jdbc@arkaria.postgresql.org; Fri, 29 Mar 2024 16:48:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rqFPS-0035Od-LG for pgsql-jdbc@arkaria.postgresql.org; Fri, 29 Mar 2024 16:48:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rqFPS-0035OU-EL for pgsql-jdbc@lists.postgresql.org; Fri, 29 Mar 2024 16:48:54 +0000 Received: from pgintl.fastcrypt.com ([149.56.129.164]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rqFPK-00755l-CZ for pgsql-jdbc@lists.postgresql.org; Fri, 29 Mar 2024 16:48:53 +0000 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by pgintl.fastcrypt.com (Postfix) with ESMTPSA id 68068202FC for ; Fri, 29 Mar 2024 12:48:46 -0400 (EDT) Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-513e89d0816so2423924e87.0 for ; Fri, 29 Mar 2024 09:48:46 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWI/wx3ul8iXQmQ0nSp/mdbTwSELbY6dQEge54j+W35viujralgrFCwdsBbgHUljdtBukd44WODBIVCAwPvEz87uMPrzilBWYmG3JcB/B9G X-Gm-Message-State: AOJu0Yxr93dxSyMBtvAfGf9UkRakNIiw0akmTd5gLQUw7L3SmXA0DMkL PFgx64QqzDJv2zETtZvZkw1+/CffeRc9X0U4IpxEx4UQwkElus9kNCG0q7NHTA9F4+/sfyrZum3 f410aXGTydfZGNYXU1pKje/f1ijo= X-Google-Smtp-Source: AGHT+IEReclK53gjCSxdCAJzmxnLkKAashC2diZYR8JbrHSPRopQKaT6K/kqdaQ3paRkAJ0oV9peLtpMRu9i5TOg5dU= X-Received: by 2002:a05:6512:3e4:b0:515:c0ca:d9e6 with SMTP id n4-20020a05651203e400b00515c0cad9e6mr1744971lfq.38.1711730924119; Fri, 29 Mar 2024 09:48:44 -0700 (PDT) MIME-Version: 1.0 References: <60ab210d02748b5da813007ab2504606d0fecaa1.camel@cybertec.at> <2950.1711729266@sss.pgh.pa.us> In-Reply-To: <2950.1711729266@sss.pgh.pa.us> From: Dave Cramer Date: Fri, 29 Mar 2024 12:48:26 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: cached plan must not change result type To: Tom Lane Cc: James Pang , pgsql-jdbc@lists.postgresql.org, Laurenz Albe Content-Type: multipart/alternative; boundary="000000000000aefb9b0614cf69d1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000aefb9b0614cf69d1 Content-Type: text/plain; charset="UTF-8" On Fri, 29 Mar 2024 at 12:21, Tom Lane wrote: > Dave Cramer writes: > > This is really an issue that needs to be solved in the backend. The error > > is coming from PostgreSQL and what should happen is that when you alter a > > table that a server prepared statement relies on the backend should send > a > > message to tell us that all of the prepared statements that rely on are > now > > invalid and we can reprepare them. > > This is something that can't change without a wire protocol change. > There is nothing in the protocol that allows the backend to send out > a message like "oh, that Describe I sent you awhile back? It might > be a lie now" at random times. I agree, but it's a known issue. I'm just pointing that it would be nice to have. We'd have to figure out the details. > Also, what do you want to do about > race conditions --- that is, what if you fire off an Execute only > to find that one of those messages was already in flight to you? > A non-racy way to handle it might be for Bind/Execute to refuse to > run the query if its output has changed since the last Describe, > which we could check after acquiring table locks during Bind. > But we'd want to define "refuse" in a way that doesn't abort the > transaction, and that's a concept that doesn't exist in the > protocol at all. > This actually sounds like the best option as we wouldn't have to fire off a message, just refuse to run the Execute in a way that doesn't abort the transaction. Dave --000000000000aefb9b0614cf69d1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, 29 Mar 2024 at 12:21, Tom Lan= e <tgl@sss.pgh.pa.us> wrote:=
Dave Cramer <= ;davecramer@postgres.rocks> writes:
> This is really an issue that needs to be solved in the backend. The er= ror
> is coming from PostgreSQL and what should happen is that when you alte= r a
> table that a server prepared statement relies on the backend should se= nd a
> message to tell us that all of the prepared statements that rely on ar= e now
> invalid and we can reprepare them.

This is something that can't change without a wire protocol change.
There is nothing in the protocol that allows the backend to send out
a message like "oh, that Describe I sent you awhile back?=C2=A0 It mig= ht
be a lie now" at random times.=C2=A0

= I agree, but it's a known=C2=A0issue. I'm just pointing that it wou= ld be nice to have.
We'd have to figure out the details.
=C2=A0
Also, w= hat do you want to do about
race conditions --- that is, what if you fire off an Execute only
to find that one of those messages was already in flight to you?

A non-racy way to handle it might be for Bind/Execute to refuse to
run the query if its output has changed since the last Describe,
which we could check after acquiring table locks during Bind.
But we'd want to define "refuse" in a way that doesn't ab= ort the
transaction, and that's a concept that doesn't exist in the
protocol at all.

This actually sounds l= ike the best option as we wouldn't have to fire off a message, just ref= use to run the Execute in a way that doesn't abort the transaction.

Dave
--000000000000aefb9b0614cf69d1--