pg_get_constraintdef failing with cache lookup error

Started by Michael Paquieralmost 11 years ago4 messagesbugs
Jump to latest
#1Michael Paquier
michael@paquier.xyz

Hi all,

pg_get_constraintdef() fails rather easily:
=# select pg_get_constraintdef(1);
ERROR: cache lookup failed for constraint 1
STATEMENT: select pg_get_constraintdef(1);
ERROR: XX000: cache lookup failed for constraint 1
LOCATION: pg_get_constraintdef_worker, ruleutils.c:1305

Now by looking at pg_get_constraintdef_worker()@ruleutils.c it is
commented that this error should never happen:
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for constraint %u",
constraintId);
But it happens.
Am I missing something? Shouldn't this error be changed into something
more informative?
Regards,
--
Michael

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Paquier (#1)
Re: pg_get_constraintdef failing with cache lookup error

Michael Paquier <michael.paquier@gmail.com> writes:

pg_get_constraintdef() fails rather easily:
=# select pg_get_constraintdef(1);
ERROR: cache lookup failed for constraint 1

It's expected that the caller will supply a valid pg_constraint OID.
I don't think it's necessary to go out of our way to throw a friendlier
error message if the OID isn't found.

regards, tom lane

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

#3Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#2)
Re: pg_get_constraintdef failing with cache lookup error

On Mon, Apr 27, 2015 at 11:16 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Michael Paquier <michael.paquier@gmail.com> writes:

pg_get_constraintdef() fails rather easily:
=# select pg_get_constraintdef(1);
ERROR: cache lookup failed for constraint 1

It's expected that the caller will supply a valid pg_constraint OID.
I don't think it's necessary to go out of our way to throw a friendlier
error message if the OID isn't found.

It's clearly at least a bug in the comment to complain that it can't
happen if in fact it can. But I would argue that we should never hit
an elog just because of bad user input.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

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

#4Michael Paquier
michael@paquier.xyz
In reply to: Robert Haas (#3)
Re: pg_get_constraintdef failing with cache lookup error

On Tue, Apr 28, 2015 at 3:15 AM, Robert Haas <robertmhaas@gmail.com> wrote:

On Mon, Apr 27, 2015 at 11:16 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Michael Paquier <michael.paquier@gmail.com> writes:

pg_get_constraintdef() fails rather easily:
=# select pg_get_constraintdef(1);
ERROR: cache lookup failed for constraint 1

It's expected that the caller will supply a valid pg_constraint OID.
I don't think it's necessary to go out of our way to throw a friendlier
error message if the OID isn't found.

It's clearly at least a bug in the comment to complain that it can't
happen if in fact it can. But I would argue that we should never hit
an elog just because of bad user input.

Fine for me to just remove the comment, constraintdef is the only *def
function that has such one.
--
Michael

Attachments:

20150428_constraint_def_fix_comment.patchapplication/x-patch; name=20150428_constraint_def_fix_comment.patchDownload+1-1