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

Commit8e21bf5

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 wordboundary. There are architectures on which that is pretty much guaranteed toNOT be the case ... and those arches also don't like non-aligned memoryaccesses, meaning that log_newpage() would crash if it ever got invoked.Even on Intel-ish machines there's a potential for a large performance penaltyfrom doing I/O to an inadequately aligned buffer. So palloc it instead.Backpatch to 8.0 --- 7.4 doesn't have this code.
1 parent3137b49 commit8e21bf5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 14 additions & 3 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.142.4.13 2010/07/2916:15:47 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.142.4.14 2010/07/2919:24:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -5729,11 +5729,11 @@ static void
57295729
copy_relation_data(Relationrel,SMgrRelationdst)
57305730
{
57315731
SMgrRelationsrc;
5732+
char*buf;
5733+
Pagepage;
57325734
booluse_wal;
57335735
BlockNumbernblocks;
57345736
BlockNumberblkno;
5735-
charbuf[BLCKSZ];
5736-
Pagepage= (Page)buf;
57375737

57385738
/*
57395739
* Since we copy the data directly without looking at the shared
@@ -5744,6 +5744,15 @@ copy_relation_data(Relation rel, SMgrRelation dst)
57445744
*/
57455745
FlushRelationBuffers(rel,0);
57465746

5747+
/*
5748+
* palloc the buffer so that it's MAXALIGN'd. If it were just a local
5749+
* char[] array, the compiler might align it on any byte boundary, which
5750+
* can seriously hurt transfer speed to and from the kernel; not to
5751+
* mention possibly making PageSetLSN fail.
5752+
*/
5753+
buf= (char*)palloc(BLCKSZ);
5754+
page= (Page)buf;
5755+
57475756
/*
57485757
* We need to log the copied data in WAL iff WAL archiving is enabled
57495758
* AND it's not a temp rel.
@@ -5807,6 +5816,8 @@ copy_relation_data(Relation rel, SMgrRelation dst)
58075816
smgrwrite(dst,blkno,buf, true);
58085817
}
58095818

5819+
pfree(buf);
5820+
58105821
/*
58115822
* If the rel isn't temp, we must fsync it down to disk before it's
58125823
* safe to commit the transaction.(For a temp rel we don't care

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp