Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit91ce16a

Browse files
committed
Allow rewriting ALTER TABLE to skip WAL logging.
Itagaki Takahiro, with small changes by me and Simon.
1 parenta4d03bb commit91ce16a

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.304 2009/10/14 22:14:21 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.305 2009/11/04 12:24:23 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3037,6 +3037,9 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
30373037
inti;
30383038
ListCell*l;
30393039
EState*estate;
3040+
CommandIdmycid;
3041+
BulkInsertStatebistate;
3042+
inthi_options;
30403043

30413044
/*
30423045
* Open the relation(s). We have surely already locked the existing
@@ -3051,6 +3054,29 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
30513054
else
30523055
newrel=NULL;
30533056

3057+
/*
3058+
* Prepare a BulkInsertState and options for heap_insert. Because
3059+
* we're building a new heap, we can skip WAL-logging and fsync it
3060+
* to disk at the end instead (unless WAL-logging is required for
3061+
* archiving). The FSM is empty too, so don't bother using it.
3062+
*/
3063+
if (newrel)
3064+
{
3065+
mycid=GetCurrentCommandId(true);
3066+
bistate=GetBulkInsertState();
3067+
3068+
hi_options=HEAP_INSERT_SKIP_FSM;
3069+
if (!XLogArchivingActive())
3070+
hi_options |=HEAP_INSERT_SKIP_WAL;
3071+
}
3072+
else
3073+
{
3074+
/* keep compiler quiet about using these uninitialized */
3075+
mycid=0;
3076+
bistate=NULL;
3077+
hi_options=0;
3078+
}
3079+
30543080
/*
30553081
* If we need to rewrite the table, the operation has to be propagated to
30563082
* tables that use this table's rowtype as a column type.
@@ -3252,7 +3278,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
32523278

32533279
/* Write the tuple out to the new relation */
32543280
if (newrel)
3255-
simple_heap_insert(newrel,tuple);
3281+
heap_insert(newrel,tuple,mycid,hi_options,bistate);
32563282

32573283
ResetExprContext(econtext);
32583284

@@ -3270,7 +3296,15 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
32703296

32713297
heap_close(oldrel,NoLock);
32723298
if (newrel)
3299+
{
3300+
FreeBulkInsertState(bistate);
3301+
3302+
/* If we skipped writing WAL, then we need to sync the heap. */
3303+
if (hi_options&HEAP_INSERT_SKIP_WAL)
3304+
heap_sync(newrel);
3305+
32733306
heap_close(newrel,NoLock);
3307+
}
32743308
}
32753309

32763310
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp