aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/partitionfuncs.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-03-02 18:18:59 +0900
committerMichael Paquier <michael@paquier.xyz>2019-03-02 18:18:59 +0900
commit3422955735d9b2623532c60c53cb885c9cb6e3b1 (patch)
treebd11dd3f56e057637fcbf6086dcab0cbdf07b0d5 /src/backend/utils/adt/partitionfuncs.c
parent70b9bda65f8174e24eef5d8967705485a314a82e (diff)
downloadpostgresql-3422955735d9b2623532c60c53cb885c9cb6e3b1.tar.gz
postgresql-3422955735d9b2623532c60c53cb885c9cb6e3b1.zip
Consider only relations part of partition trees in partition functions
This changes the partition functions so as tables and indexes which are not part of partition trees are handled the same way as what is done for undefined objects and unsupported relkinds: pg_partition_tree() returns no rows and pg_partition_root() returns a NULL result. Hence, partitioned tables, partitioned indexes and relations whose flag pg_class.relispartition is set are considered as valid objects to process. Previously, tables and indexes not included in a partition tree were processed the same way as a partition or a partitioned table, which caused the functions to return inconsistent results for inherited tables, especially when inheriting from multiple tables. Reported-by: Álvaro Herrera Author: Amit Langote, Michael Paquier Reviewed-by: Tom Lane Discussion: https://postgr.es/m/20190228193203.GA26151@alvherre.pgsql
Diffstat (limited to 'src/backend/utils/adt/partitionfuncs.c')
-rw-r--r--src/backend/utils/adt/partitionfuncs.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c
index 36d9f69cbcc..a2fe4f34b6d 100644
--- a/src/backend/utils/adt/partitionfuncs.c
+++ b/src/backend/utils/adt/partitionfuncs.c
@@ -35,17 +35,17 @@ static bool
check_rel_can_be_partition(Oid relid)
{
char relkind;
+ bool relispartition;
/* Check if relation exists */
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(relid)))
return false;
relkind = get_rel_relkind(relid);
+ relispartition = get_rel_relispartition(relid);
/* Only allow relation types that can appear in partition trees. */
- if (relkind != RELKIND_RELATION &&
- relkind != RELKIND_FOREIGN_TABLE &&
- relkind != RELKIND_INDEX &&
+ if (!relispartition &&
relkind != RELKIND_PARTITIONED_TABLE &&
relkind != RELKIND_PARTITIONED_INDEX)
return false;
@@ -189,13 +189,6 @@ pg_partition_root(PG_FUNCTION_ARGS)
if (!check_rel_can_be_partition(relid))
PG_RETURN_NULL();
- /*
- * If the relation is not a partition (it may be the partition parent),
- * return itself as a result.
- */
- if (!get_rel_relispartition(relid))
- PG_RETURN_OID(relid);
-
/* Fetch the top-most parent */
ancestors = get_partition_ancestors(relid);
rootrelid = llast_oid(ancestors);