aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/partitionfuncs.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-03-22 17:27:38 +0900
committerMichael Paquier <michael@paquier.xyz>2019-03-22 17:27:38 +0900
commit2ab6d28d233af17987ea323e3235b2bda89b4f2e (patch)
tree6bf3a4fac6e23fd3248972948d7cd8fab1bbf944 /src/backend/utils/adt/partitionfuncs.c
parentfff518d051285bc47e2694a349d410e01972730b (diff)
downloadpostgresql-2ab6d28d233af17987ea323e3235b2bda89b4f2e.tar.gz
postgresql-2ab6d28d233af17987ea323e3235b2bda89b4f2e.zip
Fix crash with pg_partition_root
Trying to call the function with the top-most parent of a partition tree was leading to a crash. In this case the correct result is to return the top-most parent itself. Reported-by: Álvaro Herrera Author: Michael Paquier Reviewed-by: Amit Langote Discussion: https://postgr.es/m/20190322032612.GA323@alvherre.pgsql
Diffstat (limited to 'src/backend/utils/adt/partitionfuncs.c')
-rw-r--r--src/backend/utils/adt/partitionfuncs.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c
index 98c8ef77f17..714a0242a18 100644
--- a/src/backend/utils/adt/partitionfuncs.c
+++ b/src/backend/utils/adt/partitionfuncs.c
@@ -189,8 +189,16 @@ pg_partition_root(PG_FUNCTION_ARGS)
if (!check_rel_can_be_partition(relid))
PG_RETURN_NULL();
- /* Fetch the top-most parent */
+ /* fetch the list of ancestors */
ancestors = get_partition_ancestors(relid);
+
+ /*
+ * If the input relation is already the top-most parent, just return
+ * itself.
+ */
+ if (ancestors == NIL)
+ PG_RETURN_OID(relid);
+
rootrelid = llast_oid(ancestors);
list_free(ancestors);