1999-12-21 01:06:44 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* tuptoaster.h
|
|
|
|
* POSTGRES definitions for external and compressed storage
|
2000-04-12 19:17:23 +02:00
|
|
|
* of variable size attributes.
|
1999-12-21 01:06:44 +01:00
|
|
|
*
|
2003-08-05 01:59:41 +02:00
|
|
|
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
1999-12-21 01:06:44 +01:00
|
|
|
*
|
2003-11-29 23:41:33 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/tuptoaster.h,v 1.17 2003/11/29 22:40:55 pgsql Exp $
|
1999-12-21 01:06:44 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef TUPTOASTER_H
|
|
|
|
#define TUPTOASTER_H
|
|
|
|
|
|
|
|
#include "access/heapam.h"
|
|
|
|
#include "access/htup.h"
|
|
|
|
#include "access/tupmacs.h"
|
|
|
|
#include "utils/rel.h"
|
|
|
|
|
2000-08-04 06:16:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This enables de-toasting of index entries. Needed until VACUUM is
|
|
|
|
* smart enough to rebuild indexes from scratch.
|
|
|
|
*/
|
2000-07-22 13:18:47 +02:00
|
|
|
#define TOAST_INDEX_HACK
|
2000-07-21 12:31:31 +02:00
|
|
|
|
1999-12-21 01:06:44 +01:00
|
|
|
|
2000-08-04 06:16:17 +02:00
|
|
|
/*
|
|
|
|
* These symbols control toaster activation. If a tuple is larger than
|
|
|
|
* TOAST_TUPLE_THRESHOLD, we will try to toast it down to no more than
|
|
|
|
* TOAST_TUPLE_TARGET bytes. Both numbers include all tuple header and
|
|
|
|
* alignment-padding overhead.
|
|
|
|
*
|
|
|
|
* The numbers need not be the same, though they currently are.
|
|
|
|
*/
|
|
|
|
#define TOAST_TUPLE_THRESHOLD (MaxTupleSize / 4)
|
|
|
|
|
|
|
|
#define TOAST_TUPLE_TARGET (MaxTupleSize / 4)
|
|
|
|
|
2001-02-15 21:57:01 +01:00
|
|
|
/*
|
|
|
|
* If an index value is larger than TOAST_INDEX_TARGET, we will try to
|
|
|
|
* compress it (we can't move it out-of-line, however). Note that this
|
|
|
|
* number is per-datum, not per-tuple, for simplicity in index_formtuple().
|
|
|
|
*/
|
|
|
|
#define TOAST_INDEX_TARGET (MaxTupleSize / 16)
|
2000-08-04 06:16:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When we store an oversize datum externally, we divide it into chunks
|
2001-03-22 05:01:46 +01:00
|
|
|
* containing at most TOAST_MAX_CHUNK_SIZE data bytes. This number *must*
|
2000-08-04 06:16:17 +02:00
|
|
|
* be small enough that the completed toast-table tuple (including the
|
|
|
|
* ID and sequence fields and all overhead) is no more than MaxTupleSize
|
|
|
|
* bytes. It *should* be small enough to make toast-table tuples no more
|
|
|
|
* than TOAST_TUPLE_THRESHOLD bytes, else heapam.c will uselessly invoke
|
|
|
|
* the toaster on toast-table tuples.
|
|
|
|
*
|
|
|
|
* NB: you cannot change this value without forcing initdb, at least not
|
|
|
|
* if your DB contains any multi-chunk toasted values.
|
|
|
|
*/
|
|
|
|
#define TOAST_MAX_CHUNK_SIZE (TOAST_TUPLE_THRESHOLD - \
|
|
|
|
MAXALIGN( \
|
|
|
|
MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + \
|
|
|
|
sizeof(Oid) + \
|
|
|
|
sizeof(int32) + \
|
|
|
|
VARHDRSZ))
|
2000-07-04 01:10:14 +02:00
|
|
|
|
|
|
|
|
2000-07-22 13:18:47 +02:00
|
|
|
/* ----------
|
|
|
|
* heap_tuple_toast_attrs() -
|
|
|
|
*
|
|
|
|
* Called by heap_insert(), heap_update() and heap_delete().
|
2000-08-04 06:16:17 +02:00
|
|
|
* Outdates any no-longer-needed toast entries referenced
|
|
|
|
* by oldtup and creates new ones until newtup is no more than
|
|
|
|
* TOAST_TUPLE_TARGET (or we run out of toastable values).
|
2000-07-22 13:18:47 +02:00
|
|
|
* Possibly modifies newtup by replacing the t_data part!
|
2000-08-04 06:16:17 +02:00
|
|
|
*
|
|
|
|
* oldtup is NULL if insert, newtup is NULL if delete.
|
2000-07-22 13:18:47 +02:00
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
extern void heap_tuple_toast_attrs(Relation rel,
|
2001-03-22 05:01:46 +01:00
|
|
|
HeapTuple newtup, HeapTuple oldtup);
|
1999-12-21 01:06:44 +01:00
|
|
|
|
2000-07-22 13:18:47 +02:00
|
|
|
/* ----------
|
|
|
|
* heap_tuple_fetch_attr() -
|
|
|
|
*
|
|
|
|
* Fetches an external stored attribute from the toast
|
|
|
|
* relation. Does NOT decompress it, if stored external
|
|
|
|
* in compressed format.
|
|
|
|
* ----------
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
extern varattrib *heap_tuple_fetch_attr(varattrib *attr);
|
2000-07-22 13:18:47 +02:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* heap_tuple_untoast_attr() -
|
|
|
|
*
|
|
|
|
* Fully detoasts one attribute, fetching and/or decompressing
|
|
|
|
* it as needed.
|
|
|
|
* ----------
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
extern varattrib *heap_tuple_untoast_attr(varattrib *attr);
|
1999-12-21 01:06:44 +01:00
|
|
|
|
2002-03-05 06:33:31 +01:00
|
|
|
/* ----------
|
|
|
|
* heap_tuple_untoast_attr_slice() -
|
|
|
|
*
|
2002-09-04 22:31:48 +02:00
|
|
|
* Fetches only the specified portion of an attribute.
|
|
|
|
* (Handles all cases for attribute storage)
|
2002-03-05 06:33:31 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2002-09-04 22:31:48 +02:00
|
|
|
extern varattrib *heap_tuple_untoast_attr_slice(varattrib *attr,
|
|
|
|
int32 sliceoffset,
|
|
|
|
int32 slicelength);
|
2002-03-05 06:33:31 +01:00
|
|
|
|
2001-02-15 21:57:01 +01:00
|
|
|
/* ----------
|
|
|
|
* toast_compress_datum -
|
|
|
|
*
|
|
|
|
* Create a compressed version of a varlena datum, if possible
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
extern Datum toast_compress_datum(Datum value);
|
|
|
|
|
2001-05-07 02:43:27 +02:00
|
|
|
/* ----------
|
|
|
|
* toast_raw_datum_size -
|
|
|
|
*
|
|
|
|
* Return the raw (detoasted) size of a varlena datum
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
extern Size toast_raw_datum_size(Datum value);
|
1999-12-21 01:06:44 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* TUPTOASTER_H */
|