mirror of
https://github.com/postgres/postgres.git
synced 2025-07-21 16:02:15 +03:00
Decouple the values of TOAST_TUPLE_THRESHOLD and TOAST_MAX_CHUNK_SIZE.
Add the latter to the values checked in pg_control, since it can't be changed without invalidating toast table content. This commit in itself shouldn't change any behavior, but it lays some necessary groundwork for experimentation with these toast-control numbers. Note: while TOAST_TUPLE_THRESHOLD can now be changed without initdb, some thought still needs to be given to needs_toast_table() in toasting.c before unleashing random changes.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.230 2007/03/29 00:15:37 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.231 2007/04/03 04:14:26 tgl Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@ -1420,7 +1420,13 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
|
||||
* Note: below this point, heaptup is the data we actually intend to store
|
||||
* into the relation; tup is the caller's original untoasted data.
|
||||
*/
|
||||
if (HeapTupleHasExternal(tup) || tup->t_len > TOAST_TUPLE_THRESHOLD)
|
||||
if (relation->rd_rel->relkind == RELKIND_TOASTVALUE)
|
||||
{
|
||||
/* toast table entries should never be recursively toasted */
|
||||
Assert(!HeapTupleHasExternal(tup));
|
||||
heaptup = tup;
|
||||
}
|
||||
else if (HeapTupleHasExternal(tup) || tup->t_len > TOAST_TUPLE_THRESHOLD)
|
||||
heaptup = toast_insert_or_update(relation, tup, NULL,
|
||||
use_wal, use_fsm);
|
||||
else
|
||||
@ -1777,7 +1783,12 @@ l1:
|
||||
* because we need to look at the contents of the tuple, but it's OK to
|
||||
* release the content lock on the buffer first.
|
||||
*/
|
||||
if (HeapTupleHasExternal(&tp))
|
||||
if (relation->rd_rel->relkind == RELKIND_TOASTVALUE)
|
||||
{
|
||||
/* toast table entries should never be recursively toasted */
|
||||
Assert(!HeapTupleHasExternal(&tp));
|
||||
}
|
||||
else if (HeapTupleHasExternal(&tp))
|
||||
toast_delete(relation, &tp);
|
||||
|
||||
/*
|
||||
@ -2075,9 +2086,17 @@ l2:
|
||||
* We need to invoke the toaster if there are already any out-of-line
|
||||
* toasted values present, or if the new tuple is over-threshold.
|
||||
*/
|
||||
need_toast = (HeapTupleHasExternal(&oldtup) ||
|
||||
HeapTupleHasExternal(newtup) ||
|
||||
newtup->t_len > TOAST_TUPLE_THRESHOLD);
|
||||
if (relation->rd_rel->relkind == RELKIND_TOASTVALUE)
|
||||
{
|
||||
/* toast table entries should never be recursively toasted */
|
||||
Assert(!HeapTupleHasExternal(&oldtup));
|
||||
Assert(!HeapTupleHasExternal(newtup));
|
||||
need_toast = false;
|
||||
}
|
||||
else
|
||||
need_toast = (HeapTupleHasExternal(&oldtup) ||
|
||||
HeapTupleHasExternal(newtup) ||
|
||||
newtup->t_len > TOAST_TUPLE_THRESHOLD);
|
||||
|
||||
pagefree = PageGetFreeSpace((Page) dp);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.72 2007/03/29 00:15:37 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.73 2007/04/03 04:14:26 tgl Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@ -291,6 +291,12 @@ toast_delete(Relation rel, HeapTuple oldtup)
|
||||
Datum toast_values[MaxHeapAttributeNumber];
|
||||
bool toast_isnull[MaxHeapAttributeNumber];
|
||||
|
||||
/*
|
||||
* We should only ever be called for tuples of plain relations ---
|
||||
* recursing on a toast rel is bad news.
|
||||
*/
|
||||
Assert(rel->rd_rel->relkind == RELKIND_RELATION);
|
||||
|
||||
/*
|
||||
* Get the tuple descriptor and break down the tuple into fields.
|
||||
*
|
||||
@ -360,6 +366,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
bool has_nulls = false;
|
||||
|
||||
Size maxDataLen;
|
||||
Size hoff;
|
||||
|
||||
char toast_action[MaxHeapAttributeNumber];
|
||||
bool toast_isnull[MaxHeapAttributeNumber];
|
||||
@ -370,6 +377,12 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
bool toast_free[MaxHeapAttributeNumber];
|
||||
bool toast_delold[MaxHeapAttributeNumber];
|
||||
|
||||
/*
|
||||
* We should only ever be called for tuples of plain relations ---
|
||||
* recursing on a toast rel is bad news.
|
||||
*/
|
||||
Assert(rel->rd_rel->relkind == RELKIND_RELATION);
|
||||
|
||||
/*
|
||||
* Get the tuple descriptor and break down the tuple(s) into fields.
|
||||
*/
|
||||
@ -512,15 +525,15 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
*/
|
||||
|
||||
/* compute header overhead --- this should match heap_form_tuple() */
|
||||
maxDataLen = offsetof(HeapTupleHeaderData, t_bits);
|
||||
hoff = offsetof(HeapTupleHeaderData, t_bits);
|
||||
if (has_nulls)
|
||||
maxDataLen += BITMAPLEN(numAttrs);
|
||||
hoff += BITMAPLEN(numAttrs);
|
||||
if (newtup->t_data->t_infomask & HEAP_HASOID)
|
||||
maxDataLen += sizeof(Oid);
|
||||
maxDataLen = MAXALIGN(maxDataLen);
|
||||
Assert(maxDataLen == newtup->t_data->t_hoff);
|
||||
hoff += sizeof(Oid);
|
||||
hoff = MAXALIGN(hoff);
|
||||
Assert(hoff == newtup->t_data->t_hoff);
|
||||
/* now convert to a limit on the tuple data size */
|
||||
maxDataLen = TOAST_TUPLE_TARGET - maxDataLen;
|
||||
maxDataLen = TOAST_TUPLE_TARGET - hoff;
|
||||
|
||||
/*
|
||||
* Look for attributes with attstorage 'x' to compress
|
||||
@ -583,7 +596,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
|
||||
/*
|
||||
* Second we look for attributes of attstorage 'x' or 'e' that are still
|
||||
* inline.
|
||||
* inline. But skip this if there's no toast table to push them to.
|
||||
*/
|
||||
while (heap_compute_data_size(tupleDesc,
|
||||
toast_values, toast_isnull) > maxDataLen &&
|
||||
@ -695,7 +708,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally we store attributes of type 'm' external
|
||||
* Finally we store attributes of type 'm' external, if possible.
|
||||
*/
|
||||
while (heap_compute_data_size(tupleDesc,
|
||||
toast_values, toast_isnull) > maxDataLen &&
|
||||
|
Reference in New Issue
Block a user