]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use LOCKMODE in parse_relation.c/.h
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 23 Feb 2026 20:17:06 +0000 (21:17 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 23 Feb 2026 20:25:55 +0000 (21:25 +0100)
There were a couple of comments in parse_relation.c

> Note: properly, lockmode should be declared LOCKMODE not int, but that
> would require importing storage/lock.h into parse_relation.h.  Since
> LOCKMODE is typedef'd as int anyway, that seems like overkill.

but actually LOCKMODE has been in storage/lockdefs.h for a while,
which is intentionally a more narrow header.  So we can include that
one in parse_relation.h and just use LOCKMODE normally.

An alternative would be to add a duplicate typedef into
parse_relation.h, but that doesn't seem necessary here.

Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/4bcd65fb-2497-484c-bb41-83cb435eb64d%40eisentraut.org

src/backend/parser/parse_relation.c
src/include/parser/parse_relation.h

index 3ec8d8de0118621cbe59adf9b94c84c569ab83ea..e003db520de70a4c8549a8b11eebc2b73ad13927 100644 (file)
@@ -1422,13 +1422,9 @@ buildNSItemFromLists(RangeTblEntry *rte, Index rtindex,
  * This is essentially just the same as table_openrv(), except that it caters
  * to some parser-specific error reporting needs, notably that it arranges
  * to include the RangeVar's parse location in any resulting error.
- *
- * Note: properly, lockmode should be declared LOCKMODE not int, but that
- * would require importing storage/lock.h into parse_relation.h.  Since
- * LOCKMODE is typedef'd as int anyway, that seems like overkill.
  */
 Relation
-parserOpenTable(ParseState *pstate, const RangeVar *relation, int lockmode)
+parserOpenTable(ParseState *pstate, const RangeVar *relation, LOCKMODE lockmode)
 {
        Relation        rel;
        ParseCallbackState pcbstate;
@@ -1571,15 +1567,11 @@ addRangeTableEntry(ParseState *pstate,
  * of AccessShareLock, RowShareLock, or RowExclusiveLock depending on the
  * RTE's role within the query.  The caller must hold that lock mode
  * or a stronger one.
- *
- * Note: properly, lockmode should be declared LOCKMODE not int, but that
- * would require importing storage/lock.h into parse_relation.h.  Since
- * LOCKMODE is typedef'd as int anyway, that seems like overkill.
  */
 ParseNamespaceItem *
 addRangeTableEntryForRelation(ParseState *pstate,
                                                          Relation rel,
-                                                         int lockmode,
+                                                         LOCKMODE lockmode,
                                                          Alias *alias,
                                                          bool inh,
                                                          bool inFromCl)
index 5379330a9bf7a89b02d170b38d0e5cda7261d86a..46b2d5ca02a390b69d67021f47f39ec5e4a9d803 100644 (file)
@@ -15,6 +15,7 @@
 #define PARSE_RELATION_H
 
 #include "parser/parse_node.h"
+#include "storage/lockdefs.h"
 
 
 extern ParseNamespaceItem *refnameNamespaceItem(ParseState *pstate,
@@ -44,7 +45,7 @@ extern Node *colNameToVar(ParseState *pstate, const char *colname, bool localonl
 extern void markNullableIfNeeded(ParseState *pstate, Var *var);
 extern void markVarForSelectPriv(ParseState *pstate, Var *var);
 extern Relation parserOpenTable(ParseState *pstate, const RangeVar *relation,
-                                                               int lockmode);
+                                                               LOCKMODE lockmode);
 extern ParseNamespaceItem *addRangeTableEntry(ParseState *pstate,
                                                                                          RangeVar *relation,
                                                                                          Alias *alias,
@@ -52,7 +53,7 @@ extern ParseNamespaceItem *addRangeTableEntry(ParseState *pstate,
                                                                                          bool inFromCl);
 extern ParseNamespaceItem *addRangeTableEntryForRelation(ParseState *pstate,
                                                                                                                 Relation rel,
-                                                                                                                int lockmode,
+                                                                                                                LOCKMODE lockmode,
                                                                                                                 Alias *alias,
                                                                                                                 bool inh,
                                                                                                                 bool inFromCl);