postgresql/src/backend
Tom Lane aaf10f32a3 Fix assorted bugs in pg_get_partition_constraintdef().
It failed if passed a nonexistent relation OID, or one that was a non-heap
relation, because of blindly applying heap_open to a user-supplied OID.
This is not OK behavior for a SQL-exposed function; we have a project
policy that we should return NULL in such cases.  Moreover, since
pg_get_partition_constraintdef ought now to work on indexes, restricting
it to heaps is flat wrong anyway.

The underlying function generate_partition_qual() wasn't on board with
indexes having partition quals either, nor for that matter with rels
having relispartition set but yet null relpartbound.  (One wonders
whether the person who wrote the function comment blocks claiming that
these functions allow a missing relpartbound had ever tested it.)

Fix by testing relispartition before opening the rel, and by using
relation_open not heap_open.  (If any other relkinds ever grow the
ability to have relispartition set, the code will work with them
automatically.)  Also, don't reject null relpartbound in
generate_partition_qual.

Back-patch to v11, and all but the null-relpartbound change to v10.
(It's not really necessary to change generate_partition_qual at all
in v10, but I thought s/heap_open/relation_open/ would be a good
idea anyway just to keep the code in sync with later branches.)

Per report from Justin Pryzby.

Discussion: https://postgr.es/m/20180927200020.GJ776@telsasoft.com
2018-09-27 18:15:17 -04:00
..
access Minor formatting cleanup for 2a6368343f 2018-09-27 23:29:50 +03:00
bootstrap Install a check for mis-linking of src/port and src/common functions. 2018-09-09 12:23:23 -04:00
catalog Split ExecStoreTuple into ExecStoreHeapTuple and ExecStoreBufferHeapTuple. 2018-09-25 16:27:48 -07:00
commands Recurse to sequences on ownership change for all relkinds 2018-09-26 20:19:15 +02:00
executor Remove absolete function TupleDescGetSlot(). 2018-09-25 16:28:57 -07:00
foreign Remove bogus "extern" annotations on function definitions. 2018-02-19 12:07:44 -05:00
jit Change TupleTableSlot->tts_nvalid to type AttrNumber. 2018-09-25 15:59:46 -07:00
lib Implement %m in src/port/snprintf.c, and teach elog.c to rely on that. 2018-09-26 13:31:56 -04:00
libpq Minor cleanup/future-proofing for pg_saslprep(). 2018-09-08 18:20:36 -04:00
main Update copyright for 2018 2018-01-02 23:30:12 -05:00
nodes Add a debugging option to stress-test outfuncs.c and readfuncs.c. 2018-09-18 17:11:54 -04:00
optimizer Fix some minor issues exposed by outfuncs/readfuncs testing. 2018-09-18 15:08:28 -04:00
parser Update dummy CREATE ASSERTION grammar 2018-09-26 13:26:24 +02:00
partitioning Split ExecStoreTuple into ExecStoreHeapTuple and ExecStoreBufferHeapTuple. 2018-09-25 16:27:48 -07:00
po Translation updates 2018-06-25 12:37:18 +02:00
port Convert elog.c's useful_strerror() into a globally-used strerror wrapper. 2018-09-26 11:06:42 -04:00
postmaster Refactor dlopen() support 2018-09-06 11:33:04 +02:00
regex Clean up warnings from -Wimplicit-fallthrough. 2018-05-01 19:35:08 -04:00
replication Split ExecStoreTuple into ExecStoreHeapTuple and ExecStoreBufferHeapTuple. 2018-09-25 16:27:48 -07:00
rewrite Fix some minor issues exposed by outfuncs/readfuncs testing. 2018-09-18 15:08:28 -04:00
snowball Sync our Snowball stemmer dictionaries with current upstream. 2018-09-24 17:29:38 -04:00
statistics Fix typos. 2018-08-27 09:32:59 +12:00
storage Replace CAS loop with single TAS in ProcArrayGroupClearXid() 2018-09-22 16:22:30 +03:00
tcop Add a debugging option to stress-test outfuncs.c and readfuncs.c. 2018-09-18 17:11:54 -04:00
tsearch Hand code string to integer conversion for performance. 2018-07-22 14:58:23 -07:00
utils Fix assorted bugs in pg_get_partition_constraintdef(). 2018-09-27 18:15:17 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Refactor dlopen() support 2018-09-06 11:33:04 +02:00
nls.mk Translation updates 2018-06-25 12:37:18 +02:00