From 65b21f740fc09dcf80ed60a77a3a64d85605a203 Mon Sep 17 00:00:00 2001
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
Date: Fri, 1 Sep 2023 19:23:17 +0200
Subject: [PATCH 2/2] Remove the bki 'close' command.

Bootstrapping works without manually closing relations because they are
auto-closed when a different relation is opened, and apparently leaking
a single opened relation at the end of the runway isn't a problem in the
currently available tests.
---
 src/backend/bootstrap/bootparse.y   | 13 +------------
 src/backend/bootstrap/bootscanner.l |  2 --
 src/backend/catalog/genbki.pl       | 12 ------------
 3 files changed, 1 insertion(+), 26 deletions(-)

diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y
index 81a1b7bfec..e405ed1c7b 100644
--- a/src/backend/bootstrap/bootparse.y
+++ b/src/backend/bootstrap/bootparse.y
@@ -99,7 +99,7 @@ static int num_columns_read = 0;
 /* NULLVAL is a reserved keyword */
 %token NULLVAL
 /* All the rest are unreserved, and should be handled in boot_ident! */
-%token <kw> OPEN XCLOSE XCREATE INSERT_TUPLE
+%token <kw> OPEN XCREATE INSERT_TUPLE
 %token <kw> XDECLARE INDEX ON USING XBUILD INDICES UNIQUE XTOAST
 %token <kw> OBJ_ID XBOOTSTRAP XSHARED_RELATION XROWTYPE_OID
 %token <kw> XFORCE XNOT XNULL
@@ -120,7 +120,6 @@ Boot_Queries:
 
 Boot_Query :
 		  Boot_OpenStmt
-		| Boot_CloseStmt
 		| Boot_CreateStmt
 		| Boot_InsertStmt
 		| Boot_DeclareIndexStmt
@@ -138,15 +137,6 @@ Boot_OpenStmt:
 				}
 		;
 
-Boot_CloseStmt:
-		  XCLOSE boot_ident
-				{
-					do_start();
-					closerel($2);
-					do_end();
-				}
-		;
-
 Boot_CreateStmt:
 		  XCREATE boot_ident oidspec optbootstrap optsharedrelation optrowtypeoid LPAREN
 				{
@@ -467,7 +457,6 @@ boot_column_val:
 boot_ident:
 		  ID			{ $$ = $1; }
 		| OPEN			{ $$ = pstrdup($1); }
-		| XCLOSE		{ $$ = pstrdup($1); }
 		| XCREATE		{ $$ = pstrdup($1); }
 		| INSERT_TUPLE	{ $$ = pstrdup($1); }
 		| XDECLARE		{ $$ = pstrdup($1); }
diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index 6a9d4193f2..99cb7861c9 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -73,8 +73,6 @@ sid		\'([^']|\'\')*\'
 
 open			{ boot_yylval.kw = "open"; return OPEN; }
 
-close			{ boot_yylval.kw = "close"; return XCLOSE; }
-
 create			{ boot_yylval.kw = "create"; return XCREATE; }
 
 OID				{ boot_yylval.kw = "OID"; return OBJ_ID; }
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl
index 67d63864b3..814d945cb1 100644
--- a/src/backend/catalog/genbki.pl
+++ b/src/backend/catalog/genbki.pl
@@ -549,8 +549,6 @@ EOM
 	{
 		print $def $line;
 	}
-	
-	my $opened = 0;
 
 	# Open it, unless it's a bootstrap catalog (create bootstrap does this
 	# automatically)
@@ -559,13 +557,8 @@ EOM
 		if (($catalog_data{$catname} || 0) > 0 || $catname eq 'pg_attribute')
 		{
 			print $bki "open $catname\n";
-			$opened = 1;
 		}
 	}
-	else
-	{
-		$opened = 1;
-	}
 
 	# For pg_attribute.h, we generate data entries ourselves.
 	if ($catname eq 'pg_attribute')
@@ -681,11 +674,6 @@ EOM
 		}
 	}
 
-	if ($opened eq 1)
-	{
-		print $bki "close $catname\n";
-	}
-
 	printf $def "\n#endif\t\t\t\t\t\t\t/* %s_D_H */\n", uc $catname;
 
 	# Close and rename definition header
-- 
2.40.1

