PostgreSQL Source Code  git master
ginvacuum.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * ginvacuum.c
4  * delete & vacuum routines for the postgres GIN
5  *
6  *
7  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * IDENTIFICATION
11  * src/backend/access/gin/ginvacuum.c
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "postgres.h"
16 
17 #include "access/gin_private.h"
18 #include "access/ginxlog.h"
19 #include "access/xloginsert.h"
20 #include "commands/vacuum.h"
21 #include "miscadmin.h"
22 #include "postmaster/autovacuum.h"
23 #include "storage/indexfsm.h"
24 #include "storage/lmgr.h"
25 #include "storage/predicate.h"
26 #include "utils/memutils.h"
27 
29 {
37 };
38 
39 /*
40  * Vacuums an uncompressed posting list. The size of the must can be specified
41  * in number of items (nitems).
42  *
43  * If none of the items need to be removed, returns NULL. Otherwise returns
44  * a new palloc'd array with the remaining items. The number of remaining
45  * items is returned in *nremaining.
46  */
49  int nitem, int *nremaining)
50 {
51  int i,
52  remaining = 0;
53  ItemPointer tmpitems = NULL;
54 
55  /*
56  * Iterate over TIDs array
57  */
58  for (i = 0; i < nitem; i++)
59  {
60  if (gvs->callback(items + i, gvs->callback_state))
61  {
62  gvs->result->tuples_removed += 1;
63  if (!tmpitems)
64  {
65  /*
66  * First TID to be deleted: allocate memory to hold the
67  * remaining items.
68  */
69  tmpitems = palloc(sizeof(ItemPointerData) * nitem);
70  memcpy(tmpitems, items, sizeof(ItemPointerData) * i);
71  }
72  }
73  else
74  {
75  gvs->result->num_index_tuples += 1;
76  if (tmpitems)
77  tmpitems[remaining] = items[i];
78  remaining++;
79  }
80  }
81 
82  *nremaining = remaining;
83  return tmpitems;
84 }
85 
86 /*
87  * Create a WAL record for vacuuming entry tree leaf page.
88  */
89 static void
91 {
92  Page page = BufferGetPage(buffer);
93  XLogRecPtr recptr;
94 
95  /* This is only used for entry tree leaf pages. */
96  Assert(!GinPageIsData(page));
97  Assert(GinPageIsLeaf(page));
98 
99  if (!RelationNeedsWAL(index))
100  return;
101 
102  /*
103  * Always create a full image, we don't track the changes on the page at
104  * any more fine-grained level. This could obviously be improved...
105  */
106  XLogBeginInsert();
108 
109  recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_VACUUM_PAGE);
110  PageSetLSN(page, recptr);
111 }
112 
113 
114 typedef struct DataPageDeleteStack
115 {
118 
119  BlockNumber blkno; /* current block number */
120  Buffer leftBuffer; /* pinned and locked rightest non-deleted page
121  * on left */
122  bool isRoot;
124 
125 
126 /*
127  * Delete a posting tree page.
128  */
129 static void
131  BlockNumber parentBlkno, OffsetNumber myoff, bool isParentRoot)
132 {
133  Buffer dBuffer;
134  Buffer lBuffer;
135  Buffer pBuffer;
136  Page page,
137  parentPage;
138  BlockNumber rightlink;
139 
140  /*
141  * This function MUST be called only if someone of parent pages hold
142  * exclusive cleanup lock. This guarantees that no insertions currently
143  * happen in this subtree. Caller also acquires Exclusive locks on
144  * deletable, parent and left pages.
145  */
146  lBuffer = ReadBufferExtended(gvs->index, MAIN_FORKNUM, leftBlkno,
147  RBM_NORMAL, gvs->strategy);
148  dBuffer = ReadBufferExtended(gvs->index, MAIN_FORKNUM, deleteBlkno,
149  RBM_NORMAL, gvs->strategy);
150  pBuffer = ReadBufferExtended(gvs->index, MAIN_FORKNUM, parentBlkno,
151  RBM_NORMAL, gvs->strategy);
152 
153  page = BufferGetPage(dBuffer);
154  rightlink = GinPageGetOpaque(page)->rightlink;
155 
156  /*
157  * Any insert which would have gone on the leaf block will now go to its
158  * right sibling.
159  */
160  PredicateLockPageCombine(gvs->index, deleteBlkno, rightlink);
161 
163 
164  /* Unlink the page by changing left sibling's rightlink */
165  page = BufferGetPage(lBuffer);
166  GinPageGetOpaque(page)->rightlink = rightlink;
167 
168  /* For deleted page remember last xid which could knew its address */
170 
171  /* Delete downlink from parent */
172  parentPage = BufferGetPage(pBuffer);
173 #ifdef USE_ASSERT_CHECKING
174  do
175  {
176  PostingItem *tod = GinDataPageGetPostingItem(parentPage, myoff);
177 
178  Assert(PostingItemGetBlockNumber(tod) == deleteBlkno);
179  } while (0);
180 #endif
181  GinPageDeletePostingItem(parentPage, myoff);
182 
183  page = BufferGetPage(dBuffer);
184 
185  /*
186  * we shouldn't change rightlink field to save workability of running
187  * search scan
188  */
189  GinPageSetDeleted(page);
190 
191  MarkBufferDirty(pBuffer);
192  MarkBufferDirty(lBuffer);
193  MarkBufferDirty(dBuffer);
194 
195  if (RelationNeedsWAL(gvs->index))
196  {
197  XLogRecPtr recptr;
198  ginxlogDeletePage data;
199 
200  /*
201  * We can't pass REGBUF_STANDARD for the deleted page, because we
202  * didn't set pd_lower on pre-9.4 versions. The page might've been
203  * binary-upgraded from an older version, and hence not have pd_lower
204  * set correctly. Ditto for the left page, but removing the item from
205  * the parent updated its pd_lower, so we know that's OK at this
206  * point.
207  */
208  XLogBeginInsert();
209  XLogRegisterBuffer(0, dBuffer, 0);
210  XLogRegisterBuffer(1, pBuffer, REGBUF_STANDARD);
211  XLogRegisterBuffer(2, lBuffer, 0);
212 
213  data.parentOffset = myoff;
214  data.rightLink = GinPageGetOpaque(page)->rightlink;
215  data.deleteXid = GinPageGetDeleteXid(page);
216 
217  XLogRegisterData((char *) &data, sizeof(ginxlogDeletePage));
218 
219  recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_DELETE_PAGE);
220  PageSetLSN(page, recptr);
221  PageSetLSN(parentPage, recptr);
222  PageSetLSN(BufferGetPage(lBuffer), recptr);
223  }
224 
225  ReleaseBuffer(pBuffer);
226  ReleaseBuffer(lBuffer);
227  ReleaseBuffer(dBuffer);
228 
230 
231  gvs->result->pages_deleted++;
232 }
233 
234 
235 /*
236  * Scans posting tree and deletes empty pages. Caller must lock root page for
237  * cleanup. During scan path from root to current page is kept exclusively
238  * locked. Also keep left page exclusively locked, because ginDeletePage()
239  * needs it. If we try to relock left page later, it could deadlock with
240  * ginStepRight().
241  */
242 static bool
245 {
247  Buffer buffer;
248  Page page;
249  bool meDelete = false;
250  bool isempty;
251 
252  if (isRoot)
253  {
254  me = parent;
255  }
256  else
257  {
258  if (!parent->child)
259  {
261  me->parent = parent;
262  parent->child = me;
264  }
265  else
266  me = parent->child;
267  }
268 
269  buffer = ReadBufferExtended(gvs->index, MAIN_FORKNUM, blkno,
270  RBM_NORMAL, gvs->strategy);
271 
272  if (!isRoot)
273  LockBuffer(buffer, GIN_EXCLUSIVE);
274 
275  page = BufferGetPage(buffer);
276 
277  Assert(GinPageIsData(page));
278 
279  if (!GinPageIsLeaf(page))
280  {
281  OffsetNumber i;
282 
283  me->blkno = blkno;
284  for (i = FirstOffsetNumber; i <= GinPageGetOpaque(page)->maxoff; i++)
285  {
286  PostingItem *pitem = GinDataPageGetPostingItem(page, i);
287 
288  if (ginScanToDelete(gvs, PostingItemGetBlockNumber(pitem), false, me, i))
289  i--;
290  }
291 
292  if (GinPageRightMost(page) && BufferIsValid(me->child->leftBuffer))
293  {
296  }
297  }
298 
299  if (GinPageIsLeaf(page))
300  isempty = GinDataLeafPageIsEmpty(page);
301  else
302  isempty = GinPageGetOpaque(page)->maxoff < FirstOffsetNumber;
303 
304  if (isempty)
305  {
306  /* we never delete the left- or rightmost branch */
307  if (BufferIsValid(me->leftBuffer) && !GinPageRightMost(page))
308  {
309  Assert(!isRoot);
311  me->parent->blkno, myoff, me->parent->isRoot);
312  meDelete = true;
313  }
314  }
315 
316  if (!meDelete)
317  {
318  if (BufferIsValid(me->leftBuffer))
320  me->leftBuffer = buffer;
321  }
322  else
323  {
324  if (!isRoot)
325  LockBuffer(buffer, GIN_UNLOCK);
326 
327  ReleaseBuffer(buffer);
328  }
329 
330  if (isRoot)
331  ReleaseBuffer(buffer);
332 
333  return meDelete;
334 }
335 
336 
337 /*
338  * Scan through posting tree leafs, delete empty tuples. Returns true if there
339  * is at least one empty page.
340  */
341 static bool
343 {
344  Buffer buffer;
345  Page page;
346  bool hasVoidPage = false;
347  MemoryContext oldCxt;
348 
349  /* Find leftmost leaf page of posting tree and lock it in exclusive mode */
350  while (true)
351  {
352  PostingItem *pitem;
353 
354  buffer = ReadBufferExtended(gvs->index, MAIN_FORKNUM, blkno,
355  RBM_NORMAL, gvs->strategy);
356  LockBuffer(buffer, GIN_SHARE);
357  page = BufferGetPage(buffer);
358 
359  Assert(GinPageIsData(page));
360 
361  if (GinPageIsLeaf(page))
362  {
363  LockBuffer(buffer, GIN_UNLOCK);
364  LockBuffer(buffer, GIN_EXCLUSIVE);
365  break;
366  }
367 
369 
371  blkno = PostingItemGetBlockNumber(pitem);
372  Assert(blkno != InvalidBlockNumber);
373 
374  UnlockReleaseBuffer(buffer);
375  }
376 
377  /* Iterate all posting tree leaves using rightlinks and vacuum them */
378  while (true)
379  {
380  oldCxt = MemoryContextSwitchTo(gvs->tmpCxt);
381  ginVacuumPostingTreeLeaf(gvs->index, buffer, gvs);
382  MemoryContextSwitchTo(oldCxt);
384 
385  if (GinDataLeafPageIsEmpty(page))
386  hasVoidPage = true;
387 
388  blkno = GinPageGetOpaque(page)->rightlink;
389 
390  UnlockReleaseBuffer(buffer);
391 
392  if (blkno == InvalidBlockNumber)
393  break;
394 
395  buffer = ReadBufferExtended(gvs->index, MAIN_FORKNUM, blkno,
396  RBM_NORMAL, gvs->strategy);
397  LockBuffer(buffer, GIN_EXCLUSIVE);
398  page = BufferGetPage(buffer);
399  }
400 
401  return hasVoidPage;
402 }
403 
404 static void
406 {
407  if (ginVacuumPostingTreeLeaves(gvs, rootBlkno))
408  {
409  /*
410  * There is at least one empty page. So we have to rescan the tree
411  * deleting empty pages.
412  */
413  Buffer buffer;
414  DataPageDeleteStack root,
415  *ptr,
416  *tmp;
417 
418  buffer = ReadBufferExtended(gvs->index, MAIN_FORKNUM, rootBlkno,
419  RBM_NORMAL, gvs->strategy);
420 
421  /*
422  * Lock posting tree root for cleanup to ensure there are no
423  * concurrent inserts.
424  */
425  LockBufferForCleanup(buffer);
426 
427  memset(&root, 0, sizeof(DataPageDeleteStack));
428  root.leftBuffer = InvalidBuffer;
429  root.isRoot = true;
430 
431  ginScanToDelete(gvs, rootBlkno, true, &root, InvalidOffsetNumber);
432 
433  ptr = root.child;
434 
435  while (ptr)
436  {
437  tmp = ptr->child;
438  pfree(ptr);
439  ptr = tmp;
440  }
441 
442  UnlockReleaseBuffer(buffer);
443  }
444 }
445 
446 /*
447  * returns modified page or NULL if page isn't modified.
448  * Function works with original page until first change is occurred,
449  * then page is copied into temporary one.
450  */
451 static Page
453 {
454  Page origpage = BufferGetPage(buffer),
455  tmppage;
456  OffsetNumber i,
457  maxoff = PageGetMaxOffsetNumber(origpage);
458 
459  tmppage = origpage;
460 
461  *nroot = 0;
462 
463  for (i = FirstOffsetNumber; i <= maxoff; i++)
464  {
465  IndexTuple itup = (IndexTuple) PageGetItem(tmppage, PageGetItemId(tmppage, i));
466 
467  if (GinIsPostingTree(itup))
468  {
469  /*
470  * store posting tree's roots for further processing, we can't
471  * vacuum it just now due to risk of deadlocks with scans/inserts
472  */
473  roots[*nroot] = GinGetDownlink(itup);
474  (*nroot)++;
475  }
476  else if (GinGetNPosting(itup) > 0)
477  {
478  int nitems;
479  ItemPointer items_orig;
480  bool free_items_orig;
481  ItemPointer items;
482 
483  /* Get list of item pointers from the tuple. */
484  if (GinItupIsCompressed(itup))
485  {
486  items_orig = ginPostingListDecode((GinPostingList *) GinGetPosting(itup), &nitems);
487  free_items_orig = true;
488  }
489  else
490  {
491  items_orig = (ItemPointer) GinGetPosting(itup);
492  nitems = GinGetNPosting(itup);
493  free_items_orig = false;
494  }
495 
496  /* Remove any items from the list that need to be vacuumed. */
497  items = ginVacuumItemPointers(gvs, items_orig, nitems, &nitems);
498 
499  if (free_items_orig)
500  pfree(items_orig);
501 
502  /* If any item pointers were removed, recreate the tuple. */
503  if (items)
504  {
506  Datum key;
507  GinNullCategory category;
508  GinPostingList *plist;
509  int plistsize;
510 
511  if (nitems > 0)
512  {
513  plist = ginCompressPostingList(items, nitems, GinMaxItemSize, NULL);
514  plistsize = SizeOfGinPostingList(plist);
515  }
516  else
517  {
518  plist = NULL;
519  plistsize = 0;
520  }
521 
522  /*
523  * if we already created a temporary page, make changes in
524  * place
525  */
526  if (tmppage == origpage)
527  {
528  /*
529  * On first difference, create a temporary copy of the
530  * page and copy the tuple's posting list to it.
531  */
532  tmppage = PageGetTempPageCopy(origpage);
533 
534  /* set itup pointer to new page */
535  itup = (IndexTuple) PageGetItem(tmppage, PageGetItemId(tmppage, i));
536  }
537 
538  attnum = gintuple_get_attrnum(&gvs->ginstate, itup);
539  key = gintuple_get_key(&gvs->ginstate, itup, &category);
540  itup = GinFormTuple(&gvs->ginstate, attnum, key, category,
541  (char *) plist, plistsize,
542  nitems, true);
543  if (plist)
544  pfree(plist);
545  PageIndexTupleDelete(tmppage, i);
546 
547  if (PageAddItem(tmppage, (Item) itup, IndexTupleSize(itup), i, false, false) != i)
548  elog(ERROR, "failed to add item to index page in \"%s\"",
550 
551  pfree(itup);
552  pfree(items);
553  }
554  }
555  }
556 
557  return (tmppage == origpage) ? NULL : tmppage;
558 }
559 
563 {
564  Relation index = info->index;
566  GinVacuumState gvs;
567  Buffer buffer;
568  BlockNumber rootOfPostingTree[BLCKSZ / (sizeof(IndexTupleData) + sizeof(ItemId))];
569  uint32 nRoot;
570 
572  "Gin vacuum temporary context",
574  gvs.index = index;
575  gvs.callback = callback;
577  gvs.strategy = info->strategy;
578  initGinState(&gvs.ginstate, index);
579 
580  /* first time through? */
581  if (stats == NULL)
582  {
583  /* Yes, so initialize stats to zeroes */
585 
586  /*
587  * and cleanup any pending inserts
588  */
590  false, true, stats);
591  }
592 
593  /* we'll re-count the tuples each time */
594  stats->num_index_tuples = 0;
595  gvs.result = stats;
596 
597  buffer = ReadBufferExtended(index, MAIN_FORKNUM, blkno,
598  RBM_NORMAL, info->strategy);
599 
600  /* find leaf page */
601  for (;;)
602  {
603  Page page = BufferGetPage(buffer);
604  IndexTuple itup;
605 
606  LockBuffer(buffer, GIN_SHARE);
607 
608  Assert(!GinPageIsData(page));
609 
610  if (GinPageIsLeaf(page))
611  {
612  LockBuffer(buffer, GIN_UNLOCK);
613  LockBuffer(buffer, GIN_EXCLUSIVE);
614 
615  if (blkno == GIN_ROOT_BLKNO && !GinPageIsLeaf(page))
616  {
617  LockBuffer(buffer, GIN_UNLOCK);
618  continue; /* check it one more */
619  }
620  break;
621  }
622 
624 
625  itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, FirstOffsetNumber));
626  blkno = GinGetDownlink(itup);
627  Assert(blkno != InvalidBlockNumber);
628 
629  UnlockReleaseBuffer(buffer);
630  buffer = ReadBufferExtended(index, MAIN_FORKNUM, blkno,
631  RBM_NORMAL, info->strategy);
632  }
633 
634  /* right now we found leftmost page in entry's BTree */
635 
636  for (;;)
637  {
638  Page page = BufferGetPage(buffer);
639  Page resPage;
640  uint32 i;
641 
642  Assert(!GinPageIsData(page));
643 
644  resPage = ginVacuumEntryPage(&gvs, buffer, rootOfPostingTree, &nRoot);
645 
646  blkno = GinPageGetOpaque(page)->rightlink;
647 
648  if (resPage)
649  {
651  PageRestoreTempPage(resPage, page);
652  MarkBufferDirty(buffer);
653  xlogVacuumPage(gvs.index, buffer);
654  UnlockReleaseBuffer(buffer);
656  }
657  else
658  {
659  UnlockReleaseBuffer(buffer);
660  }
661 
663 
664  for (i = 0; i < nRoot; i++)
665  {
666  ginVacuumPostingTree(&gvs, rootOfPostingTree[i]);
668  }
669 
670  if (blkno == InvalidBlockNumber) /* rightmost page */
671  break;
672 
673  buffer = ReadBufferExtended(index, MAIN_FORKNUM, blkno,
674  RBM_NORMAL, info->strategy);
675  LockBuffer(buffer, GIN_EXCLUSIVE);
676  }
677 
679 
680  return gvs.result;
681 }
682 
685 {
686  Relation index = info->index;
687  bool needLock;
688  BlockNumber npages,
689  blkno;
690  BlockNumber totFreePages;
692  GinStatsData idxStat;
693 
694  /*
695  * In an autovacuum analyze, we want to clean up pending insertions.
696  * Otherwise, an ANALYZE-only call is a no-op.
697  */
698  if (info->analyze_only)
699  {
701  {
702  initGinState(&ginstate, index);
703  ginInsertCleanup(&ginstate, false, true, true, stats);
704  }
705  return stats;
706  }
707 
708  /*
709  * Set up all-zero stats and cleanup pending inserts if ginbulkdelete
710  * wasn't called
711  */
712  if (stats == NULL)
713  {
715  initGinState(&ginstate, index);
717  false, true, stats);
718  }
719 
720  memset(&idxStat, 0, sizeof(idxStat));
721 
722  /*
723  * XXX we always report the heap tuple count as the number of index
724  * entries. This is bogus if the index is partial, but it's real hard to
725  * tell how many distinct heap entries are referenced by a GIN index.
726  */
727  stats->num_index_tuples = info->num_heap_tuples;
728  stats->estimated_count = info->estimated_count;
729 
730  /*
731  * Need lock unless it's local to this backend.
732  */
733  needLock = !RELATION_IS_LOCAL(index);
734 
735  if (needLock)
737  npages = RelationGetNumberOfBlocks(index);
738  if (needLock)
740 
741  totFreePages = 0;
742 
743  for (blkno = GIN_ROOT_BLKNO; blkno < npages; blkno++)
744  {
745  Buffer buffer;
746  Page page;
747 
749 
750  buffer = ReadBufferExtended(index, MAIN_FORKNUM, blkno,
751  RBM_NORMAL, info->strategy);
752  LockBuffer(buffer, GIN_SHARE);
753  page = (Page) BufferGetPage(buffer);
754 
755  if (GinPageIsRecyclable(page))
756  {
757  Assert(blkno != GIN_ROOT_BLKNO);
758  RecordFreeIndexPage(index, blkno);
759  totFreePages++;
760  }
761  else if (GinPageIsData(page))
762  {
763  idxStat.nDataPages++;
764  }
765  else if (!GinPageIsList(page))
766  {
767  idxStat.nEntryPages++;
768 
769  if (GinPageIsLeaf(page))
770  idxStat.nEntries += PageGetMaxOffsetNumber(page);
771  }
772 
773  UnlockReleaseBuffer(buffer);
774  }
775 
776  /* Update the metapage with accurate page and entry counts */
777  idxStat.nTotalPages = npages;
778  ginUpdateStats(info->index, &idxStat, false);
779 
780  /* Finally, vacuum the FSM */
782 
783  stats->pages_free = totFreePages;
784 
785  if (needLock)
787  stats->num_pages = RelationGetNumberOfBlocks(index);
788  if (needLock)
790 
791  return stats;
792 }
int remaining
Definition: informix.c:667
#define GIN_UNLOCK
Definition: gin_private.h:48
BlockNumber nEntryPages
Definition: gin.h:45
TransactionId deleteXid
Definition: ginxlog.h:159
GinPostingList * ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize, int *nwritten)
IndexBulkDeleteResult * ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: ginvacuum.c:684
void LockBufferForCleanup(Buffer buffer)
Definition: bufmgr.c:3659
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
#define AllocSetContextCreate
Definition: memutils.h:170
double tuples_removed
Definition: genam.h:78
#define GinPageIsRecyclable(page)
Definition: ginblock.h:137
void PageRestoreTempPage(Page tempPage, Page oldPage)
Definition: bufpage.c:410
ItemPointer ginPostingListDecode(GinPostingList *plist, int *ndecoded)
void PageIndexTupleDelete(Page page, OffsetNumber offnum)
Definition: bufpage.c:726
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1458
#define ExclusiveLock
Definition: lockdefs.h:44
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:213
Relation index
Definition: ginvacuum.c:30
#define RELATION_IS_LOCAL(relation)
Definition: rel.h:542
bool analyze_only
Definition: genam.h:47
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:642
BlockNumber rightLink
Definition: ginxlog.h:158
BufferAccessStrategy strategy
Definition: ginvacuum.c:35
#define END_CRIT_SECTION()
Definition: miscadmin.h:134
BufferAccessStrategy strategy
Definition: genam.h:52
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Pointer Item
Definition: item.h:17
#define InvalidBuffer
Definition: buf.h:25
ItemPointer ginVacuumItemPointers(GinVacuumState *gvs, ItemPointerData *items, int nitem, int *nremaining)
Definition: ginvacuum.c:48
#define START_CRIT_SECTION()
Definition: miscadmin.h:132
Relation index
Definition: genam.h:46
int64 nEntries
Definition: gin.h:47
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:416
#define GinGetNPosting(itup)
Definition: ginblock.h:229
#define GinPageGetDeleteXid(page)
Definition: ginblock.h:135
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:136
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3365
#define GinPageGetOpaque(page)
Definition: ginblock.h:110
OffsetNumber parentOffset
Definition: ginxlog.h:157
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
static void ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkno, BlockNumber parentBlkno, OffsetNumber myoff, bool isParentRoot)
Definition: ginvacuum.c:130
#define GinGetPosting(itup)
Definition: ginblock.h:239
IndexBulkDeleteResult * result
Definition: ginvacuum.c:31
#define GinItupIsCompressed(itup)
Definition: ginblock.h:240
#define GinDataLeafPageIsEmpty(page)
Definition: ginblock.h:284
uint16 OffsetNumber
Definition: off.h:24
ItemPointerData * ItemPointer
Definition: itemptr.h:49
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:1056
static bool ginVacuumPostingTreeLeaves(GinVacuumState *gvs, BlockNumber blkno)
Definition: ginvacuum.c:342
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3388
#define ERROR
Definition: elog.h:43
#define GinPageRightMost(page)
Definition: ginblock.h:129
signed char GinNullCategory
Definition: ginblock.h:207
static void xlogVacuumPage(Relation index, Buffer buffer)
Definition: ginvacuum.c:90
#define GinDataPageGetPostingItem(page, i)
Definition: ginblock.h:299
BlockNumber num_pages
Definition: genam.h:74
BlockNumber pages_free
Definition: genam.h:80
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
BlockNumber blkno
Definition: ginvacuum.c:119
OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple)
Definition: ginutil.c:218
void ginVacuumPostingTreeLeaf(Relation indexrel, Buffer buffer, GinVacuumState *gvs)
Definition: gindatapage.c:735
static Page ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint32 *nroot)
Definition: ginvacuum.c:452
IndexBulkDeleteCallback callback
Definition: ginvacuum.c:32
#define FirstOffsetNumber
Definition: off.h:27
IndexTupleData * IndexTuple
Definition: itup.h:53
#define REGBUF_STANDARD
Definition: xloginsert.h:35
void initGinState(GinState *state, Relation index)
Definition: ginutil.c:89
#define RelationGetRelationName(relation)
Definition: rel.h:456
unsigned int uint32
Definition: c.h:359
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define GinPageIsLeaf(page)
Definition: ginblock.h:112
Datum gintuple_get_key(GinState *ginstate, IndexTuple tuple, GinNullCategory *category)
Definition: ginutil.c:251
BlockNumber pages_deleted
Definition: genam.h:79
void * callback_state
Definition: ginvacuum.c:33
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
struct DataPageDeleteStack DataPageDeleteStack
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3281
#define GIN_SHARE
Definition: gin_private.h:49
#define REGBUF_FORCE_IMAGE
Definition: xloginsert.h:31
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:402
#define XLOG_GIN_VACUUM_PAGE
Definition: ginxlog.h:135
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
void * palloc0(Size size)
Definition: mcxt.c:980
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:452
uintptr_t Datum
Definition: postgres.h:367
struct IndexTupleData IndexTupleData
#define GIN_EXCLUSIVE
Definition: gin_private.h:50
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3602
#define GinGetDownlink(itup)
Definition: ginblock.h:258
void GinPageDeletePostingItem(Page page, OffsetNumber offset)
Definition: gindatapage.c:417
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:198
struct DataPageDeleteStack * child
Definition: ginvacuum.c:116
#define InvalidOffsetNumber
Definition: off.h:26
BlockNumber nDataPages
Definition: gin.h:46
int16 attnum
Definition: pg_attribute.h:79
void ginInsertCleanup(GinState *ginstate, bool full_clean, bool fill_fsm, bool forceCleanup, IndexBulkDeleteResult *stats)
Definition: ginfast.c:780
#define GinPageIsData(page)
Definition: ginblock.h:115
double num_heap_tuples
Definition: genam.h:51
#define PostingItemGetBlockNumber(pointer)
Definition: ginblock.h:190
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:739
#define GinPageSetDeleteXid(page, xid)
Definition: ginblock.h:136
IndexTuple GinFormTuple(GinState *ginstate, OffsetNumber attnum, Datum key, GinNullCategory category, Pointer data, Size dataSize, int nipd, bool errorTooBig)
Definition: ginentrypage.c:45
void IndexFreeSpaceMapVacuum(Relation rel)
Definition: indexfsm.c:71
struct DataPageDeleteStack * parent
Definition: ginvacuum.c:117
IndexBulkDeleteResult * ginbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: ginvacuum.c:561
#define GinPageIsList(page)
Definition: ginblock.h:117
#define InvalidBlockNumber
Definition: block.h:33
BlockNumber nTotalPages
Definition: gin.h:44
#define BufferIsValid(bufnum)
Definition: bufmgr.h:113
#define RelationNeedsWAL(relation)
Definition: rel.h:524
static TransactionId ReadNewTransactionId(void)
Definition: transam.h:244
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2613
void ginUpdateStats(Relation index, const GinStatsData *stats, bool is_build)
Definition: ginutil.c:651
#define GinIsPostingTree(itup)
Definition: ginblock.h:232
void * palloc(Size size)
Definition: mcxt.c:949
Page PageGetTempPageCopy(Page page)
Definition: bufpage.c:368
#define SizeOfGinPostingList(plist)
Definition: ginblock.h:343
#define GinMaxItemSize
Definition: ginblock.h:249
#define elog(elevel,...)
Definition: elog.h:228
#define GinPageSetDeleted(page)
Definition: ginblock.h:125
int i
void PredicateLockPageCombine(Relation relation, BlockNumber oldblkno, BlockNumber newblkno)
Definition: predicate.c:3187
static void ginVacuumPostingTree(GinVacuumState *gvs, BlockNumber rootBlkno)
Definition: ginvacuum.c:405
void vacuum_delay_point(void)
Definition: vacuum.c:1942
void XLogBeginInsert(void)
Definition: xloginsert.c:120
#define XLOG_GIN_DELETE_PAGE
Definition: ginxlog.h:153
void RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)
Definition: indexfsm.c:52
MemoryContext tmpCxt
Definition: ginvacuum.c:36
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368
double num_index_tuples
Definition: genam.h:77
int Buffer
Definition: buf.h:23
bool estimated_count
Definition: genam.h:76
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
#define GIN_ROOT_BLKNO
Definition: ginblock.h:52
Pointer Page
Definition: bufpage.h:78
#define IndexTupleSize(itup)
Definition: itup.h:71
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition: genam.h:84
static bool ginScanToDelete(GinVacuumState *gvs, BlockNumber blkno, bool isRoot, DataPageDeleteStack *parent, OffsetNumber myoff)
Definition: ginvacuum.c:243
bool estimated_count
Definition: genam.h:49
GinState ginstate
Definition: ginvacuum.c:34