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

Commit 984d56b

Browse files
committed
Fix another longstanding problem in copy_relation_data: it was blithely
assuming that a local char[] array would be aligned on at least a word boundary. There are architectures on which that is pretty much guaranteed to NOT be the case ... and those arches also don't like non-aligned memory accesses, meaning that log_newpage() would crash if it ever got invoked. Even on Intel-ish machines there's a potential for a large performance penalty from doing I/O to an inadequately aligned buffer. So palloc it instead. Backpatch to 8.0 --- 7.4 doesn't have this code.
1 parent 5b48e2e commit 984d56b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/backend/commands/tablecmds.c

+14-3
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.336 2010/07/29 11:06:34 sriggs Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.337 2010/07/29 19:23:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -7230,11 +7230,20 @@ static void
72307230
copy_relation_data(SMgrRelation src, SMgrRelation dst,
72317231
ForkNumber forkNum, bool istemp)
72327232
{
7233+
char *buf;
7234+
Page page;
72337235
bool use_wal;
72347236
BlockNumber nblocks;
72357237
BlockNumber blkno;
7236-
char buf[BLCKSZ];
7237-
Page page = (Page) buf;
7238+
7239+
/*
7240+
* palloc the buffer so that it's MAXALIGN'd. If it were just a local
7241+
* char[] array, the compiler might align it on any byte boundary, which
7242+
* can seriously hurt transfer speed to and from the kernel; not to
7243+
* mention possibly making log_newpage's accesses to the page header fail.
7244+
*/
7245+
buf = (char *) palloc(BLCKSZ);
7246+
page = (Page) buf;
72387247

72397248
/*
72407249
* We need to log the copied data in WAL iff WAL archiving/streaming is
@@ -7263,6 +7272,8 @@ copy_relation_data(SMgrRelation src, SMgrRelation dst,
72637272
smgrextend(dst, forkNum, blkno, buf, true);
72647273
}
72657274

7275+
pfree(buf);
7276+
72667277
/*
72677278
* If the rel isn't temp, we must fsync it down to disk before it's safe
72687279
* to commit the transaction. (For a temp rel we don't care since the rel

0 commit comments

Comments
 (0)