PostgreSQL Source Code git master
Loading...
Searching...
No Matches
nbtutils.c File Reference
#include "postgres.h"
#include <time.h>
#include "access/nbtree.h"
#include "access/reloptions.h"
#include "access/relscan.h"
#include "commands/progress.h"
#include "common/int.h"
#include "lib/qunique.h"
#include "miscadmin.h"
#include "storage/lwlock.h"
#include "utils/datum.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
Include dependency graph for nbtutils.c:

Go to the source code of this file.

Data Structures

struct  BTOneVacInfo
 
struct  BTVacInfo
 

Typedefs

typedef struct BTOneVacInfo BTOneVacInfo
 
typedef struct BTVacInfo BTVacInfo
 

Functions

static int _bt_compare_int (const void *va, const void *vb)
 
static int _bt_keep_natts (Relation rel, IndexTuple lastleft, IndexTuple firstright, BTScanInsert itup_key)
 
BTScanInsert _bt_mkscankey (Relation rel, IndexTuple itup)
 
void _bt_killitems (IndexScanDesc scan)
 
BTCycleId _bt_vacuum_cycleid (Relation rel)
 
BTCycleId _bt_start_vacuum (Relation rel)
 
void _bt_end_vacuum (Relation rel)
 
void _bt_end_vacuum_callback (int code, Datum arg)
 
Size BTreeShmemSize (void)
 
void BTreeShmemInit (void)
 
byteabtoptions (Datum reloptions, bool validate)
 
