pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: CN <cnliou9@fastmail.fm>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #14483: Prepared statement does not re-plan while it should
Date: Tue, 03 Jan 2017 15:25:26 +0800
Message-ID: <1483428326.1346104.835592537.16DDF6CD@webmail.messagingengine.com> (raw)
In-Reply-To: <16871.1483373067@sss.pgh.pa.us>
References: <20170102154014.10135.49515@wrigleys.postgresql.org>
	<16871.1483373067@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

> This behavior is intentional: it's to keep applications from having to
> deal with the possibility that they prepare a statement, Describe it
> to find out what columns it returns, and then when they actually execute
> it, it returns some other column set.

Many thanks for the clarification!

I am not sure if it is appropriate to turn this bug report into feature
request, again.  We will get several results by searching key phrase
"cached plan must not change result type".

It will be much easier for me to use prepared statements if they are
automatically re-parsed after any DDL that affects them or "SET
SEARCH_PATH TO" is executed. I believe this is especially true where
connection pool products are used.

Even without using connections pooling, the following example shows that
simple usage can also cause production applications to malfunction -
they get the error when developers are also changing the database
schema:

====
test=# CREATE TABLE t1 (c1 INTEGER);
CREATE TABLE
test=# PREPARE p1 AS SELECT c1 FROM t1;
PREPARE
test=# EXECUTE p1;
 c1 
----
(0 rows)

test=# ALTER TABLE t1 ALTER c1 TYPE TEXT;
ALTER TABLE
test=# EXECUTE p1;
ERROR:  cached plan must not change result type
====

Once an application encounters this problem, disconnecting from the
database and reconnecting back, which usually means restarting the
application, seems to be the only way to "fix" it.

Although deallocating prepared statements wherever necessary ultimately
avoids this issue, it is complicated for me to correctly implement such
applications. As a result, I currently avoid using prepared statements
altogether and hence obviously greatly degrade the overall performance.

Best Regards,
CN

-- 
http://www.fastmail.com - Choose from over 50 domains or use your own



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (5+ messages)  latest in thread

Message-ID: <1483428326.1346104.835592537.16DDF6CD@webmail.messagingengine.com>
Permalink:  ../1483428326.1346104.835592537.16DDF6CD@webmail.messagingengine.com/
Also on:    postgresql.org/message-id/1483428326.1346104.835592537.16DDF6CD@webmail.messagingengine.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: cnliou9@fastmail.fm
  Subject: Re: BUG #14483: Prepared statement does not re-plan while it should
  In-Reply-To: <1483428326.1346104.835592537.16DDF6CD@webmail.messagingengine.com>
  References: <20170102154014.10135.49515@wrigleys.postgresql.org> <16871.1483373067@sss.pgh.pa.us> <1483428326.1346104.835592537.16DDF6CD@webmail.messagingengine.com>

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

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