partition-funcs-tweak.patch
text/x-diff
Filename: partition-funcs-tweak.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/utils/adt/partitionfuncs.c | 3 | 10 |
| src/test/regress/expected/partition_info.out | 5 | 6 |
| src/test/regress/sql/partition_info.sql | 1 | 1 |
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c
index 36d9f69cbc..a2fe4f34b6 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);
diff --git a/src/test/regress/expected/partition_info.out b/src/test/regress/expected/partition_info.out
index 73269ffd09..24e3fe60f3 100644
--- a/src/test/regress/expected/partition_info.out
+++ b/src/test/regress/expected/partition_info.out
@@ -138,19 +138,18 @@ SELECT relid, parentrelid, level, isleaf
(6 rows)
DROP TABLE ptif_test;
--- Table that is not part of any partition tree is the only member listed.
+-- Table that is not part of any partition tree is not listed.
CREATE TABLE ptif_normal_table(a int);
SELECT relid, parentrelid, level, isleaf
FROM pg_partition_tree('ptif_normal_table');
- relid | parentrelid | level | isleaf
--------------------+-------------+-------+--------
- ptif_normal_table | | 0 | t
-(1 row)
+ relid | parentrelid | level | isleaf
+-------+-------------+-------+--------
+(0 rows)
SELECT pg_partition_root('ptif_normal_table');
pg_partition_root
-------------------
- ptif_normal_table
+
(1 row)
DROP TABLE ptif_normal_table;
diff --git a/src/test/regress/sql/partition_info.sql b/src/test/regress/sql/partition_info.sql
index 119b90afe4..d9dfa5d5d7 100644
--- a/src/test/regress/sql/partition_info.sql
+++ b/src/test/regress/sql/partition_info.sql
@@ -64,7 +64,7 @@ SELECT relid, parentrelid, level, isleaf
DROP TABLE ptif_test;
--- Table that is not part of any partition tree is the only member listed.
+-- Table that is not part of any partition tree is not listed.
CREATE TABLE ptif_normal_table(a int);
SELECT relid, parentrelid, level, isleaf
FROM pg_partition_tree('ptif_normal_table');