]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Flip logic in table validate_relation_kind
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 23 Feb 2026 16:26:29 +0000 (17:26 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 23 Feb 2026 16:32:07 +0000 (17:32 +0100)
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.

Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/6d3fef19-a420-4e11-8235-8ea534bf2080%40eisentraut.org

src/backend/access/table/table.c

index fe330ae862af804fa26aad89884d8f48daaf3eae..0d8662a145268b04e7642601edaa0555b8748499 100644 (file)
@@ -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\"",