0002-Flip-logic-in-table-validate_relation_kind.patch
text/plain
Filename: 0002-Flip-logic-in-table-validate_relation_kind.patch
Type: text/plain
Part: 1
Patch
Format: format-patch
Series: patch 0002
Subject: Flip logic in table validate_relation_kind
| File | + | − |
|---|---|---|
| src/backend/access/table/table.c | 9 | 4 |
From 2cd2bf31d5adb6fcdbb4528018de700094075936 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 18 Feb 2026 14:32:45 +0100
Subject: [PATCH 2/2] Flip logic in table validate_relation_kind
It instead of checking which relkinds it shouldn't be, explicitly list
the ones we accept. This is used to check which relkinds are accepted
in table_open() and related functions. Before this change, figuring
that out was always a few steps too complicated. This also makes
changes for new relkinds more explicit instead of accidental.
Finally, this makes this more aligned with the functions of the same
name in src/backend/access/index/indexam.c and
src/backend/access/sequence/sequence.c.
---
src/backend/access/table/table.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/backend/access/table/table.c b/src/backend/access/table/table.c
index fe330ae862a..ef33d75d6fa 100644
--- a/src/backend/access/table/table.c
+++ b/src/backend/access/table/table.c
@@ -131,15 +131,20 @@ table_close(Relation relation, LOCKMODE lockmode)
/* ----------------
* validate_relation_kind - check the relation's kind
*
- * Make sure relkind is not index or composite type
+ * Make sure relkind is table-like. In particular, this excludes indexes
+ * and composite types, which cannot be read from in a query.
* ----------------
*/
static inline void
validate_relation_kind(Relation r)
{
- if (r->rd_rel->relkind == RELKIND_INDEX ||
- r->rd_rel->relkind == RELKIND_PARTITIONED_INDEX ||
- r->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
+ if (r->rd_rel->relkind != RELKIND_RELATION ||
+ r->rd_rel->relkind != RELKIND_SEQUENCE ||
+ r->rd_rel->relkind != RELKIND_TOASTVALUE ||
+ r->rd_rel->relkind != RELKIND_VIEW ||
+ r->rd_rel->relkind != RELKIND_MATVIEW ||
+ r->rd_rel->relkind != RELKIND_FOREIGN_TABLE ||
+ r->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot open relation \"%s\"",
--
2.53.0