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 1rqEQB-00BIRq-Nj for pgsql-jdbc@arkaria.postgresql.org; Fri, 29 Mar 2024 15:45:36 +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 1rqEQA-002UI3-HM for pgsql-jdbc@arkaria.postgresql.org; Fri, 29 Mar 2024 15:45:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rqEQA-002UHv-9v for pgsql-jdbc@lists.postgresql.org; Fri, 29 Mar 2024 15:45:34 +0000 Received: from pgintl.fastcrypt.com ([149.56.129.164]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rqEQ6-007JUh-Vn for pgsql-jdbc@lists.postgresql.org; Fri, 29 Mar 2024 15:45:33 +0000 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by pgintl.fastcrypt.com (Postfix) with ESMTPSA id D0278201BA for ; Fri, 29 Mar 2024 11:45:26 -0400 (EDT) Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a4715991c32so266210266b.1 for ; Fri, 29 Mar 2024 08:45:26 -0700 (PDT) X-Gm-Message-State: AOJu0YzdgMQEAf8w0PLmEhctzJeLCn+jVSQ6XkNiJ7QqqvyR4IdDz+vT c33D+0cZdyDwlvBCNeg24BYM5Jg66N13doC8LLuuS0y2rusoQVyoyh7XvkTTrhyF4AGaIFSJskT xx3b/hs8HPjTCh4KqWI6krOVKn8M= X-Google-Smtp-Source: AGHT+IG+DFu9dbOoeNmmEAWjwyfJDQAo05CTRZpIClFAioYLmGaicupeCpt1a3MhW6/7avA4R8p+zxP7LVKtfcBVWCI= X-Received: by 2002:a17:906:f80b:b0:a4e:280d:6a5f with SMTP id kh11-20020a170906f80b00b00a4e280d6a5fmr1652482ejb.16.1711727125847; Fri, 29 Mar 2024 08:45:25 -0700 (PDT) MIME-Version: 1.0 References: <60ab210d02748b5da813007ab2504606d0fecaa1.camel@cybertec.at> In-Reply-To: From: Dave Cramer Date: Fri, 29 Mar 2024 11:45:09 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: cached plan must not change result type To: James Pang Cc: pgsql-jdbc@lists.postgresql.org, Laurenz Albe Content-Type: multipart/alternative; boundary="00000000000049ee6a0614ce8746" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000049ee6a0614ce8746 Content-Type: text/plain; charset="UTF-8" On Fri, 29 Mar 2024 at 05:09, James Pang wrote: > forwarded to pgjdbc, we want to understand why JDBC failed to reexecute > the SQL instead of throw error out. Like this document > https://jdbc.postgresql.org/documentation/server-prepare/#re-execution-of-failed-statements > . > > > > protected final void execute(CachedQuery cachedQuery, > @Nullable ParameterList queryParameters, int flags) > throws SQLException { > try { > executeInternal(cachedQuery, queryParameters, flags); > } catch (SQLException e) { > // Don't retry composite queries as it might get partially executed > if (cachedQuery.query.getSubqueries() != null > <<< no idea how this cachedQuery.query.getSubqueries() != null > || !connection.getQueryExecutor().willHealOnRetry(e)) { > throw e; > } > cachedQuery.query.close(); > // Execute the query one more time > executeInternal(cachedQuery, queryParameters, flags); > } > } > > cachedQuery.query.getSubqueries() != null, how this code decide composite > queries here ? that mean some query having subquery or having many JOIN > or LEFT JOINs like select .... A left join B ... > > Thanks, > > James > 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. Currently the driver has no idea that you changed the table and the prepared statement will fail so it just continues to use it. Dave --00000000000049ee6a0614ce8746 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, 29 Mar 2024 at 05:09, James P= ang <jamespang886@gmail.com> wrote:

protec= ted final void execute(CachedQuery cachedQuery,
=C2=A0 =C2=A0 =C2=A0 @Nu= llable ParameterList queryParameters, int flags)
=C2=A0 =C2=A0 =C2=A0 th= rows SQLException {
=C2=A0 =C2=A0 try {
=C2=A0 =C2=A0 =C2=A0 executeI= nternal(cachedQuery, queryParameters, flags);
=C2=A0 =C2=A0 } catch (SQL= Exception e) {
=C2=A0 =C2=A0 =C2=A0 // Don't retry composite queries= as it might get partially executed
=C2=A0 =C2=A0 =C2=A0 if (cachedQuery= .query.getSubqueries() !=3D null=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0<<< no idea how this=C2=A0 cachedQuery.query.getSubqueries() !=3D null
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 || !connection.getQueryExecutor().willHealOnRetry(e)) {
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 throw e;
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 = =C2=A0 cachedQuery.query.close();
=C2=A0 =C2=A0 =C2=A0 // Execute the qu= ery one more time
=C2=A0 =C2=A0 =C2=A0 executeInternal(cachedQuery, quer= yParameters, flags);
=C2=A0 =C2=A0 }
=C2=A0 }

= cachedQuery.query.getSubqueries() !=3D null, how this code decide composite= queries=C2=A0 here ?=C2=A0 =C2=A0that mean some query having subquery or h= aving many JOIN or LEFT JOINs like=C2=A0 select .... A left join B ...
<= /div>

Thanks,

James=C2=A0
=

This is really an issue that needs t= o be solved in the backend. The error is coming from PostgreSQL and what sh= ould 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 pre= pared statements that rely on are now invalid and we can reprepare them. Cu= rrently the driver has no idea that you changed the table and the prepared = statement will fail so it just continues to use it.

Dave
--00000000000049ee6a0614ce8746--