pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joe Van Dyk <joe@tanga.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: plpgsql plan caching allowing invalid data to enter table?
Date: Tue, 09 Jul 2013 19:42:33 -0400
Message-ID: <7165.1373413353@sss.pgh.pa.us> (raw)
In-Reply-To: <CACfv+pJUbc5Kg7HQ-xSpw_HDhExZWOWhff0pVyADb24bkokaaQ@mail.gmail.com>
References: <CACfv+pJUbc5Kg7HQ-xSpw_HDhExZWOWhff0pVyADb24bkokaaQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>

Joe Van Dyk <joe@tanga.com> writes:
> It's looking like I can use a plpgsql function to insert data into a table
> that violates a domain constraint. Is this a known problem?

I think it's not really plpgsql's fault but domain_in's --- there's no
provision for flushing the latter's cached info about how to check
domain constraints.  (You can't see this in simple commands because
the cache only lives as long as the statement, but I think plpgsql
is letting it get put into the function's definitional memory context,
which will pretty much survive for the whole session if you don't
redefine the function.)

We could ameliorate this case and probably improve performance as well
by keeping domain check info in the typcache rather than using ad-hoc
storage for it.

However, I think it's a mistake to imagine that there's ever going to be
a bulletproof guarantee that you can whack domain constraints around
in a live database and not have any risk of some data going unchecked.
As a couple of examples:

* suppose you do the ALTER DOMAIN, and commit it at an instant where
the plpgsql function is actively executing and has a live variable
value of that domain type.  Nothing is going to make the constraint
change apply retroactively to that variable.

* suppose you don't do an ALTER DOMAIN at all, but just change the
behavior of a function that's used in a check constraint.

			regards, tom lane


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



view thread (6+ messages)

Message-ID: <7165.1373413353@sss.pgh.pa.us>
Permalink:  ../7165.1373413353@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/7165.1373413353@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, joe@tanga.com, pgsql-general@postgresql.org
  Subject: Re: plpgsql plan caching allowing invalid data to enter table?
  In-Reply-To: <7165.1373413353@sss.pgh.pa.us>
  References: <CACfv+pJUbc5Kg7HQ-xSpw_HDhExZWOWhff0pVyADb24bkokaaQ@mail.gmail.com> <7165.1373413353@sss.pgh.pa.us>

* 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