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

Commitca7c816

Browse files
committed
Tweak TOAST code so that columns marked with MAIN storage strategy are
not forced out-of-line unless that is necessary to make the row fit on apage. Previously, they were forced out-of-line if needed to get the rowdown to the default target size (1/4th page).Kevin Grittner
1 parenta5375bf commitca7c816

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

‎doc/src/sgml/storage.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/storage.sgml,v 1.29 2009/06/1721:58:49 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/storage.sgml,v 1.30 2009/07/22 01:21:22 tgl Exp $ -->
22

33
<chapter id="storage">
44

@@ -347,7 +347,7 @@ The <acronym>TOAST</> code recognizes four different strategies for storing
347347
<literal>MAIN</literal> allows compression but not out-of-line
348348
storage. (Actually, out-of-line storage will still be performed
349349
for such columns, but only as a last resort when there is no other
350-
way to make the row small enough.)
350+
way to make the row small enough to fit on a page.)
351351
</para>
352352
</listitem>
353353
</itemizedlist>

‎src/backend/access/heap/tuptoaster.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.93 2009/06/11 14:48:54 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.94 2009/07/22 01:21:22 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -796,8 +796,12 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
796796
}
797797

798798
/*
799-
* Finally we store attributes of type 'm' external, if possible.
799+
* Finally we store attributes of type 'm' externally. At this point
800+
* we increase the target tuple size, so that 'm' attributes aren't
801+
* stored externally unless really necessary.
800802
*/
803+
maxDataLen=TOAST_TUPLE_TARGET_MAIN-hoff;
804+
801805
while (heap_compute_data_size(tupleDesc,
802806
toast_values,toast_isnull)>maxDataLen&&
803807
rel->rd_rel->reltoastrelid!=InvalidOid)

‎src/include/access/tuptoaster.h

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
88
*
9-
* $PostgreSQL: pgsql/src/include/access/tuptoaster.h,v 1.43 2009/01/01 17:23:56 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/access/tuptoaster.h,v 1.44 2009/07/22 01:21:22 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -24,20 +24,26 @@
2424
#defineTOAST_INDEX_HACK
2525

2626

27+
/*
28+
* Find the maximum size of a tuple if there are to be N tuples per page.
29+
*/
30+
#defineMaximumBytesPerTuple(tuplesPerPage)\
31+
MAXALIGN_DOWN((BLCKSZ - \
32+
MAXALIGN(SizeOfPageHeaderData + (tuplesPerPage) * sizeof(ItemIdData))) \
33+
/ (tuplesPerPage))
34+
2735
/*
2836
* These symbols control toaster activation. If a tuple is larger than
2937
* TOAST_TUPLE_THRESHOLD, we will try to toast it down to no more than
30-
* TOAST_TUPLE_TARGET bytes. Both numbers include all tuple header overhead
31-
* and between-fields alignment padding, but we do *not* consider any
32-
* end-of-tuple alignment padding; hence the values can be compared directly
33-
* to a tuple's t_len field.
38+
* TOAST_TUPLE_TARGET bytes through compressing compressible fields and
39+
* moving EXTENDED and EXTERNAL data out-of-line.
3440
*
3541
* The numbers need not be the same, though they currently are. It doesn't
3642
* make sense for TARGET to exceed THRESHOLD, but it could be useful to make
3743
* it be smaller.
3844
*
3945
* Currently we choose both values to match the largest tuple size for which
40-
* TOAST_TUPLES_PER_PAGE tuples can fit on adisk page.
46+
* TOAST_TUPLES_PER_PAGE tuples can fit on aheap page.
4147
*
4248
* XXX while these can be modified without initdb, some thought needs to be
4349
* given to needs_toast_table() in toasting.c before unleashing random
@@ -46,13 +52,21 @@
4652
*/
4753
#defineTOAST_TUPLES_PER_PAGE4
4854

49-
#defineTOAST_TUPLE_THRESHOLD\
50-
MAXALIGN_DOWN((BLCKSZ - \
51-
MAXALIGN(SizeOfPageHeaderData + TOAST_TUPLES_PER_PAGE * sizeof(ItemIdData))) \
52-
/ TOAST_TUPLES_PER_PAGE)
55+
#defineTOAST_TUPLE_THRESHOLDMaximumBytesPerTuple(TOAST_TUPLES_PER_PAGE)
5356

5457
#defineTOAST_TUPLE_TARGETTOAST_TUPLE_THRESHOLD
5558

59+
/*
60+
* The code will also consider moving MAIN data out-of-line, but only as a
61+
* last resort if the previous steps haven't reached the target tuple size.
62+
* In this phase we use a different target size, currently equal to the
63+
* largest tuple that will fit on a heap page. This is reasonable since
64+
* the user has told us to keep the data in-line if at all possible.
65+
*/
66+
#defineTOAST_TUPLES_PER_PAGE_MAIN1
67+
68+
#defineTOAST_TUPLE_TARGET_MAINMaximumBytesPerTuple(TOAST_TUPLES_PER_PAGE_MAIN)
69+
5670
/*
5771
* If an index value is larger than TOAST_INDEX_TARGET, we will try to
5872
* compress it (we can't move it out-of-line, however). Note that this
@@ -72,10 +86,7 @@
7286
*/
7387
#defineEXTERN_TUPLES_PER_PAGE4/* tweak only this */
7488

75-
#defineEXTERN_TUPLE_MAX_SIZE\
76-
MAXALIGN_DOWN((BLCKSZ - \
77-
MAXALIGN(SizeOfPageHeaderData + EXTERN_TUPLES_PER_PAGE * sizeof(ItemIdData))) \
78-
/ EXTERN_TUPLES_PER_PAGE)
89+
#defineEXTERN_TUPLE_MAX_SIZEMaximumBytesPerTuple(EXTERN_TUPLES_PER_PAGE)
7990

8091
#defineTOAST_MAX_CHUNK_SIZE\
8192
(EXTERN_TUPLE_MAX_SIZE -\

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp