PostgreSQL Source Code  git master
gistget.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * gistget.c
4  * fetch tuples from a GiST scan.
5  *
6  *
7  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * IDENTIFICATION
11  * src/backend/access/gist/gistget.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/genam.h"
18 #include "access/gist_private.h"
19 #include "access/relscan.h"
20 #include "lib/pairingheap.h"
21 #include "miscadmin.h"
22 #include "pgstat.h"
23 #include "storage/lmgr.h"
24 #include "storage/predicate.h"
25 #include "utils/float.h"
26 #include "utils/memutils.h"
27 #include "utils/rel.h"
28 
29 /*
30  * gistkillitems() -- set LP_DEAD state for items an indexscan caller has
31  * told us were killed.
32  *
33  * We re-read page here, so it's important to check page LSN. If the page
34  * has been modified since the last read (as determined by LSN), we cannot
35  * flag any entries because it is possible that the old entry was vacuumed
36  * away and the TID was re-used by a completely different heap tuple.
37  */
38 static void
40 {
42  Buffer buffer;
43  Page page;
44  OffsetNumber offnum;
45  ItemId iid;
46  int i;
47  bool killedsomething = false;
48 
51  Assert(so->killedItems != NULL);
52 
53  buffer = ReadBuffer(scan->indexRelation, so->curBlkno);
54  if (!BufferIsValid(buffer))
55  return;
56 
57  LockBuffer(buffer, GIST_SHARE);
58  gistcheckpage(scan->indexRelation, buffer);
59  page = BufferGetPage(buffer);
60 
61  /*
62  * If page LSN differs it means that the page was modified since the last
63  * read. killedItems could be not valid so LP_DEAD hints applying is not
64  * safe.
65  */
66  if (BufferGetLSNAtomic(buffer) != so->curPageLSN)
67  {
68  UnlockReleaseBuffer(buffer);
69  so->numKilled = 0; /* reset counter */
70  return;
71  }
72 
73  Assert(GistPageIsLeaf(page));
74 
75  /*
76  * Mark all killedItems as dead. We need no additional recheck, because,
77  * if page was modified, curPageLSN must have changed.
78  */
79  for (i = 0; i < so->numKilled; i++)
80  {
81  offnum = so->killedItems[i];
82  iid = PageGetItemId(page, offnum);
83  ItemIdMarkDead(iid);
84  killedsomething = true;
85  }
86 
87  if (killedsomething)
88  {
90  MarkBufferDirtyHint(buffer, true);
91  }
92 
93  UnlockReleaseBuffer(buffer);
94 
95  /*
96  * Always reset the scan state, so we don't look for same items on other
97  * pages.
98  */
99  so->numKilled = 0;
100 }
101 
102 /*
103  * gistindex_keytest() -- does this index tuple satisfy the scan key(s)?
104  *
105  * The index tuple might represent either a heap tuple or a lower index page,
106  * depending on whether the containing page is a leaf page or not.
107  *
108  * On success return for a heap tuple, *recheck_p is set to indicate whether
109  * the quals need to be rechecked. We recheck if any of the consistent()
110  * functions request it. recheck is not interesting when examining a non-leaf
111  * entry, since we must visit the lower index page if there's any doubt.
112  * Similarly, *recheck_distances_p is set to indicate whether the distances
113  * need to be rechecked, and it is also ignored for non-leaf entries.
114  *
115  * If we are doing an ordered scan, so->distances[] is filled with distance
116  * data from the distance() functions before returning success.
117  *
118  * We must decompress the key in the IndexTuple before passing it to the
119  * sk_funcs (which actually are the opclass Consistent or Distance methods).
120  *
121  * Note that this function is always invoked in a short-lived memory context,
122  * so we don't need to worry about cleaning up allocated memory, either here
123  * or in the implementation of any Consistent or Distance methods.
124  */
125 static bool
127  IndexTuple tuple,
128  Page page,
129  OffsetNumber offset,
130  bool *recheck_p,
131  bool *recheck_distances_p)
132 {
133  GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
134  GISTSTATE *giststate = so->giststate;
135  ScanKey key = scan->keyData;
136  int keySize = scan->numberOfKeys;
137  IndexOrderByDistance *distance_p;
138  Relation r = scan->indexRelation;
139 
140  *recheck_p = false;
141  *recheck_distances_p = false;
142 
143  /*
144  * If it's a leftover invalid tuple from pre-9.1, treat it as a match with
145  * minimum possible distances. This means we'll always follow it to the
146  * referenced page.
147  */
148  if (GistTupleIsInvalid(tuple))
149  {
150  int i;
151 
152  if (GistPageIsLeaf(page)) /* shouldn't happen */
153  elog(ERROR, "invalid GiST tuple found on leaf page");
154  for (i = 0; i < scan->numberOfOrderBys; i++)
155  {
157  so->distances[i].isnull = false;
158  }
159  return true;
160  }
161 
162  /* Check whether it matches according to the Consistent functions */
163  while (keySize > 0)
164  {
165  Datum datum;
166  bool isNull;
167 
168  datum = index_getattr(tuple,
169  key->sk_attno,
170  giststate->leafTupdesc,
171  &isNull);
172 
173  if (key->sk_flags & SK_ISNULL)
174  {
175  /*
176  * On non-leaf page we can't conclude that child hasn't NULL
177  * values because of assumption in GiST: union (VAL, NULL) is VAL.
178  * But if on non-leaf page key IS NULL, then all children are
179  * NULL.
180  */
181  if (key->sk_flags & SK_SEARCHNULL)
182  {
183  if (GistPageIsLeaf(page) && !isNull)
184  return false;
185  }
186  else
187  {
188  Assert(key->sk_flags & SK_SEARCHNOTNULL);
189  if (isNull)
190  return false;
191  }
192  }
193  else if (isNull)
194  {
195  return false;
196  }
197  else
198  {
199  Datum test;
200  bool recheck;
201  GISTENTRY de;
202 
203  gistdentryinit(giststate, key->sk_attno - 1, &de,
204  datum, r, page, offset,
205  false, isNull);
206 
207  /*
208  * Call the Consistent function to evaluate the test. The
209  * arguments are the index datum (as a GISTENTRY*), the comparison
210  * datum, the comparison operator's strategy number and subtype
211  * from pg_amop, and the recheck flag.
212  *
213  * (Presently there's no need to pass the subtype since it'll
214  * always be zero, but might as well pass it for possible future
215  * use.)
216  *
217  * We initialize the recheck flag to true (the safest assumption)
218  * in case the Consistent function forgets to set it.
219  */
220  recheck = true;
221 
222  test = FunctionCall5Coll(&key->sk_func,
223  key->sk_collation,
224  PointerGetDatum(&de),
225  key->sk_argument,
226  Int16GetDatum(key->sk_strategy),
227  ObjectIdGetDatum(key->sk_subtype),
228  PointerGetDatum(&recheck));
229 
230  if (!DatumGetBool(test))
231  return false;
232  *recheck_p |= recheck;
233  }
234 
235  key++;
236  keySize--;
237  }
238 
239  /* OK, it passes --- now let's compute the distances */
240  key = scan->orderByData;
241  distance_p = so->distances;
242  keySize = scan->numberOfOrderBys;
243  while (keySize > 0)
244  {
245  Datum datum;
246  bool isNull;
247 
248  datum = index_getattr(tuple,
249  key->sk_attno,
250  giststate->leafTupdesc,
251  &isNull);
252 
253  if ((key->sk_flags & SK_ISNULL) || isNull)
254  {
255  /* Assume distance computes as null */
256  distance_p->value = 0.0;
257  distance_p->isnull = true;
258  }
259  else
260  {
261  Datum dist;
262  bool recheck;
263  GISTENTRY de;
264 
265  gistdentryinit(giststate, key->sk_attno - 1, &de,
266  datum, r, page, offset,
267  false, isNull);
268 
269  /*
270  * Call the Distance function to evaluate the distance. The
271  * arguments are the index datum (as a GISTENTRY*), the comparison
272  * datum, the ordering operator's strategy number and subtype from
273  * pg_amop, and the recheck flag.
274  *
275  * (Presently there's no need to pass the subtype since it'll
276  * always be zero, but might as well pass it for possible future
277  * use.)
278  *
279  * If the function sets the recheck flag, the returned distance is
280  * a lower bound on the true distance and needs to be rechecked.
281  * We initialize the flag to 'false'. This flag was added in
282  * version 9.5; distance functions written before that won't know
283  * about the flag, but are expected to never be lossy.
284  */
285  recheck = false;
286  dist = FunctionCall5Coll(&key->sk_func,
287  key->sk_collation,
288  PointerGetDatum(&de),
289  key->sk_argument,
290  Int16GetDatum(key->sk_strategy),
291  ObjectIdGetDatum(key->sk_subtype),
292  PointerGetDatum(&recheck));
293  *recheck_distances_p |= recheck;
294  distance_p->value = DatumGetFloat8(dist);
295  distance_p->isnull = false;
296  }
297 
298  key++;
299  distance_p++;
300  keySize--;
301  }
302 
303  return true;
304 }
305 
306 /*
307  * Scan all items on the GiST index page identified by *pageItem, and insert
308  * them into the queue (or directly to output areas)
309  *
310  * scan: index scan we are executing
311  * pageItem: search queue item identifying an index page to scan
312  * myDistances: distances array associated with pageItem, or NULL at the root
313  * tbm: if not NULL, gistgetbitmap's output bitmap
314  * ntids: if not NULL, gistgetbitmap's output tuple counter
315  *
316  * If tbm/ntids aren't NULL, we are doing an amgetbitmap scan, and heap
317  * tuples should be reported directly into the bitmap. If they are NULL,
318  * we're doing a plain or ordered indexscan. For a plain indexscan, heap
319  * tuple TIDs are returned into so->pageData[]. For an ordered indexscan,
320  * heap tuple TIDs are pushed into individual search queue items. In an
321  * index-only scan, reconstructed index tuples are returned along with the
322  * TIDs.
323  *
324  * If we detect that the index page has split since we saw its downlink
325  * in the parent, we push its new right sibling onto the queue so the
326  * sibling will be processed next.
327  */
328 static void
330  IndexOrderByDistance *myDistances, TIDBitmap *tbm, int64 *ntids)
331 {
332  GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
333  GISTSTATE *giststate = so->giststate;
334  Relation r = scan->indexRelation;
335  Buffer buffer;
336  Page page;
337  GISTPageOpaque opaque;
338  OffsetNumber maxoff;
339  OffsetNumber i;
340  MemoryContext oldcxt;
341 
342  Assert(!GISTSearchItemIsHeap(*pageItem));
343 
344  buffer = ReadBuffer(scan->indexRelation, pageItem->blkno);
345  LockBuffer(buffer, GIST_SHARE);
347  gistcheckpage(scan->indexRelation, buffer);
348  page = BufferGetPage(buffer);
349  opaque = GistPageGetOpaque(page);
350 
351  /*
352  * Check if we need to follow the rightlink. We need to follow it if the
353  * page was concurrently split since we visited the parent (in which case
354  * parentlsn < nsn), or if the system crashed after a page split but
355  * before the downlink was inserted into the parent.
356  */
357  if (!XLogRecPtrIsInvalid(pageItem->data.parentlsn) &&
358  (GistFollowRight(page) ||
359  pageItem->data.parentlsn < GistPageGetNSN(page)) &&
360  opaque->rightlink != InvalidBlockNumber /* sanity check */ )
361  {
362  /* There was a page split, follow right link to add pages */
363  GISTSearchItem *item;
364 
365  /* This can't happen when starting at the root */
366  Assert(myDistances != NULL);
367 
368  oldcxt = MemoryContextSwitchTo(so->queueCxt);
369 
370  /* Create new GISTSearchItem for the right sibling index page */
372  item->blkno = opaque->rightlink;
373  item->data.parentlsn = pageItem->data.parentlsn;
374 
375  /* Insert it into the queue using same distances as for this page */
376  memcpy(item->distances, myDistances,
377  sizeof(item->distances[0]) * scan->numberOfOrderBys);
378 
379  pairingheap_add(so->queue, &item->phNode);
380 
381  MemoryContextSwitchTo(oldcxt);
382  }
383 
384  /*
385  * Check if the page was deleted after we saw the downlink. There's
386  * nothing of interest on a deleted page. Note that we must do this after
387  * checking the NSN for concurrent splits! It's possible that the page
388  * originally contained some tuples that are visible to us, but was split
389  * so that all the visible tuples were moved to another page, and then
390  * this page was deleted.
391  */
392  if (GistPageIsDeleted(page))
393  {
394  UnlockReleaseBuffer(buffer);
395  return;
396  }
397 
398  so->nPageData = so->curPageData = 0;
399  scan->xs_hitup = NULL; /* might point into pageDataCxt */
400  if (so->pageDataCxt)
402 
403  /*
404  * We save the LSN of the page as we read it, so that we know whether it
405  * safe to apply LP_DEAD hints to the page later. This allows us to drop
406  * the pin for MVCC scans, which allows vacuum to avoid blocking.
407  */
408  so->curPageLSN = BufferGetLSNAtomic(buffer);
409 
410  /*
411  * check all tuples on page
412  */
413  maxoff = PageGetMaxOffsetNumber(page);
414  for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
415  {
416  ItemId iid = PageGetItemId(page, i);
417  IndexTuple it;
418  bool match;
419  bool recheck;
420  bool recheck_distances;
421 
422  /*
423  * If the scan specifies not to return killed tuples, then we treat a
424  * killed tuple as not passing the qual.
425  */
426  if (scan->ignore_killed_tuples && ItemIdIsDead(iid))
427  continue;
428 
429  it = (IndexTuple) PageGetItem(page, iid);
430 
431  /*
432  * Must call gistindex_keytest in tempCxt, and clean up any leftover
433  * junk afterward.
434  */
435  oldcxt = MemoryContextSwitchTo(so->giststate->tempCxt);
436 
437  match = gistindex_keytest(scan, it, page, i,
438  &recheck, &recheck_distances);
439 
440  MemoryContextSwitchTo(oldcxt);
442 
443  /* Ignore tuple if it doesn't match */
444  if (!match)
445  continue;
446 
447  if (tbm && GistPageIsLeaf(page))
448  {
449  /*
450  * getbitmap scan, so just push heap tuple TIDs into the bitmap
451  * without worrying about ordering
452  */
453  tbm_add_tuples(tbm, &it->t_tid, 1, recheck);
454  (*ntids)++;
455  }
456  else if (scan->numberOfOrderBys == 0 && GistPageIsLeaf(page))
457  {
458  /*
459  * Non-ordered scan, so report tuples in so->pageData[]
460  */
461  so->pageData[so->nPageData].heapPtr = it->t_tid;
462  so->pageData[so->nPageData].recheck = recheck;
463  so->pageData[so->nPageData].offnum = i;
464 
465  /*
466  * In an index-only scan, also fetch the data from the tuple. The
467  * reconstructed tuples are stored in pageDataCxt.
468  */
469  if (scan->xs_want_itup)
470  {
471  oldcxt = MemoryContextSwitchTo(so->pageDataCxt);
472  so->pageData[so->nPageData].recontup =
473  gistFetchTuple(giststate, r, it);
474  MemoryContextSwitchTo(oldcxt);
475  }
476  so->nPageData++;
477  }
478  else
479  {
480  /*
481  * Must push item into search queue. We get here for any lower
482  * index page, and also for heap tuples if doing an ordered
483  * search.
484  */
485  GISTSearchItem *item;
486  int nOrderBys = scan->numberOfOrderBys;
487 
488  oldcxt = MemoryContextSwitchTo(so->queueCxt);
489 
490  /* Create new GISTSearchItem for this item */
492 
493  if (GistPageIsLeaf(page))
494  {
495  /* Creating heap-tuple GISTSearchItem */
496  item->blkno = InvalidBlockNumber;
497  item->data.heap.heapPtr = it->t_tid;
498  item->data.heap.recheck = recheck;
499  item->data.heap.recheckDistances = recheck_distances;
500 
501  /*
502  * In an index-only scan, also fetch the data from the tuple.
503  */
504  if (scan->xs_want_itup)
505  item->data.heap.recontup = gistFetchTuple(giststate, r, it);
506  }
507  else
508  {
509  /* Creating index-page GISTSearchItem */
510  item->blkno = ItemPointerGetBlockNumber(&it->t_tid);
511 
512  /*
513  * LSN of current page is lsn of parent page for child. We
514  * only have a shared lock, so we need to get the LSN
515  * atomically.
516  */
517  item->data.parentlsn = BufferGetLSNAtomic(buffer);
518  }
519 
520  /* Insert it into the queue using new distance data */
521  memcpy(item->distances, so->distances,
522  sizeof(item->distances[0]) * nOrderBys);
523 
524  pairingheap_add(so->queue, &item->phNode);
525 
526  MemoryContextSwitchTo(oldcxt);
527  }
528  }
529 
530  UnlockReleaseBuffer(buffer);
531 }
532 
533 /*
534  * Extract next item (in order) from search queue
535  *
536  * Returns a GISTSearchItem or NULL. Caller must pfree item when done with it.
537  */
538 static GISTSearchItem *
540 {
541  GISTSearchItem *item;
542 
543  if (!pairingheap_is_empty(so->queue))
544  {
546  }
547  else
548  {
549  /* Done when both heaps are empty */
550  item = NULL;
551  }
552 
553  /* Return item; caller is responsible to pfree it */
554  return item;
555 }
556 
557 /*
558  * Fetch next heap tuple in an ordered search
559  */
560 static bool
562 {
563  GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
564  bool res = false;
565 
566  if (scan->xs_hitup)
567  {
568  /* free previously returned tuple */
569  pfree(scan->xs_hitup);
570  scan->xs_hitup = NULL;
571  }
572 
573  do
574  {
576 
577  if (!item)
578  break;
579 
580  if (GISTSearchItemIsHeap(*item))
581  {
582  /* found a heap item at currently minimal distance */
583  scan->xs_heaptid = item->data.heap.heapPtr;
584  scan->xs_recheck = item->data.heap.recheck;
585 
587  item->distances,
588  item->data.heap.recheckDistances);
589 
590  /* in an index-only scan, also return the reconstructed tuple. */
591  if (scan->xs_want_itup)
592  scan->xs_hitup = item->data.heap.recontup;
593  res = true;
594  }
595  else
596  {
597  /* visit an index page, extract its items into queue */
599 
600  gistScanPage(scan, item, item->distances, NULL, NULL);
601  }
602 
603  pfree(item);
604  } while (!res);
605 
606  return res;
607 }
608 
609 /*
610  * gistgettuple() -- Get the next tuple in the scan
611  */
612 bool
614 {
615  GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
616 
617  if (dir != ForwardScanDirection)
618  elog(ERROR, "GiST only supports forward scan direction");
619 
620  if (!so->qual_ok)
621  return false;
622 
623  if (so->firstCall)
624  {
625  /* Begin the scan by processing the root page */
626  GISTSearchItem fakeItem;
627 
629 
630  so->firstCall = false;
631  so->curPageData = so->nPageData = 0;
632  scan->xs_hitup = NULL;
633  if (so->pageDataCxt)
635 
636  fakeItem.blkno = GIST_ROOT_BLKNO;
637  memset(&fakeItem.data.parentlsn, 0, sizeof(GistNSN));
638  gistScanPage(scan, &fakeItem, NULL, NULL, NULL);
639  }
640 
641  if (scan->numberOfOrderBys > 0)
642  {
643  /* Must fetch tuples in strict distance order */
644  return getNextNearest(scan);
645  }
646  else
647  {
648  /* Fetch tuples index-page-at-a-time */
649  for (;;)
650  {
651  if (so->curPageData < so->nPageData)
652  {
653  if (scan->kill_prior_tuple && so->curPageData > 0)
654  {
655 
656  if (so->killedItems == NULL)
657  {
658  MemoryContext oldCxt =
660 
661  so->killedItems =
663  * sizeof(OffsetNumber));
664 
665  MemoryContextSwitchTo(oldCxt);
666  }
668  so->killedItems[so->numKilled++] =
669  so->pageData[so->curPageData - 1].offnum;
670  }
671  /* continuing to return tuples from a leaf page */
672  scan->xs_heaptid = so->pageData[so->curPageData].heapPtr;
673  scan->xs_recheck = so->pageData[so->curPageData].recheck;
674 
675  /* in an index-only scan, also return the reconstructed tuple */
676  if (scan->xs_want_itup)
677  scan->xs_hitup = so->pageData[so->curPageData].recontup;
678 
679  so->curPageData++;
680 
681  return true;
682  }
683 
684  /*
685  * Check the last returned tuple and add it to killedItems if
686  * necessary
687  */
688  if (scan->kill_prior_tuple
689  && so->curPageData > 0
690  && so->curPageData == so->nPageData)
691  {
692 
693  if (so->killedItems == NULL)
694  {
695  MemoryContext oldCxt =
697 
698  so->killedItems =
700  * sizeof(OffsetNumber));
701 
702  MemoryContextSwitchTo(oldCxt);
703  }
705  so->killedItems[so->numKilled++] =
706  so->pageData[so->curPageData - 1].offnum;
707  }
708  /* find and process the next index page */
709  do
710  {
711  GISTSearchItem *item;
712 
713  if ((so->curBlkno != InvalidBlockNumber) && (so->numKilled > 0))
714  gistkillitems(scan);
715 
716  item = getNextGISTSearchItem(so);
717 
718  if (!item)
719  return false;
720 
722 
723  /* save current item BlockNumber for next gistkillitems() call */
724  so->curBlkno = item->blkno;
725 
726  /*
727  * While scanning a leaf page, ItemPointers of matching heap
728  * tuples are stored in so->pageData. If there are any on
729  * this page, we fall out of the inner "do" and loop around to
730  * return them.
731  */
732  gistScanPage(scan, item, item->distances, NULL, NULL);
733 
734  pfree(item);
735  } while (so->nPageData == 0);
736  }
737  }
738 }
739 
740 /*
741  * gistgetbitmap() -- Get a bitmap of all heap tuple locations
742  */
743 int64
745 {
746  GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
747  int64 ntids = 0;
748  GISTSearchItem fakeItem;
749 
750  if (!so->qual_ok)
751  return 0;
752 
754 
755  /* Begin the scan by processing the root page */
756  so->curPageData = so->nPageData = 0;
757  scan->xs_hitup = NULL;
758  if (so->pageDataCxt)
760 
761  fakeItem.blkno = GIST_ROOT_BLKNO;
762  memset(&fakeItem.data.parentlsn, 0, sizeof(GistNSN));
763  gistScanPage(scan, &fakeItem, NULL, tbm, &ntids);
764 
765  /*
766  * While scanning a leaf page, ItemPointers of matching heap tuples will
767  * be stored directly into tbm, so we don't need to deal with them here.
768  */
769  for (;;)
770  {
772 
773  if (!item)
774  break;
775 
777 
778  gistScanPage(scan, item, item->distances, tbm, &ntids);
779 
780  pfree(item);
781  }
782 
783  return ntids;
784 }
785 
786 /*
787  * Can we do index-only scans on the given index column?
788  *
789  * Opclasses that implement a fetch function support index-only scans.
790  * Opclasses without compression functions also support index-only scans.
791  * Included attributes always can be fetched for index-only scans.
792  */
793 bool
795 {
799  return true;
800  else
801  return false;
802 }
#define InvalidBlockNumber
Definition: block.h:33
int Buffer
Definition: buf.h:23
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:3290
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
Definition: bufmgr.c:3551
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4497
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4715
void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
Definition: bufmgr.c:4544
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:708
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:350
static bool BufferIsValid(Buffer bufnum)
Definition: bufmgr.h:301
Pointer Page
Definition: bufpage.h:78
static Item PageGetItem(Page page, ItemId itemId)
Definition: bufpage.h:351
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:240
static OffsetNumber PageGetMaxOffsetNumber(Page page)
Definition: bufpage.h:369
#define OidIsValid(objectId)
Definition: c.h:764
#define ERROR
Definition: elog.h:39
static float8 get_float8_infinity(void)
Definition: float.h:94
Datum FunctionCall5Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Definition: fmgr.c:1206
#define GIST_FETCH_PROC
Definition: gist.h:38
#define GIST_COMPRESS_PROC
Definition: gist.h:32
#define GistPageIsLeaf(page)
Definition: gist.h:167
#define GistFollowRight(page)
Definition: gist.h:180
#define GistPageIsDeleted(page)
Definition: gist.h:170
#define GistPageGetOpaque(page)
Definition: gist.h:165
#define GistMarkPageHasGarbage(page)
Definition: gist.h:177
#define GistPageGetNSN(page)
Definition: gist.h:184
XLogRecPtr GistNSN
Definition: gist.h:60
#define GIST_ROOT_BLKNO
Definition: gist_private.h:262
GISTScanOpaqueData * GISTScanOpaque
Definition: gist_private.h:181
#define SizeOfGISTSearchItem(n_distances)
Definition: gist_private.h:147
#define GistTupleIsInvalid(itup)
Definition: gist_private.h:288
#define GIST_SHARE
Definition: gist_private.h:42
#define GISTSearchItemIsHeap(item)
Definition: gist_private.h:145
static bool getNextNearest(IndexScanDesc scan)
Definition: gistget.c:561
static bool gistindex_keytest(IndexScanDesc scan, IndexTuple tuple, Page page, OffsetNumber offset, bool *recheck_p, bool *recheck_distances_p)
Definition: gistget.c:126
bool gistgettuple(IndexScanDesc scan, ScanDirection dir)
Definition: gistget.c:613
int64 gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition: gistget.c:744
static GISTSearchItem * getNextGISTSearchItem(GISTScanOpaque so)
Definition: gistget.c:539
bool gistcanreturn(Relation index, int attno)
Definition: gistget.c:794
static void gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem, IndexOrderByDistance *myDistances, TIDBitmap *tbm, int64 *ntids)
Definition: gistget.c:329
static void gistkillitems(IndexScanDesc scan)
Definition: gistget.c:39
HeapTuple gistFetchTuple(GISTSTATE *giststate, Relation r, IndexTuple tuple)
Definition: gistutil.c:667
void gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e, Datum k, Relation r, Page pg, OffsetNumber o, bool l, bool isNull)
Definition: gistutil.c:547
void gistcheckpage(Relation rel, Buffer buf)
Definition: gistutil.c:785
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:777
void index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes, IndexOrderByDistance *distances, bool recheckOrderBy)
Definition: indexam.c:879
int i
Definition: isn.c:73
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
#define ItemIdMarkDead(itemId)
Definition: itemid.h:179
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103
IndexTupleData * IndexTuple
Definition: itup.h:53
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: itup.h:117
#define MaxIndexTuplesPerPage
Definition: itup.h:165
Assert(fmt[strlen(fmt) - 1] !='\n')
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:330
void pfree(void *pointer)
Definition: mcxt.c:1456
void * palloc(Size size)
Definition: mcxt.c:1226
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
void pairingheap_add(pairingheap *heap, pairingheap_node *node)
Definition: pairingheap.c:112
pairingheap_node * pairingheap_remove_first(pairingheap *heap)
Definition: pairingheap.c:145
#define pairingheap_is_empty(h)
Definition: pairingheap.h:96
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define pgstat_count_index_scan(rel)
Definition: pgstat.h:623
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
uintptr_t Datum
Definition: postgres.h:64
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
static float8 DatumGetFloat8(Datum X)
Definition: postgres.h:494
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
void PredicateLockPage(Relation relation, BlockNumber blkno, Snapshot snapshot)
Definition: predicate.c:2533
static void test(void)
#define IndexRelationGetNumberOfKeyAttributes(relation)
Definition: rel.h:523
ScanDirection
Definition: sdir.h:25
@ ForwardScanDirection
Definition: sdir.h:28
#define SK_SEARCHNOTNULL
Definition: skey.h:122
#define SK_SEARCHNULL
Definition: skey.h:121
#define SK_ISNULL
Definition: skey.h:115
MemoryContext tempCxt
Definition: gist_private.h:78
MemoryContext scanCxt
Definition: gist_private.h:77
OffsetNumber * killedItems
Definition: gist_private.h:168
pairingheap * queue
Definition: gist_private.h:159
OffsetNumber nPageData
Definition: gist_private.h:175
GISTSTATE * giststate
Definition: gist_private.h:156
MemoryContext queueCxt
Definition: gist_private.h:160
OffsetNumber curPageData
Definition: gist_private.h:176
GISTSearchHeapItem pageData[BLCKSZ/sizeof(IndexTupleData)]
Definition: gist_private.h:174
IndexOrderByDistance * distances
Definition: gist_private.h:165
BlockNumber curBlkno
Definition: gist_private.h:170
MemoryContext pageDataCxt
Definition: gist_private.h:177
ItemPointerData heapPtr
Definition: gist_private.h:120
OffsetNumber offnum
Definition: gist_private.h:125
GISTSearchHeapItem heap
Definition: gist_private.h:138
BlockNumber blkno
Definition: gist_private.h:133
IndexOrderByDistance distances[FLEXIBLE_ARRAY_MEMBER]
Definition: gist_private.h:142
union GISTSearchItem::@43 data
GistNSN parentlsn
Definition: gist_private.h:136
pairingheap_node phNode
Definition: gist_private.h:132
struct ScanKeyData * keyData
Definition: relscan.h:122
struct ScanKeyData * orderByData
Definition: relscan.h:123
HeapTuple xs_hitup
Definition: relscan.h:144
bool ignore_killed_tuples
Definition: relscan.h:129
int numberOfOrderBys
Definition: relscan.h:121
bool kill_prior_tuple
Definition: relscan.h:128
Relation indexRelation
Definition: relscan.h:118
ItemPointerData xs_heaptid
Definition: relscan.h:147
struct SnapshotData * xs_snapshot
Definition: relscan.h:119
ItemPointerData t_tid
Definition: itup.h:37
Definition: type.h:95
void tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids, bool recheck)
Definition: tidbitmap.c:376
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29