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

Commitd26bf23

Browse files
committed
Arrange to squeeze out the MINIMAL_TUPLE_PADDING in the tuple representation
written to temp files by tuplesort.c and tuplestore.c. This saves 2 bytes perrow for 32-bit machines, and 6 bytes per row for 64-bit machines, which seemsworth the slight additional uglification of the tuple read/write routines.
1 parent8ecd535 commitd26bf23

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

‎src/backend/utils/sort/tuplesort.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
* Portions Copyright (c) 1994, Regents of the University of California
9292
*
9393
* IDENTIFICATION
94-
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.87 2008/09/15 18:43:41 tgl Exp $
94+
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.88 2008/10/28 15:51:03 tgl Exp $
9595
*
9696
*-------------------------------------------------------------------------
9797
*/
@@ -2632,18 +2632,20 @@ copytup_heap(Tuplesortstate *state, SortTuple *stup, void *tup)
26322632
&stup->isnull1);
26332633
}
26342634

2635-
/*
2636-
* Since MinimalTuple already has length in its first word, we don't need
2637-
* to write that separately.
2638-
*/
26392635
staticvoid
26402636
writetup_heap(Tuplesortstate*state,inttapenum,SortTuple*stup)
26412637
{
26422638
MinimalTupletuple= (MinimalTuple)stup->tuple;
2643-
unsignedinttuplen=tuple->t_len;
2639+
/* the part of the MinimalTuple we'll write: */
2640+
char*tupbody= (char*)tuple+MINIMAL_TUPLE_DATA_OFFSET;
2641+
unsignedinttupbodylen=tuple->t_len-MINIMAL_TUPLE_DATA_OFFSET;
2642+
/* total on-disk footprint: */
2643+
unsignedinttuplen=tupbodylen+sizeof(int);
26442644

26452645
LogicalTapeWrite(state->tapeset,tapenum,
2646-
(void*)tuple,tuplen);
2646+
(void*)&tuplen,sizeof(tuplen));
2647+
LogicalTapeWrite(state->tapeset,tapenum,
2648+
(void*)tupbody,tupbodylen);
26472649
if (state->randomAccess)/* need trailing length word? */
26482650
LogicalTapeWrite(state->tapeset,tapenum,
26492651
(void*)&tuplen,sizeof(tuplen));
@@ -2656,16 +2658,18 @@ static void
26562658
readtup_heap(Tuplesortstate*state,SortTuple*stup,
26572659
inttapenum,unsignedintlen)
26582660
{
2659-
MinimalTupletuple= (MinimalTuple)palloc(len);
2660-
unsignedinttuplen;
2661+
unsignedinttupbodylen=len-sizeof(int);
2662+
unsignedinttuplen=tupbodylen+MINIMAL_TUPLE_DATA_OFFSET;
2663+
MinimalTupletuple= (MinimalTuple)palloc(tuplen);
2664+
char*tupbody= (char*)tuple+MINIMAL_TUPLE_DATA_OFFSET;
26612665
HeapTupleDatahtup;
26622666

26632667
USEMEM(state,GetMemoryChunkSpace(tuple));
26642668
/* read in the tuple proper */
2665-
tuple->t_len=len;
2669+
tuple->t_len=tuplen;
26662670
if (LogicalTapeRead(state->tapeset,tapenum,
2667-
(void*)((char*)tuple+sizeof(int)),
2668-
len-sizeof(int))!= (size_t)(len-sizeof(int)))
2671+
(void*)tupbody,
2672+
tupbodylen)!= (size_t)tupbodylen)
26692673
elog(ERROR,"unexpected end of data");
26702674
if (state->randomAccess)/* need trailing length word? */
26712675
if (LogicalTapeRead(state->tapeset,tapenum, (void*)&tuplen,

‎src/backend/utils/sort/tuplestore.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* Portions Copyright (c) 1994, Regents of the University of California
4747
*
4848
* IDENTIFICATION
49-
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.42 2008/10/07 00:05:55 tgl Exp $
49+
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.43 2008/10/28 15:51:03 tgl Exp $
5050
*
5151
*-------------------------------------------------------------------------
5252
*/
@@ -1173,9 +1173,17 @@ static void
11731173
writetup_heap(Tuplestorestate*state,void*tup)
11741174
{
11751175
MinimalTupletuple= (MinimalTuple)tup;
1176-
unsignedinttuplen=tuple->t_len;
1177-
1178-
if (BufFileWrite(state->myfile, (void*)tuple,tuplen)!= (size_t)tuplen)
1176+
/* the part of the MinimalTuple we'll write: */
1177+
char*tupbody= (char*)tuple+MINIMAL_TUPLE_DATA_OFFSET;
1178+
unsignedinttupbodylen=tuple->t_len-MINIMAL_TUPLE_DATA_OFFSET;
1179+
/* total on-disk footprint: */
1180+
unsignedinttuplen=tupbodylen+sizeof(int);
1181+
1182+
if (BufFileWrite(state->myfile, (void*)&tuplen,
1183+
sizeof(tuplen))!=sizeof(tuplen))
1184+
elog(ERROR,"write failed");
1185+
if (BufFileWrite(state->myfile, (void*)tupbody,
1186+
tupbodylen)!= (size_t)tupbodylen)
11791187
elog(ERROR,"write failed");
11801188
if (state->backward)/* need trailing length word? */
11811189
if (BufFileWrite(state->myfile, (void*)&tuplen,
@@ -1189,14 +1197,16 @@ writetup_heap(Tuplestorestate *state, void *tup)
11891197
staticvoid*
11901198
readtup_heap(Tuplestorestate*state,unsignedintlen)
11911199
{
1192-
MinimalTupletuple= (MinimalTuple)palloc(len);
1193-
unsignedinttuplen;
1200+
unsignedinttupbodylen=len-sizeof(int);
1201+
unsignedinttuplen=tupbodylen+MINIMAL_TUPLE_DATA_OFFSET;
1202+
MinimalTupletuple= (MinimalTuple)palloc(tuplen);
1203+
char*tupbody= (char*)tuple+MINIMAL_TUPLE_DATA_OFFSET;
11941204

11951205
USEMEM(state,GetMemoryChunkSpace(tuple));
11961206
/* read in the tuple proper */
1197-
tuple->t_len=len;
1198-
if (BufFileRead(state->myfile, (void*)((char*)tuple+sizeof(int)),
1199-
len-sizeof(int))!= (size_t)(len-sizeof(int)))
1207+
tuple->t_len=tuplen;
1208+
if (BufFileRead(state->myfile, (void*)tupbody,
1209+
tupbodylen)!= (size_t)tupbodylen)
12001210
elog(ERROR,"unexpected end of data");
12011211
if (state->backward)/* need trailing length word? */
12021212
if (BufFileRead(state->myfile, (void*)&tuplen,

‎src/include/access/htup.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.101 2008/08/11 11:05:11 heikki Exp $
10+
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.102 2008/10/28 15:51:03 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -420,11 +420,17 @@ do { \
420420
*
421421
* Note that t_hoff is computed the same as in a full tuple, hence it includes
422422
* the MINIMAL_TUPLE_OFFSET distance. t_len does not include that, however.
423+
*
424+
* MINIMAL_TUPLE_DATA_OFFSET is the offset to the first useful (non-pad) data
425+
* other than the length word. tuplesort.c and tuplestore.c use this to avoid
426+
* writing the padding to disk.
423427
*/
424428
#defineMINIMAL_TUPLE_OFFSET \
425429
((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
426430
#defineMINIMAL_TUPLE_PADDING \
427431
((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
432+
#defineMINIMAL_TUPLE_DATA_OFFSET \
433+
offsetof(MinimalTupleData, t_infomask2)
428434

429435
typedefstructMinimalTupleData
430436
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp