0001-Use-LOCKMODE-in-parse_relation.c-.h.patch

text/plain

Filename: 0001-Use-LOCKMODE-in-parse_relation.c-.h.patch
Type: text/plain
Part: 0
Message: Use LOCKMODE in parse_relation.c/.h

Patch

Format: format-patch
Series: patch 0001
Subject: Use LOCKMODE in parse_relation.c/.h
File+
src/backend/parser/parse_relation.c 2 10
src/include/parser/parse_relation.h 3 2
From caa2f84ebcc23ba2be03e45ce78e1cd25b6b8816 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 18 Feb 2026 10:35:38 +0100
Subject: [PATCH] Use LOCKMODE in parse_relation.c/.h

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.
---
 src/backend/parser/parse_relation.c | 12 ++----------
 src/include/parser/parse_relation.h |  5 +++--
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index 3ec8d8de011..e003db520de 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -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)
diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h
index 5379330a9bf..46b2d5ca02a 100644
--- a/src/include/parser/parse_relation.h
+++ b/src/include/parser/parse_relation.h
@@ -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);
-- 
2.53.0