bool btproperty (Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
 
charbtbuildphasename (int64 phasenum)
 
IndexTuple _bt_truncate (Relation rel, IndexTuple lastleft, IndexTuple firstright, BTScanInsert itup_key)
 
int _bt_keep_natts_fast (Relation rel, IndexTuple lastleft, IndexTuple firstright)
 
bool _bt_check_natts (Relation rel, bool heapkeyspace, Page page, OffsetNumber offnum)
 
void _bt_check_third_page (Relation rel, Relation heap, bool needheaptidspace, Page page, IndexTuple newtup)
 
bool _bt_allequalimage (Relation rel, bool debugmessage)
 

Variables

static BTVacInfobtvacinfo
 

Typedef Documentation

◆ BTOneVacInfo

◆ BTVacInfo

Function Documentation

◆ _bt_allequalimage()

bool _bt_allequalimage ( Relation  rel,
bool  debugmessage 
)

Definition at line 1177 of file nbtutils.c.

1178{
1179 bool allequalimage = true;
1180
1181 /* INCLUDE indexes can never support deduplication */
1184 return false;
1185
1186 for (int i = 0; i < IndexRelationGetNumberOfKeyAttributes(rel); i++)
1187 {
1188 Oid opfamily = rel->rd_opfamily[i];
1189 Oid opcintype = rel->rd_opcintype[i];
1190 Oid collation = rel->rd_indcollation[i];
1192
1193 equalimageproc = get_opfamily_proc(opfamily, opcintype, opcintype,
1195
1196 /*
1197 * If there is no BTEQUALIMAGE_PROC then deduplication is assumed to
1198 * be unsafe. Otherwise, actually call proc and see what it says.
1199 */
1200 if (!OidIsValid(equalimageproc) ||
1202 ObjectIdGetDatum(opcintype))))
1203 {
1204 allequalimage = false;
1205 break;
1206 }
1207 }
1208
1209 if (debugmessage)
1210 {
1211 if (allequalimage)
1212 elog(DEBUG1, "index \"%s\" can safely use deduplication",
1214 else
1215 elog(DEBUG1, "index \"%s\" cannot use deduplication",
1217 }
1218
1219 return allequalimage;
1220}
#define OidIsValid(objectId)
Definition c.h:860
#define DEBUG1
Definition elog.h:30
#define elog(elevel,...)
Definition elog.h:226
Datum OidFunctionCall1Coll(Oid functionId, Oid collation, Datum arg1)
Definition fmgr.c:1413
int i
Definition isn.c:77
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Definition lsyscache.c:915
#define BTEQUALIMAGE_PROC
Definition nbtree.h:720
static bool DatumGetBool(Datum X)
Definition postgres.h:100
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
unsigned int Oid
static int fb(int x)
#define RelationGetRelationName(relation)
Definition rel.h:548
#define IndexRelationGetNumberOfAttributes(relation)
Definition rel.h:526
#define IndexRelationGetNumberOfKeyAttributes(relation)
Definition rel.h:533
Oid * rd_opcintype
Definition rel.h:208
Oid * rd_opfamily
Definition rel.h:207
Oid * rd_indcollation
Definition rel.h:217

References BTEQUALIMAGE_PROC, DatumGetBool(), DEBUG1, elog, fb(), get_opfamily_proc(), i, IndexRelationGetNumberOfAttributes, IndexRelationGetNumberOfKeyAttributes, ObjectIdGetDatum(), OidFunctionCall1Coll(), OidIsValid, RelationData::rd_indcollation, RelationData::rd_opcintype, RelationData::rd_opfamily, and RelationGetRelationName.

Referenced by _bt_leafbuild(), bt_index_check_callback(), and btbuildempty().

◆ _bt_check_natts()

bool _bt_check_natts ( Relation  rel,
bool  heapkeyspace,
Page  page,
OffsetNumber  offnum 
)

Definition at line 960 of file nbtutils.c.

961{
964 BTPageOpaque opaque = BTPageGetOpaque(page);
965 IndexTuple itup;
966 int tupnatts;
967
968 /*
969 * We cannot reliably test a deleted or half-dead page, since they have
970 * dummy high keys
971 */
972 if (P_IGNORE(opaque))
973 return true;
974
975 Assert(offnum >= FirstOffsetNumber &&
976 offnum <= PageGetMaxOffsetNumber(page));
977
978 itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
979 tupnatts = BTreeTupleGetNAtts(itup, rel);
980
981 /* !heapkeyspace indexes do not support deduplication */
982 if (!heapkeyspace && BTreeTupleIsPosting(itup))
983 return false;
984
985 /* Posting list tuples should never have "pivot heap TID" bit set */
986 if (BTreeTupleIsPosting(itup) &&
989 return false;
990
991 /* INCLUDE indexes do not support deduplication */
992 if (natts != nkeyatts && BTreeTupleIsPosting(itup))
993 return false;
994
995 if (P_ISLEAF(opaque))
996 {
997 if (offnum >= P_FIRSTDATAKEY(opaque))
998 {
999 /*
1000 * Non-pivot tuple should never be explicitly marked as a pivot
1001 * tuple
1002 */
1003 if (BTreeTupleIsPivot(itup))
1004 return false;
1005
1006 /*
1007 * Leaf tuples that are not the page high key (non-pivot tuples)
1008 * should never be truncated. (Note that tupnatts must have been
1009 * inferred, even with a posting list tuple, because only pivot
1010 * tuples store tupnatts directly.)
1011 */
1012 return tupnatts == natts;
1013 }
1014 else
1015 {
1016 /*
1017 * Rightmost page doesn't contain a page high key, so tuple was
1018 * checked above as ordinary leaf tuple
1019 */
1020 Assert(!P_RIGHTMOST(opaque));
1021
1022 /*
1023 * !heapkeyspace high key tuple contains only key attributes. Note
1024 * that tupnatts will only have been explicitly represented in
1025 * !heapkeyspace indexes that happen to have non-key attributes.
1026 */
1027 if (!heapkeyspace)
1028 return tupnatts == nkeyatts;
1029
1030 /* Use generic heapkeyspace pivot tuple handling */
1031 }
1032 }
1033 else /* !P_ISLEAF(opaque) */
1034 {
1035 if (offnum == P_FIRSTDATAKEY(opaque))
1036 {
1037 /*
1038 * The first tuple on any internal page (possibly the first after
1039 * its high key) is its negative infinity tuple. Negative
1040 * infinity tuples are always truncated to zero attributes. They
1041 * are a particular kind of pivot tuple.
1042 */
1043 if (heapkeyspace)
1044 return tupnatts == 0;
1045
1046 /*
1047 * The number of attributes won't be explicitly represented if the
1048 * negative infinity tuple was generated during a page split that
1049 * occurred with a version of Postgres before v11. There must be
1050 * a problem when there is an explicit representation that is
1051 * non-zero, or when there is no explicit representation and the
1052 * tuple is evidently not a pre-pg_upgrade tuple.
1053 *
1054 * Prior to v11, downlinks always had P_HIKEY as their offset.
1055 * Accept that as an alternative indication of a valid
1056 * !heapkeyspace negative infinity tuple.
1057 */
1058 return tupnatts == 0 ||
1060 }
1061 else
1062 {
1063 /*
1064 * !heapkeyspace downlink tuple with separator key contains only
1065 * key attributes. Note that tupnatts will only have been
1066 * explicitly represented in !heapkeyspace indexes that happen to
1067 * have non-key attributes.
1068 */
1069 if (!heapkeyspace)
1070 return tupnatts == nkeyatts;
1071
1072 /* Use generic heapkeyspace pivot tuple handling */
1073 }
1074 }
1075
1076 /* Handle heapkeyspace pivot tuples (excluding minus infinity items) */
1077 Assert(heapkeyspace);
1078
1079 /*
1080 * Explicit representation of the number of attributes is mandatory with
1081 * heapkeyspace index pivot tuples, regardless of whether or not there are
1082 * non-key attributes.
1083 */
1084 if (!BTreeTupleIsPivot(itup))
1085 return false;
1086
1087 /* Pivot tuple should not use posting list representation (redundant) */
1088 if (BTreeTupleIsPosting(itup))
1089 return false;
1090
1091 /*
1092 * Heap TID is a tiebreaker key attribute, so it cannot be untruncated
1093 * when any other key attribute is truncated
1094 */
1095 if (BTreeTupleGetHeapTID(itup) != NULL && tupnatts != nkeyatts)
1096 return false;
1097
1098 /*
1099 * Pivot tuple must have at least one untruncated key attribute (minus
1100 * infinity pivot tuples are the only exception). Pivot tuples can never
1101 * represent that there is a value present for a key attribute that
1102 * exceeds pg_index.indnkeyatts for the index.
1103 */
1104 return tupnatts > 0 && tupnatts <= nkeyatts;
1105}
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition bufpage.h:269
static void * PageGetItem(PageData *page, const ItemIdData *itemId)
Definition bufpage.h:379
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
Definition bufpage.h:397
#define Assert(condition)
Definition c.h:945
int16_t int16
Definition c.h:613
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
Definition itemptr.h:124
static OffsetNumber ItemPointerGetOffsetNumberNoCheck(const ItemPointerData *pointer)
Definition itemptr.h:114
IndexTupleData * IndexTuple
Definition itup.h:53
#define BT_PIVOT_HEAP_TID_ATTR
Definition nbtree.h:466
static bool BTreeTupleIsPivot(IndexTuple itup)
Definition nbtree.h:481
#define P_ISLEAF(opaque)
Definition nbtree.h:221
#define P_HIKEY
Definition nbtree.h:368
#define BTPageGetOpaque(page)
Definition nbtree.h:74
#define P_FIRSTDATAKEY(opaque)
Definition nbtree.h:370
#define P_RIGHTMOST(opaque)
Definition nbtree.h:220
#define P_IGNORE(opaque)
Definition nbtree.h:226
static bool BTreeTupleIsPosting(IndexTuple itup)
Definition nbtree.h:493
static ItemPointer BTreeTupleGetHeapTID(IndexTuple itup)
Definition nbtree.h:639
#define BTreeTupleGetNAtts(itup, rel)
Definition nbtree.h:578
#define FirstOffsetNumber
Definition off.h:27
ItemPointerData t_tid
Definition itup.h:37

References Assert, BT_PIVOT_HEAP_TID_ATTR, BTPageGetOpaque, BTreeTupleGetHeapTID(), BTreeTupleGetNAtts, BTreeTupleIsPivot(), BTreeTupleIsPosting(), fb(), FirstOffsetNumber, IndexRelationGetNumberOfAttributes, IndexRelationGetNumberOfKeyAttributes, ItemPointerGetOffsetNumber(), ItemPointerGetOffsetNumberNoCheck(), P_FIRSTDATAKEY, P_HIKEY, P_IGNORE, P_ISLEAF, P_RIGHTMOST, PageGetItem(), PageGetItemId(), PageGetMaxOffsetNumber(), and IndexTupleData::t_tid.

Referenced by _bt_compare(), and bt_target_page_check().

◆ _bt_check_third_page()

void _bt_check_third_page ( Relation  rel,
Relation  heap,
bool  needheaptidspace,
Page  page,
IndexTuple  newtup 
)

Definition at line 1120 of file nbtutils.c.

1122{
1123 Size itemsz;
1124 BTPageOpaque opaque;
1125
1126 itemsz = MAXALIGN(IndexTupleSize(newtup));
1127
1128 /* Double check item size against limit */
1129 if (itemsz <= BTMaxItemSize)
1130 return;
1131
1132 /*
1133 * Tuple is probably too large to fit on page, but it's possible that the
1134 * index uses version 2 or version 3, or that page is an internal page, in
1135 * which case a slightly higher limit applies.
1136 */
1137 if (!needheaptidspace && itemsz <= BTMaxItemSizeNoHeapTid)
1138 return;
1139
1140 /*
1141 * Internal page insertions cannot fail here, because that would mean that
1142 * an earlier leaf level insertion that should have failed didn't
1143 */
1144 opaque = BTPageGetOpaque(page);
1145 if (!P_ISLEAF(opaque))
1146 elog(ERROR, "cannot insert oversized tuple of size %zu on internal page of index \"%s\"",
1147 itemsz, RelationGetRelationName(rel));
1148
1149 ereport(ERROR,
1151 errmsg("index row size %zu exceeds btree version %u maximum %zu for index \"%s\"",
1152 itemsz,
1156 errdetail("Index row references tuple (%u,%u) in relation \"%s\".",
1160 errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n"
1161 "Consider a function index of an MD5 hash of the value, "
1162 "or use full text indexing."),
1164}
#define MAXALIGN(LEN)
Definition c.h:898
size_t Size
Definition c.h:691
int errcode(int sqlerrcode)
Definition elog.c:874
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition itemptr.h:103
static Size IndexTupleSize(const IndexTupleData *itup)
Definition itup.h:71
#define BTREE_VERSION
Definition nbtree.h:151
#define BTREE_NOVAC_VERSION
Definition nbtree.h:153
#define BTMaxItemSizeNoHeapTid
Definition nbtree.h:170
#define BTMaxItemSize
Definition nbtree.h:165
static char * errmsg
int errtableconstraint(Relation rel, const char *conname)
Definition relcache.c:6117

References BTMaxItemSize, BTMaxItemSizeNoHeapTid, BTPageGetOpaque, BTREE_NOVAC_VERSION, BTREE_VERSION, BTreeTupleGetHeapTID(), elog, ereport, errcode(), errdetail(), errhint(), errmsg, ERROR, errtableconstraint(), fb(), IndexTupleSize(), ItemPointerGetBlockNumber(), ItemPointerGetOffsetNumber(), MAXALIGN, P_ISLEAF, and RelationGetRelationName.

Referenced by _bt_buildadd(), and _bt_findinsertloc().

◆ _bt_compare_int()

static int _bt_compare_int ( const void va,
const void vb 
)
static

Definition at line 152 of file nbtutils.c.

153{
154 int a = *((const int *) va);
155 int b = *((const int *) vb);
156
157 return pg_cmp_s32(a, b);
158}
static int pg_cmp_s32(int32 a, int32 b)
Definition int.h:713
int b
Definition isn.c:74
int a
Definition isn.c:73

References a, b, fb(), and pg_cmp_s32().

Referenced by _bt_killitems().

◆ _bt_end_vacuum()

void _bt_end_vacuum ( Relation  rel)

Definition at line 522 of file nbtutils.c.

523{
524 int i;
525
527
528 /* Find the array entry */
529 for (i = 0; i < btvacinfo->num_vacuums; i++)
530 {
532
533 if (vac->relid.relId == rel->rd_lockInfo.lockRelId.relId &&
534 vac->relid.dbId == rel->rd_lockInfo.lockRelId.dbId)
535 {
536 /* Remove it by shifting down the last entry */
539 break;
540 }
541 }
542
544}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1153
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1770
@ LW_EXCLUSIVE
Definition lwlock.h:104
static BTVacInfo * btvacinfo
Definition nbtutils.c:418
LockRelId relid
Definition nbtutils.c:406
int num_vacuums
Definition nbtutils.c:413
BTOneVacInfo vacuums[FLEXIBLE_ARRAY_MEMBER]
Definition nbtutils.c:415
LockRelId lockRelId
Definition rel.h:46
Oid relId
Definition rel.h:40
Oid dbId
Definition rel.h:41
LockInfoData rd_lockInfo
Definition rel.h:114

References btvacinfo, LockRelId::dbId, fb(), i, LockInfoData::lockRelId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), BTVacInfo::num_vacuums, RelationData::rd_lockInfo, BTOneVacInfo::relid, LockRelId::relId, and BTVacInfo::vacuums.

Referenced by _bt_end_vacuum_callback(), and btbulkdelete().

◆ _bt_end_vacuum_callback()

void _bt_end_vacuum_callback ( int  code,
Datum  arg 
)

Definition at line 550 of file nbtutils.c.

551{
553}
Datum arg
Definition elog.c:1322
void _bt_end_vacuum(Relation rel)
Definition nbtutils.c:522
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332

References _bt_end_vacuum(), arg, and DatumGetPointer().

Referenced by btbulkdelete().

◆ _bt_keep_natts()

static int _bt_keep_natts ( Relation  rel,
IndexTuple  lastleft,
IndexTuple  firstright,
BTScanInsert  itup_key 
)
static

Definition at line 839 of file nbtutils.c.

841{
844 int keepnatts;
846
847 /*
848 * _bt_compare() treats truncated key attributes as having the value minus
849 * infinity, which would break searches within !heapkeyspace indexes. We
850 * must still truncate away non-key attribute values, though.
851 */
852 if (!itup_key->heapkeyspace)
853 return nkeyatts;
854
855 scankey = itup_key->scankeys;
856 keepnatts = 1;
857 for (int attnum = 1; attnum <= nkeyatts; attnum++, scankey++)
858 {
859 Datum datum1,
860 datum2;
861 bool isNull1,
862 isNull2;
863
864 datum1 = index_getattr(lastleft, attnum, itupdesc, &isNull1);
866
867 if (isNull1 != isNull2)
868 break;
869
870 if (!isNull1 &&
872 scankey->sk_collation,
873 datum1,
874 datum2)) != 0)
875 break;
876
877 keepnatts++;
878 }
879
880 /*
881 * Assert that _bt_keep_natts_fast() agrees with us in passing. This is
882 * expected in an allequalimage index.
883 */
884 Assert(!itup_key->allequalimage ||
885 keepnatts == _bt_keep_natts_fast(rel, lastleft, firstright));
886
887 return keepnatts;
888}
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition fmgr.c:1151
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition itup.h:131
int _bt_keep_natts_fast(Relation rel, IndexTuple lastleft, IndexTuple firstright)
Definition nbtutils.c:913
int16 attnum
uint64_t Datum
Definition postgres.h:70
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
#define RelationGetDescr(relation)
Definition rel.h:540
bool allequalimage
Definition nbtree.h:798
bool heapkeyspace
Definition nbtree.h:797
ScanKeyData scankeys[INDEX_MAX_KEYS]
Definition nbtree.h:804

References _bt_keep_natts_fast(), BTScanInsertData::allequalimage, Assert, attnum, DatumGetInt32(), fb(), FunctionCall2Coll(), BTScanInsertData::heapkeyspace, index_getattr(), IndexRelationGetNumberOfKeyAttributes, RelationGetDescr, and BTScanInsertData::scankeys.

Referenced by _bt_truncate().

◆ _bt_keep_natts_fast()

int _bt_keep_natts_fast ( Relation  rel,
IndexTuple  lastleft,
IndexTuple  firstright 
)

Definition at line 913 of file nbtutils.c.

914{
917 int keepnatts;
918
919 keepnatts = 1;
920 for (int attnum = 1; attnum <= keysz; attnum++)
921 {
922 Datum datum1,
923 datum2;
924 bool isNull1,
925 isNull2;
927
928 datum1 = index_getattr(lastleft, attnum, itupdesc, &isNull1);
931
932 if (isNull1 != isNull2)
933 break;
934
935 if (!isNull1 &&
936 !datum_image_eq(datum1, datum2, att->attbyval, att->attlen))
937 break;
938
939 keepnatts++;
940 }
941
942 return keepnatts;
943}
bool datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
Definition datum.c:266
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:195

References attnum, datum_image_eq(), fb(), index_getattr(), IndexRelationGetNumberOfKeyAttributes, RelationGetDescr, and TupleDescCompactAttr().

Referenced by _bt_afternewitemoff(), _bt_bottomupdel_pass(), _bt_dedup_pass(), _bt_do_singleval(), _bt_keep_natts(), _bt_load(), _bt_set_startikey(), _bt_split_penalty(), and _bt_strategy().

◆ _bt_killitems()

void _bt_killitems ( IndexScanDesc  scan)

Definition at line 190 of file nbtutils.c.

191{
192 Relation rel = scan->indexRelation;
194 Page page;
195 BTPageOpaque opaque;
196 OffsetNumber minoff;
197 OffsetNumber maxoff;
198 int numKilled = so->numKilled;
199 bool killedsomething = false;
200 Buffer buf;
201
202 Assert(numKilled > 0);
203 Assert(BTScanPosIsValid(so->currPos));
204 Assert(scan->heapRelation != NULL); /* can't be a bitmap index scan */
205
206 /* Always invalidate so->killedItems[] before leaving so->currPos */
207 so->numKilled = 0;
208
209 /*
210 * We need to iterate through so->killedItems[] in leaf page order; the
211 * loop below expects this (when marking posting list tuples, at least).
212 * so->killedItems[] is now in whatever order the scan returned items in.
213 * Scrollable cursor scans might have even saved the same item/TID twice.
214 *
215 * Sort and unique-ify so->killedItems[] to deal with all this.
216 */
217 if (numKilled > 1)
218 {
219 qsort(so->killedItems, numKilled, sizeof(int), _bt_compare_int);
220 numKilled = qunique(so->killedItems, numKilled, sizeof(int),
222 }
223
224 if (!so->dropPin)
225 {
226 /*
227 * We have held the pin on this page since we read the index tuples,
228 * so all we need to do is lock it. The pin will have prevented
229 * concurrent VACUUMs from recycling any of the TIDs on the page.
230 */
231 Assert(BTScanPosIsPinned(so->currPos));
232 buf = so->currPos.buf;
233 _bt_lockbuf(rel, buf, BT_READ);
234 }
235 else
236 {
238
239 Assert(!BTScanPosIsPinned(so->currPos));
240 buf = _bt_getbuf(rel, so->currPos.currPage, BT_READ);
241
243 Assert(so->currPos.lsn <= latestlsn);
244 if (so->currPos.lsn != latestlsn)
245 {
246 /* Modified, give up on hinting */
247 _bt_relbuf(rel, buf);
248 return;
249 }
250
251 /* Unmodified, hinting is safe */
252 }
253
254 page = BufferGetPage(buf);
255 opaque = BTPageGetOpaque(page);
256 minoff = P_FIRSTDATAKEY(opaque);
257 maxoff = PageGetMaxOffsetNumber(page);
258
259 /* Iterate through so->killedItems[] in leaf page order */
260 for (int i = 0; i < numKilled; i++)
261 {
262 int itemIndex = so->killedItems[i];
263 BTScanPosItem *kitem = &so->currPos.items[itemIndex];
265
266 Assert(itemIndex >= so->currPos.firstItem &&
267 itemIndex <= so->currPos.lastItem);
268 Assert(i == 0 ||
269 offnum >= so->currPos.items[so->killedItems[i - 1]].indexOffset);
270
271 if (offnum < minoff)
272 continue; /* pure paranoia */
273 while (offnum <= maxoff)
274 {
275 ItemId iid = PageGetItemId(page, offnum);
277 bool killtuple = false;
278
280 {
281 int pi = i + 1;
283 int j;
284
285 /*
286 * Note that the page may have been modified in almost any way
287 * since we first read it (in the !so->dropPin case), so it's
288 * possible that this posting list tuple wasn't a posting list
289 * tuple when we first encountered its heap TIDs.
290 */
291 for (j = 0; j < nposting; j++)
292 {
294
295 if (!ItemPointerEquals(item, &kitem->heapTid))
296 break; /* out of posting list loop */
297
298 /*
299 * kitem must have matching offnum when heap TIDs match,
300 * though only in the common case where the page can't
301 * have been concurrently modified
302 */
303 Assert(kitem->indexOffset == offnum || !so->dropPin);
304
305 /*
306 * Read-ahead to later kitems here.
307 *
308 * We rely on the assumption that not advancing kitem here
309 * will prevent us from considering the posting list tuple
310 * fully dead by not matching its next heap TID in next
311 * loop iteration.
312 *
313 * If, on the other hand, this is the final heap TID in
314 * the posting list tuple, then tuple gets killed
315 * regardless (i.e. we handle the case where the last
316 * kitem is also the last heap TID in the last index tuple
317 * correctly -- posting tuple still gets killed).
318 */
319 if (pi < numKilled)
320 kitem = &so->currPos.items[so->killedItems[pi++]];
321 }
322
323 /*
324 * Don't bother advancing the outermost loop's int iterator to
325 * avoid processing killed items that relate to the same
326 * offnum/posting list tuple. This micro-optimization hardly
327 * seems worth it. (Further iterations of the outermost loop
328 * will fail to match on this same posting list's first heap
329 * TID instead, so we'll advance to the next offnum/index
330 * tuple pretty quickly.)
331 */
332 if (j == nposting)
333 killtuple = true;
334 }
335 else if (ItemPointerEquals(&ituple->t_tid, &kitem->heapTid))
336 killtuple = true;
337
338 /*
339 * Mark index item as dead, if it isn't already. Since this
340 * happens while holding a buffer lock possibly in shared mode,
341 * it's possible that multiple processes attempt to do this
342 * simultaneously, leading to multiple full-page images being sent
343 * to WAL (if wal_log_hints or data checksums are enabled), which
344 * is undesirable.
345 */
346 if (killtuple && !ItemIdIsDead(iid))
347 {
348 if (!killedsomething)
349 {
350 /*
351 * Use the hint bit infrastructure to check if we can
352 * update the page while just holding a share lock. If we
353 * are not allowed, there's no point continuing.
354 */
356 goto unlock_page;
357 }
358
359 /* found the item/all posting list items */
361 killedsomething = true;
362 break; /* out of inner search loop */
363 }
364 offnum = OffsetNumberNext(offnum);
365 }
366 }
367
368 /*
369 * Since this can be redone later if needed, mark as dirty hint.
370 *
371 * Whenever we mark anything LP_DEAD, we also set the page's
372 * BTP_HAS_GARBAGE flag, which is likewise just a hint. (Note that we
373 * only rely on the page-level flag in !heapkeyspace indexes.)
374 */
375 if (killedsomething)
376 {
377 opaque->btpo_flags |= BTP_HAS_GARBAGE;
378 BufferFinishSetHintBits(buf, true, true);
379 }
380
382 if (!so->dropPin)
383 _bt_unlockbuf(rel, buf);
384 else
385 _bt_relbuf(rel, buf);
386}
int Buffer
Definition buf.h:23
void BufferFinishSetHintBits(Buffer buffer, bool mark_dirty, bool buffer_std)
Definition bufmgr.c:7050
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
Definition bufmgr.c:4693
bool BufferBeginSetHintBits(Buffer buffer)
Definition bufmgr.c:7022
static Page BufferGetPage(Buffer buffer)
Definition bufmgr.h:472
PageData * Page
Definition bufpage.h:81
int j
Definition isn.c:78
#define ItemIdMarkDead(itemId)
Definition itemid.h:179
#define ItemIdIsDead(itemId)
Definition itemid.h:113
bool ItemPointerEquals(const ItemPointerData *pointer1, const ItemPointerData *pointer2)
Definition itemptr.c:35
void _bt_relbuf(Relation rel, Buffer buf)
Definition nbtpage.c:1044
Buffer _bt_getbuf(Relation rel, BlockNumber blkno, int access)
Definition nbtpage.c:850
void _bt_unlockbuf(Relation rel, Buffer buf)
Definition nbtpage.c:1098
void _bt_lockbuf(Relation rel, Buffer buf, int access)
Definition nbtpage.c:1067
#define BTScanPosIsPinned(scanpos)
Definition nbtree.h:1004
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
Definition nbtree.h:519
#define BTP_HAS_GARBAGE
Definition nbtree.h:83
#define BTScanPosIsValid(scanpos)
Definition nbtree.h:1021
static ItemPointer BTreeTupleGetPostingN(IndexTuple posting, int n)
Definition nbtree.h:545
#define BT_READ
Definition nbtree.h:730
BTScanOpaqueData * BTScanOpaque
Definition nbtree.h:1097
static int _bt_compare_int(const void *va, const void *vb)
Definition nbtutils.c:152
#define OffsetNumberNext(offsetNumber)
Definition off.h:52
uint16 OffsetNumber
Definition off.h:24
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define qsort(a, b, c, d)
Definition port.h:495
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
Definition qunique.h:21
uint16 btpo_flags
Definition nbtree.h:68
OffsetNumber indexOffset
Definition nbtree.h:958
Relation indexRelation
Definition relscan.h:138
Relation heapRelation
Definition relscan.h:137
uint64 XLogRecPtr
Definition xlogdefs.h:21

References _bt_compare_int(), _bt_getbuf(), _bt_lockbuf(), _bt_relbuf(), _bt_unlockbuf(), Assert, BT_READ, BTP_HAS_GARBAGE, BTPageGetOpaque, BTPageOpaqueData::btpo_flags, BTreeTupleGetNPosting(), BTreeTupleGetPostingN(), BTreeTupleIsPosting(), BTScanPosIsPinned, BTScanPosIsValid, buf, BufferBeginSetHintBits(), BufferFinishSetHintBits(), BufferGetLSNAtomic(), BufferGetPage(), fb(), IndexScanDescData::heapRelation, i, BTScanPosItem::indexOffset, IndexScanDescData::indexRelation, ItemIdIsDead, ItemIdMarkDead, ItemPointerEquals(), j, OffsetNumberNext, IndexScanDescData::opaque, P_FIRSTDATAKEY, PageGetItem(), PageGetItemId(), PageGetMaxOffsetNumber(), qsort, and qunique().

Referenced by _bt_steppage(), btendscan(), btrescan(), and btrestrpos().

◆ _bt_mkscankey()

BTScanInsert _bt_mkscankey ( Relation  rel,
IndexTuple  itup 
)

Definition at line 60 of file nbtutils.c.

61{
65 int indnkeyatts;
67 int tupnatts;
68 int i;
69
73 tupnatts = itup ? BTreeTupleGetNAtts(itup, rel) : 0;
74
76
77 /*
78 * We'll execute search using scan key constructed on key columns.
79 * Truncated attributes and non-key attributes are omitted from the final
80 * scan key.
81 */
82 key = palloc(offsetof(BTScanInsertData, scankeys) +
83 sizeof(ScanKeyData) * indnkeyatts);
84 if (itup)
85 _bt_metaversion(rel, &key->heapkeyspace, &key->allequalimage);
86 else
87 {
88 /* Utility statement callers can set these fields themselves */
89 key->heapkeyspace = true;
90 key->allequalimage = false;
91 }
92 key->anynullkeys = false; /* initial assumption */
93 key->nextkey = false; /* usual case, required by btinsert */
94 key->backward = false; /* usual case, required by btinsert */
95 key->keysz = Min(indnkeyatts, tupnatts);
96 key->scantid = key->heapkeyspace && itup ?
98 skey = key->scankeys;
99 for (i = 0; i < indnkeyatts; i++)
100 {
102 Datum arg;
103 bool null;
104 int flags;
105
106 /*
107 * We can use the cached (default) support procs since no cross-type
108 * comparison can be needed.
109 */
111
112 /*
113 * Key arguments built from truncated attributes (or when caller
114 * provides no tuple) are defensively represented as NULL values. They
115 * should never be used.
116 */
117 if (i < tupnatts)
118 arg = index_getattr(itup, i + 1, itupdesc, &null);
119 else
120 {
121 arg = (Datum) 0;
122 null = true;
123 }
124 flags = (null ? SK_ISNULL : 0) | (indoption[i] << SK_BT_INDOPTION_SHIFT);
126 flags,
127 (AttrNumber) (i + 1),
130 rel->rd_indcollation[i],
131 procinfo,
132 arg);
133 /* Record if any key attribute is NULL (or truncated) */
134 if (null)
135 key->anynullkeys = true;
136 }
137
138 /*
139 * In NULLS NOT DISTINCT mode, we pretend that there are no null keys, so
140 * that full uniqueness check is done.
141 */
142 if (rel->rd_index->indnullsnotdistinct)
143 key->anynullkeys = false;
144
145 return key;
146}
int16 AttrNumber
Definition attnum.h:21
#define Min(x, y)
Definition c.h:1093
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition indexam.c:918
void * palloc(Size size)
Definition mcxt.c:1387
void _bt_metaversion(Relation rel, bool *heapkeyspace, bool *allequalimage)
Definition nbtpage.c:744
#define BTORDER_PROC
Definition nbtree.h:717
#define SK_BT_INDOPTION_SHIFT
Definition nbtree.h:1115
#define InvalidOid
void ScanKeyEntryInitializeWithInfo(ScanKey entry, int flags, AttrNumber attributeNumber, StrategyNumber strategy, Oid subtype, Oid collation, FmgrInfo *finfo, Datum argument)
Definition scankey.c:101
#define SK_ISNULL
Definition skey.h:115
#define InvalidStrategy
Definition stratnum.h:24
int16 * rd_indoption
Definition rel.h:211
Form_pg_index rd_index
Definition rel.h:192

References _bt_metaversion(), arg, Assert, BTORDER_PROC, BTreeTupleGetHeapTID(), BTreeTupleGetNAtts, fb(), i, index_getattr(), index_getprocinfo(), IndexRelationGetNumberOfAttributes, IndexRelationGetNumberOfKeyAttributes, InvalidOid, InvalidStrategy, Min, palloc(), RelationData::rd_indcollation, RelationData::rd_index, RelationData::rd_indoption, RelationGetDescr, ScanKeyEntryInitializeWithInfo(), SK_BT_INDOPTION_SHIFT, and SK_ISNULL.

Referenced by _bt_doinsert(), _bt_leafbuild(), _bt_pagedel(), bt_mkscankey_pivotsearch(), bt_rootdescend(), tuplesort_begin_cluster(), and tuplesort_begin_index_btree().

◆ _bt_start_vacuum()

BTCycleId _bt_start_vacuum ( Relation  rel)

Definition at line 465 of file nbtutils.c.

466{
467 BTCycleId result;
468 int i;
469 BTOneVacInfo *vac;
470
472
473 /*
474 * Assign the next cycle ID, being careful to avoid zero as well as the
475 * reserved high values.
476 */
477 result = ++(btvacinfo->cycle_ctr);
478 if (result == 0 || result > MAX_BT_CYCLE_ID)
479 result = btvacinfo->cycle_ctr = 1;
480
481 /* Let's just make sure there's no entry already for this index */
482 for (i = 0; i < btvacinfo->num_vacuums; i++)
483 {
484 vac = &btvacinfo->vacuums[i];
485 if (vac->relid.relId == rel->rd_lockInfo.lockRelId.relId &&
486 vac->relid.dbId == rel->rd_lockInfo.lockRelId.dbId)
487 {
488 /*
489 * Unlike most places in the backend, we have to explicitly
490 * release our LWLock before throwing an error. This is because
491 * we expect _bt_end_vacuum() to be called before transaction
492 * abort cleanup can run to release LWLocks.
493 */
495 elog(ERROR, "multiple active vacuums for index \"%s\"",
497 }
498 }
499
500 /* OK, add an entry */
502 {
504 elog(ERROR, "out of btvacinfo slots");
505 }
507 vac->relid = rel->rd_lockInfo.lockRelId;
508 vac->cycleid = result;
510
512 return result;
513}
#define MAX_BT_CYCLE_ID
Definition nbtree.h:94
uint16 BTCycleId
Definition nbtree.h:30
BTCycleId cycleid
Definition nbtutils.c:407
BTCycleId cycle_ctr
Definition nbtutils.c:412
int max_vacuums
Definition nbtutils.c:414

References btvacinfo, BTVacInfo::cycle_ctr, BTOneVacInfo::cycleid, LockRelId::dbId, elog, ERROR, fb(), i, LockInfoData::lockRelId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAX_BT_CYCLE_ID, BTVacInfo::max_vacuums, BTVacInfo::num_vacuums, RelationData::rd_lockInfo, RelationGetRelationName, BTOneVacInfo::relid, LockRelId::relId, and BTVacInfo::vacuums.

Referenced by btbulkdelete().

◆ _bt_truncate()

IndexTuple _bt_truncate ( Relation  rel,
IndexTuple  lastleft,
IndexTuple  firstright,
BTScanInsert  itup_key 
)

Definition at line 694 of file nbtutils.c.

696{
699 int keepnatts;
704
705 /*
706 * We should only ever truncate non-pivot tuples from leaf pages. It's
707 * never okay to truncate when splitting an internal page.
708 */
710
711 /* Determine how many attributes must be kept in truncated tuple */
712 keepnatts = _bt_keep_natts(rel, lastleft, firstright, itup_key);
713
714#ifdef DEBUG_NO_TRUNCATE
715 /* Force truncation to be ineffective for testing purposes */
716 keepnatts = nkeyatts + 1;
717#endif
718
721
723 {
724 /*
725 * index_truncate_tuple() just returns a straight copy of firstright
726 * when it has no attributes to truncate. When that happens, we may
727 * need to truncate away a posting list here instead.
728 */
731 pivot->t_info &= ~INDEX_SIZE_MASK;
733 }
734
735 /*
736 * If there is a distinguishing key attribute within pivot tuple, we're
737 * done
738 */
739 if (keepnatts <= nkeyatts)
740 {
742 return pivot;
743 }
744
745 /*
746 * We have to store a heap TID in the new pivot tuple, since no non-TID
747 * key attribute value in firstright distinguishes the right side of the
748 * split from the left side. nbtree conceptualizes this case as an
749 * inability to truncate away any key attributes, since heap TID is
750 * treated as just another key attribute (despite lacking a pg_attribute
751 * entry).
752 *
753 * Use enlarged space that holds a copy of pivot. We need the extra space
754 * to store a heap TID at the end (using the special pivot tuple
755 * representation). Note that the original pivot already has firstright's
756 * possible posting list/non-key attribute values removed at this point.
757 */
761 /* Cannot leak memory here */
762 pfree(pivot);
763
764 /*
765 * Store all of firstright's key attribute values plus a tiebreaker heap
766 * TID value in enlarged pivot tuple
767 */
768 tidpivot->t_info &= ~INDEX_SIZE_MASK;
769 tidpivot->t_info |= newsize;
772
773 /*
774 * Lehman & Yao use lastleft as the leaf high key in all cases, but don't
775 * consider suffix truncation. It seems like a good idea to follow that
776 * example in cases where no truncation takes place -- use lastleft's heap
777 * TID. (This is also the closest value to negative infinity that's
778 * legally usable.)
779 */
781
782 /*
783 * We're done. Assert() that heap TID invariants hold before returning.
784 *
785 * Lehman and Yao require that the downlink to the right page, which is to
786 * be inserted into the parent page in the second phase of a page split be
787 * a strict lower bound on items on the right page, and a non-strict upper
788 * bound for items on the left page. Assert that heap TIDs follow these
789 * invariants, since a heap TID value is apparently needed as a
790 * tiebreaker.
791 */
792#ifndef DEBUG_NO_TRUNCATE
796 BTreeTupleGetHeapTID(lastleft)) >= 0);
799#else
800
801 /*
802 * Those invariants aren't guaranteed to hold for lastleft + firstright
803 * heap TID attribute values when they're considered here only because
804 * DEBUG_NO_TRUNCATE is defined (a heap TID is probably not actually
805 * needed as a tiebreaker). DEBUG_NO_TRUNCATE must therefore use a heap
806 * TID value that always works as a strict lower bound for items to the
807 * right. In particular, it must avoid using firstright's leading key
808 * attribute values along with lastleft's heap TID value when lastleft's
809 * TID happens to be greater than firstright's TID.
810 */
812
813 /*
814 * Pivot heap TID should never be fully equal to firstright. Note that
815 * the pivot heap TID will still end up equal to lastleft's heap TID when
816 * that's the only usable value.
817 */
822#endif
823
824 return tidpivot;
825}
IndexTuple index_truncate_tuple(TupleDesc sourceDescriptor, IndexTuple source, int leavenatts)
Definition indextuple.c:508
int32 ItemPointerCompare(const ItemPointerData *arg1, const ItemPointerData *arg2)
Definition itemptr.c:51
static void ItemPointerSetOffsetNumber(ItemPointerData *pointer, OffsetNumber offsetNumber)
Definition itemptr.h:158
static void ItemPointerCopy(const ItemPointerData *fromPointer, ItemPointerData *toPointer)
Definition itemptr.h:172
void pfree(void *pointer)
Definition mcxt.c:1616
void * palloc0(Size size)
Definition mcxt.c:1417
static uint32 BTreeTupleGetPostingOffset(IndexTuple posting)
Definition nbtree.h:530
static ItemPointer BTreeTupleGetMaxHeapTID(IndexTuple itup)
Definition nbtree.h:665
static void BTreeTupleSetNAtts(IndexTuple itup, uint16 nkeyatts, bool heaptid)
Definition nbtree.h:596
static int _bt_keep_natts(Relation rel, IndexTuple lastleft, IndexTuple firstright, BTScanInsert itup_key)
Definition nbtutils.c:839
#define OffsetNumberPrev(offsetNumber)
Definition off.h:54

References _bt_keep_natts(), Assert, BTreeTupleGetHeapTID(), BTreeTupleGetMaxHeapTID(), BTreeTupleGetPostingOffset(), BTreeTupleIsPivot(), BTreeTupleIsPosting(), BTreeTupleSetNAtts(), fb(), index_truncate_tuple(), IndexRelationGetNumberOfAttributes, IndexRelationGetNumberOfKeyAttributes, IndexTupleSize(), ItemPointerCompare(), ItemPointerCopy(), ItemPointerGetOffsetNumber(), ItemPointerSetOffsetNumber(), MAXALIGN, Min, OffsetNumberPrev, palloc0(), pfree(), and RelationGetDescr.

Referenced by _bt_buildadd(), and _bt_split().

◆ _bt_vacuum_cycleid()

BTCycleId _bt_vacuum_cycleid ( Relation  rel)

Definition at line 431 of file nbtutils.c.

432{
433 BTCycleId result = 0;
434 int i;
435
436 /* Share lock is enough since this is a read-only operation */
438
439 for (i = 0; i < btvacinfo->num_vacuums; i++)
440 {
442
443 if (vac->relid.relId == rel->rd_lockInfo.lockRelId.relId &&
444 vac->relid.dbId == rel->rd_lockInfo.lockRelId.dbId)
445 {
446 result = vac->cycleid;
447 break;
448 }
449 }
450
452 return result;
453}
@ LW_SHARED
Definition lwlock.h:105

References btvacinfo, BTOneVacInfo::cycleid, LockRelId::dbId, fb(), i, LockInfoData::lockRelId, LW_SHARED, LWLockAcquire(), LWLockRelease(), BTVacInfo::num_vacuums, RelationData::rd_lockInfo, BTOneVacInfo::relid, LockRelId::relId, and BTVacInfo::vacuums.

Referenced by _bt_split().

◆ btbuildphasename()

char * btbuildphasename ( int64  phasenum)

Definition at line 646 of file nbtutils.c.

647{
648 switch (phasenum)
649 {
651 return "initializing";
653 return "scanning table";
655 return "sorting live tuples";
657 return "sorting dead tuples";
659 return "loading tuples in tree";
660 default:
661 return NULL;
662 }
663}
#define PROGRESS_BTREE_PHASE_PERFORMSORT_2
Definition nbtree.h:1148
#define PROGRESS_BTREE_PHASE_LEAF_LOAD
Definition nbtree.h:1149
#define PROGRESS_BTREE_PHASE_INDEXBUILD_TABLESCAN
Definition nbtree.h:1146
#define PROGRESS_BTREE_PHASE_PERFORMSORT_1
Definition nbtree.h:1147
#define PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE
Definition progress.h:132

References fb(), PROGRESS_BTREE_PHASE_INDEXBUILD_TABLESCAN, PROGRESS_BTREE_PHASE_LEAF_LOAD, PROGRESS_BTREE_PHASE_PERFORMSORT_1, PROGRESS_BTREE_PHASE_PERFORMSORT_2, and PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE.

Referenced by bthandler().

◆ btoptions()

bytea * btoptions ( Datum  reloptions,
bool  validate 
)

Definition at line 600 of file nbtutils.c.

601{
602 static const relopt_parse_elt tab[] = {
603 {"fillfactor", RELOPT_TYPE_INT, offsetof(BTOptions, fillfactor)},
604 {"vacuum_cleanup_index_scale_factor", RELOPT_TYPE_REAL,
605 offsetof(BTOptions, vacuum_cleanup_index_scale_factor)},
606 {"deduplicate_items", RELOPT_TYPE_BOOL,
607 offsetof(BTOptions, deduplicate_items)}
608 };
609
610 return (bytea *) build_reloptions(reloptions, validate,
612 sizeof(BTOptions),
613 tab, lengthof(tab));
614}
static bool validate(Port *port, const char *auth)
Definition auth-oauth.c:638
#define lengthof(array)
Definition c.h:875
static int fillfactor
Definition pgbench.c:188
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
@ RELOPT_KIND_BTREE
Definition reloptions.h:44
@ RELOPT_TYPE_INT
Definition reloptions.h:32
@ RELOPT_TYPE_BOOL
Definition reloptions.h:30
@ RELOPT_TYPE_REAL
Definition reloptions.h:33
Definition c.h:778

References build_reloptions(), fb(), fillfactor, lengthof, RELOPT_KIND_BTREE, RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, and validate().

Referenced by bthandler().

◆ btproperty()

bool btproperty ( Oid  index_oid,
int  attno,
IndexAMProperty  prop,
const char propname,
bool res,
bool isnull 
)

Definition at line 623 of file nbtutils.c.

626{
627 switch (prop)
628 {
630 /* answer only for columns, not AM or whole index */
631 if (attno == 0)
632 return false;
633 /* otherwise, btree can always return data */
634 *res = true;
635 return true;
636
637 default:
638 return false; /* punt to generic code */
639 }
640}
@ AMPROP_RETURNABLE
Definition amapi.h:47

References AMPROP_RETURNABLE.

Referenced by bthandler().

◆ BTreeShmemInit()

void BTreeShmemInit ( void  )

Definition at line 572 of file nbtutils.c.

573{
574 bool found;
575
576 btvacinfo = (BTVacInfo *) ShmemInitStruct("BTree Vacuum State",
578 &found);
579
581 {
582 /* Initialize shared memory area */
583 Assert(!found);
584
585 /*
586 * It doesn't really matter what the cycle counter starts at, but
587 * having it always start the same doesn't seem good. Seed with
588 * low-order bits of time() instead.
589 */
591
594 }
595 else
596 Assert(found);
597}
bool IsUnderPostmaster
Definition globals.c:120
int MaxBackends
Definition globals.c:146
Size BTreeShmemSize(void)
Definition nbtutils.c:559
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:380

References Assert, BTreeShmemSize(), btvacinfo, BTVacInfo::cycle_ctr, fb(), IsUnderPostmaster, BTVacInfo::max_vacuums, MaxBackends, BTVacInfo::num_vacuums, and ShmemInitStruct().

Referenced by CreateOrAttachShmemStructs().

◆ BTreeShmemSize()

Size BTreeShmemSize ( void  )

Definition at line 559 of file nbtutils.c.

560{
561 Size size;
562
563 size = offsetof(BTVacInfo, vacuums);
564 size = add_size(size, mul_size(MaxBackends, sizeof(BTOneVacInfo)));
565 return size;
566}
Size add_size(Size s1, Size s2)
Definition shmem.c:455
Size mul_size(Size s1, Size s2)
Definition shmem.c:470

References add_size(), fb(), MaxBackends, and mul_size().

Referenced by BTreeShmemInit(), and CalculateShmemSize().

Variable Documentation

◆ btvacinfo

BTVacInfo* btvacinfo
static

Definition at line 418 of file nbtutils.c.

Referenced by _bt_end_vacuum(), _bt_start_vacuum(), _bt_vacuum_cycleid(), and BTreeShmemInit().