1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-29 22:49:41 +03:00

Tweak pg_partition_tree for undefined relations and unsupported relkinds

This fixes a crash which happened when calling the function directly
with a relation OID referring to a non-existing object, and changes the
behavior so as NULL is returned for unsupported relkinds instead of
generating an error.  This puts the new function in line with many other
system functions, and eases actions like full scans of pg_class.

Author: Michael Paquier
Reviewed-by: Amit Langote, Stephen Frost
Discussion: https://postgr.es/m/20181207010406.GO2407@paquier.xyz
This commit is contained in:
Michael Paquier
2018-12-12 09:49:39 +09:00
parent 7a28e9aa0f
commit cc53123bcc
3 changed files with 23 additions and 7 deletions

View File

@@ -23,6 +23,7 @@
#include "funcapi.h"
#include "utils/fmgrprotos.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
/*
@@ -42,16 +43,16 @@ pg_partition_tree(PG_FUNCTION_ARGS)
FuncCallContext *funcctx;
ListCell **next;
/* Only allow relation types that can appear in partition trees. */
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(rootrelid)))
PG_RETURN_NULL();
/* Return NULL for relation types that cannot appear in partition trees */
if (relkind != RELKIND_RELATION &&
relkind != RELKIND_FOREIGN_TABLE &&
relkind != RELKIND_INDEX &&
relkind != RELKIND_PARTITIONED_TABLE &&
relkind != RELKIND_PARTITIONED_INDEX)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a table, a foreign table, or an index",
get_rel_name(rootrelid))));
PG_RETURN_NULL();
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())