Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 85a0781

Browse files
committed
Use one transaction while reading postgres.bki, not one per line.
AFAICT, the only actual benefit of closing a bootstrap transaction is to reclaim transient memory. We can do that a lot more cheaply by just doing a MemoryContextReset on a suitable context. This gets the runtime of the "bootstrap" phase of initdb down to the point where, at least by eyeball, it's quite negligible compared to the rest of the phases. Per discussion with Andres Freund. Discussion: https://postgr.es/m/9244.1492106743@sss.pgh.pa.us
1 parent 2040bb4 commit 85a0781

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/backend/bootstrap/bootparse.y

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "access/htup.h"
2323
#include "access/itup.h"
2424
#include "access/tupdesc.h"
25-
#include "access/xact.h"
2625
#include "bootstrap/bootstrap.h"
2726
#include "catalog/catalog.h"
2827
#include "catalog/heap.h"
@@ -49,6 +48,7 @@
4948
#include "storage/off.h"
5049
#include "storage/smgr.h"
5150
#include "tcop/dest.h"
51+
#include "utils/memutils.h"
5252
#include "utils/rel.h"
5353

5454

@@ -63,19 +63,27 @@
6363
#define YYMALLOC palloc
6464
#define YYFREE pfree
6565

66+
static MemoryContext per_line_ctx = NULL;
67+
6668
static void
6769
do_start(void)
6870
{
69-
StartTransactionCommand();
70-
elog(DEBUG4, "start transaction");
71+
Assert(CurrentMemoryContext == CurTransactionContext);
72+
/* First time through, create the per-line working context */
73+
if (per_line_ctx == NULL)
74+
per_line_ctx = AllocSetContextCreate(CurTransactionContext,
75+
"bootstrap per-line processing",
76+
ALLOCSET_DEFAULT_SIZES);
77+
MemoryContextSwitchTo(per_line_ctx);
7178
}
7279

7380

7481
static void
7582
do_end(void)
7683
{
77-
CommitTransactionCommand();
78-
elog(DEBUG4, "commit transaction");
84+
/* Reclaim memory allocated while processing this line */
85+
MemoryContextSwitchTo(CurTransactionContext);
86+
MemoryContextReset(per_line_ctx);
7987
CHECK_FOR_INTERRUPTS(); /* allow SIGINT to kill bootstrap run */
8088
if (isatty(0))
8189
{

src/backend/bootstrap/bootstrap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <signal.h>
1919

2020
#include "access/htup_details.h"
21+
#include "access/xact.h"
2122
#include "bootstrap/bootstrap.h"
2223
#include "catalog/index.h"
2324
#include "catalog/pg_collation.h"
@@ -496,7 +497,9 @@ BootstrapModeMain(void)
496497
/*
497498
* Process bootstrap input.
498499
*/
500+
StartTransactionCommand();
499501
boot_yyparse();
502+
CommitTransactionCommand();
500503

501504
/*
502505
* We should now know about all mapped relations, so it's okay to write

0 commit comments

Comments
 (0)