Commit 85a07813 authored by Tom Lane's avatar Tom Lane

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
parent 2040bb4a
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "access/htup.h" #include "access/htup.h"
#include "access/itup.h" #include "access/itup.h"
#include "access/tupdesc.h" #include "access/tupdesc.h"
#include "access/xact.h"
#include "bootstrap/bootstrap.h" #include "bootstrap/bootstrap.h"
#include "catalog/catalog.h" #include "catalog/catalog.h"
#include "catalog/heap.h" #include "catalog/heap.h"
...@@ -49,6 +48,7 @@ ...@@ -49,6 +48,7 @@
#include "storage/off.h" #include "storage/off.h"
#include "storage/smgr.h" #include "storage/smgr.h"
#include "tcop/dest.h" #include "tcop/dest.h"
#include "utils/memutils.h"
#include "utils/rel.h" #include "utils/rel.h"
...@@ -63,19 +63,27 @@ ...@@ -63,19 +63,27 @@
#define YYMALLOC palloc #define YYMALLOC palloc
#define YYFREE pfree #define YYFREE pfree
static MemoryContext per_line_ctx = NULL;
static void static void
do_start(void) do_start(void)
{ {
StartTransactionCommand(); Assert(CurrentMemoryContext == CurTransactionContext);
elog(DEBUG4, "start transaction"); /* First time through, create the per-line working context */
if (per_line_ctx == NULL)
per_line_ctx = AllocSetContextCreate(CurTransactionContext,
"bootstrap per-line processing",
ALLOCSET_DEFAULT_SIZES);
MemoryContextSwitchTo(per_line_ctx);
} }
static void static void
do_end(void) do_end(void)
{ {
CommitTransactionCommand(); /* Reclaim memory allocated while processing this line */
elog(DEBUG4, "commit transaction"); MemoryContextSwitchTo(CurTransactionContext);
MemoryContextReset(per_line_ctx);
CHECK_FOR_INTERRUPTS(); /* allow SIGINT to kill bootstrap run */ CHECK_FOR_INTERRUPTS(); /* allow SIGINT to kill bootstrap run */
if (isatty(0)) if (isatty(0))
{ {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <signal.h> #include <signal.h>
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/xact.h"
#include "bootstrap/bootstrap.h" #include "bootstrap/bootstrap.h"
#include "catalog/index.h" #include "catalog/index.h"
#include "catalog/pg_collation.h" #include "catalog/pg_collation.h"
...@@ -496,7 +497,9 @@ BootstrapModeMain(void) ...@@ -496,7 +497,9 @@ BootstrapModeMain(void)
/* /*
* Process bootstrap input. * Process bootstrap input.
*/ */
StartTransactionCommand();
boot_yyparse(); boot_yyparse();
CommitTransactionCommand();
/* /*
* We should now know about all mapped relations, so it's okay to write * We should now know about all mapped relations, so it's okay to write
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment