PostgreSQL Source Code  git master
toast_helper.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * toast_helper.h
4  * Helper functions for table AMs implementing compressed or
5  * out-of-line storage of varlena attributes.
6  *
7  * Copyright (c) 2000-2019, PostgreSQL Global Development Group
8  *
9  * src/include/access/toast_helper.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 
14 #ifndef TOAST_HELPER_H
15 #define TOAST_HELPER_H
16 
17 #include "utils/rel.h"
18 
19 /*
20  * Information about one column of a tuple being toasted.
21  *
22  * NOTE: toast_action[i] can have these values:
23  * ' ' default handling
24  * 'p' already processed --- don't touch it
25  * 'x' incompressible, but OK to move off
26  *
27  * NOTE: toast_attr[i].tai_size is only made valid for varlena attributes with
28  * toast_action[i] different from 'p'.
29  */
30 typedef struct
31 {
36 
37 /*
38  * Information about one tuple being toasted.
39  */
40 typedef struct
41 {
42  /*
43  * Before calling toast_tuple_init, the caller must initialize the
44  * following fields. Each array must have a length equal to
45  * ttc_rel->rd_att->natts. The tts_oldvalues and tts_oldisnull fields
46  * should be NULL in the case of an insert.
47  */
48  Relation ttc_rel; /* the relation that contains the tuple */
49  Datum *ttc_values; /* values from the tuple columns */
50  bool *ttc_isnull; /* null flags for the tuple columns */
51  Datum *ttc_oldvalues; /* values from previous tuple */
52  bool *ttc_oldisnull; /* null flags from previous tuple */
53 
54  /*
55  * Before calling toast_tuple_init, the caller should set tts_attr to
56  * point to an array of ToastAttrInfo structures of a length equal to
57  * tts_rel->rd_att->natts. The contents of the array need not be
58  * initialized. ttc_flags also does not need to be initialized.
59  */
63 
64 /*
65  * Flags indicating the overall state of a TOAST operation.
66  *
67  * TOAST_NEEDS_DELETE_OLD indicates that one or more old TOAST datums need
68  * to be deleted.
69  *
70  * TOAST_NEEDS_FREE indicates that one or more TOAST values need to be freed.
71  *
72  * TOAST_HAS_NULLS indicates that nulls were found in the tuple being toasted.
73  *
74  * TOAST_NEEDS_CHANGE indicates that a new tuple needs to built; in other
75  * words, the toaster did something.
76  */
77 #define TOAST_NEEDS_DELETE_OLD 0x0001
78 #define TOAST_NEEDS_FREE 0x0002
79 #define TOAST_HAS_NULLS 0x0004
80 #define TOAST_NEEDS_CHANGE 0x0008
81 
82 /*
83  * Flags indicating the status of a TOAST operation with respect to a
84  * particular column.
85  *
86  * TOASTCOL_NEEDS_DELETE_OLD indicates that the old TOAST datums for this
87  * column need to be deleted.
88  *
89  * TOASTCOL_NEEDS_FREE indicates that the value for this column needs to
90  * be freed.
91  *
92  * TOASTCOL_IGNORE indicates that the toaster should not further process
93  * this column.
94  *
95  * TOASTCOL_INCOMPRESSIBLE indicates that this column has been found to
96  * be incompressible, but could be moved out-of-line.
97  */
98 #define TOASTCOL_NEEDS_DELETE_OLD TOAST_NEEDS_DELETE_OLD
99 #define TOASTCOL_NEEDS_FREE TOAST_NEEDS_FREE
100 #define TOASTCOL_IGNORE 0x0010
101 #define TOASTCOL_INCOMPRESSIBLE 0x0020
102 
103 extern void toast_tuple_init(ToastTupleContext *ttc);
105  bool for_compression,
106  bool check_main);
107 extern void toast_tuple_try_compression(ToastTupleContext *ttc, int attribute);
108 extern void toast_tuple_externalize(ToastTupleContext *ttc, int attribute,
109  int options);
110 extern void toast_tuple_cleanup(ToastTupleContext *ttc);
111 
112 extern void toast_delete_external(Relation rel, Datum *values, bool *isnull,
113  bool is_speculative);
114 
115 #endif
uint8 tai_colflags
Definition: toast_helper.h:34
void toast_tuple_try_compression(ToastTupleContext *ttc, int attribute)
Definition: toast_helper.c:223
unsigned char uint8
Definition: c.h:357
signed int int32
Definition: c.h:347
int toast_tuple_find_biggest_attribute(ToastTupleContext *ttc, bool for_compression, bool check_main)
Definition: toast_helper.c:178
void toast_delete_external(Relation rel, Datum *values, bool *isnull, bool is_speculative)
Definition: toast_helper.c:312
void toast_tuple_externalize(ToastTupleContext *ttc, int attribute, int options)
Definition: toast_helper.c:250
void toast_tuple_cleanup(ToastTupleContext *ttc)
Definition: toast_helper.c:269
uintptr_t Datum
Definition: postgres.h:367
Datum * ttc_oldvalues
Definition: toast_helper.h:51
static Datum values[MAXATTR]
Definition: bootstrap.c:167
void toast_tuple_init(ToastTupleContext *ttc)
Definition: toast_helper.c:39
struct varlena * tai_oldexternal
Definition: toast_helper.h:32
Definition: c.h:550
ToastAttrInfo * ttc_attr
Definition: toast_helper.h:61