PostgreSQL Source Code  git master
ginutil.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * ginutil.c
4  * Utility routines for the Postgres inverted index access method.
5  *
6  *
7  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * IDENTIFICATION
11  * src/backend/access/gin/ginutil.c
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "postgres.h"
16 
17 #include "access/gin_private.h"
18 #include "access/ginxlog.h"
19 #include "access/reloptions.h"
20 #include "access/xloginsert.h"
21 #include "catalog/pg_collation.h"
22 #include "catalog/pg_type.h"
23 #include "commands/vacuum.h"
24 #include "miscadmin.h"
25 #include "storage/indexfsm.h"
26 #include "storage/lmgr.h"
27 #include "storage/predicate.h"
28 #include "utils/builtins.h"
29 #include "utils/index_selfuncs.h"
30 #include "utils/typcache.h"
31 
32 
33 /*
34  * GIN handler function: return IndexAmRoutine with access method parameters
35  * and callbacks.
36  */
37 Datum
39 {
41 
42  amroutine->amstrategies = 0;
43  amroutine->amsupport = GINNProcs;
44  amroutine->amoptsprocnum = GIN_OPTIONS_PROC;
45  amroutine->amcanorder = false;
46  amroutine->amcanorderbyop = false;
47  amroutine->amcanbackward = false;
48  amroutine->amcanunique = false;
49  amroutine->amcanmulticol = true;
50  amroutine->amoptionalkey = true;
51  amroutine->amsearcharray = false;
52  amroutine->amsearchnulls = false;
53  amroutine->amstorage = true;
54  amroutine->amclusterable = false;
55  amroutine->ampredlocks = true;
56  amroutine->amcanparallel = false;
57  amroutine->amcaninclude = false;
58  amroutine->amusemaintenanceworkmem = true;
59  amroutine->amparallelvacuumoptions =
61  amroutine->amkeytype = InvalidOid;
62 
63  amroutine->ambuild = ginbuild;
64  amroutine->ambuildempty = ginbuildempty;
65  amroutine->aminsert = gininsert;
66  amroutine->ambulkdelete = ginbulkdelete;
67  amroutine->amvacuumcleanup = ginvacuumcleanup;
68  amroutine->amcanreturn = NULL;
69  amroutine->amcostestimate = gincostestimate;
70  amroutine->amoptions = ginoptions;
71  amroutine->amproperty = NULL;
72  amroutine->ambuildphasename = NULL;
73  amroutine->amvalidate = ginvalidate;
74  amroutine->amadjustmembers = ginadjustmembers;
75  amroutine->ambeginscan = ginbeginscan;
76  amroutine->amrescan = ginrescan;
77  amroutine->amgettuple = NULL;
78  amroutine->amgetbitmap = gingetbitmap;
79  amroutine->amendscan = ginendscan;
80  amroutine->ammarkpos = NULL;
81  amroutine->amrestrpos = NULL;
82  amroutine->amestimateparallelscan = NULL;
83  amroutine->aminitparallelscan = NULL;
84  amroutine->amparallelrescan = NULL;
85 
86  PG_RETURN_POINTER(amroutine);
87 }
88 
89 /*
90  * initGinState: fill in an empty GinState struct to describe the index
91  *
92  * Note: assorted subsidiary data is allocated in the CurrentMemoryContext.
93  */
94 void
96 {
97  TupleDesc origTupdesc = RelationGetDescr(index);
98  int i;
99 
100  MemSet(state, 0, sizeof(GinState));
101 
102  state->index = index;
103  state->oneCol = (origTupdesc->natts == 1);
104  state->origTupdesc = origTupdesc;
105 
106  for (i = 0; i < origTupdesc->natts; i++)
107  {
108  Form_pg_attribute attr = TupleDescAttr(origTupdesc, i);
109 
110  if (state->oneCol)
111  state->tupdesc[i] = state->origTupdesc;
112  else
113  {
114  state->tupdesc[i] = CreateTemplateTupleDesc(2);
115 
116  TupleDescInitEntry(state->tupdesc[i], (AttrNumber) 1, NULL,
117  INT2OID, -1, 0);
118  TupleDescInitEntry(state->tupdesc[i], (AttrNumber) 2, NULL,
119  attr->atttypid,
120  attr->atttypmod,
121  attr->attndims);
123  attr->attcollation);
124  }
125 
126  /*
127  * If the compare proc isn't specified in the opclass definition, look
128  * up the index key type's default btree comparator.
129  */
130  if (index_getprocid(index, i + 1, GIN_COMPARE_PROC) != InvalidOid)
131  {
132  fmgr_info_copy(&(state->compareFn[i]),
133  index_getprocinfo(index, i + 1, GIN_COMPARE_PROC),
135  }
136  else
137  {
138  TypeCacheEntry *typentry;
139 
140  typentry = lookup_type_cache(attr->atttypid,
142  if (!OidIsValid(typentry->cmp_proc_finfo.fn_oid))
143  ereport(ERROR,
144  (errcode(ERRCODE_UNDEFINED_FUNCTION),
145  errmsg("could not identify a comparison function for type %s",
146  format_type_be(attr->atttypid))));
147  fmgr_info_copy(&(state->compareFn[i]),
148  &(typentry->cmp_proc_finfo),
150  }
151 
152  /* Opclass must always provide extract procs */
153  fmgr_info_copy(&(state->extractValueFn[i]),
156  fmgr_info_copy(&(state->extractQueryFn[i]),
159 
160  /*
161  * Check opclass capability to do tri-state or binary logic consistent
162  * check.
163  */
164  if (index_getprocid(index, i + 1, GIN_TRICONSISTENT_PROC) != InvalidOid)
165  {
166  fmgr_info_copy(&(state->triConsistentFn[i]),
169  }
170 
171  if (index_getprocid(index, i + 1, GIN_CONSISTENT_PROC) != InvalidOid)
172  {
173  fmgr_info_copy(&(state->consistentFn[i]),
174  index_getprocinfo(index, i + 1, GIN_CONSISTENT_PROC),
176  }
177 
178  if (state->consistentFn[i].fn_oid == InvalidOid &&
179  state->triConsistentFn[i].fn_oid == InvalidOid)
180  {
181  elog(ERROR, "missing GIN support function (%d or %d) for attribute %d of index \"%s\"",
183  i + 1, RelationGetRelationName(index));
184  }
185 
186  /*
187  * Check opclass capability to do partial match.
188  */
190  {
191  fmgr_info_copy(&(state->comparePartialFn[i]),
194  state->canPartialMatch[i] = true;
195  }
196  else
197  {
198  state->canPartialMatch[i] = false;
199  }
200 
201  /*
202  * If the index column has a specified collation, we should honor that
203  * while doing comparisons. However, we may have a collatable storage
204  * type for a noncollatable indexed data type (for instance, hstore
205  * uses text index entries). If there's no index collation then
206  * specify default collation in case the support functions need
207  * collation. This is harmless if the support functions don't care
208  * about collation, so we just do it unconditionally. (We could
209  * alternatively call get_typcollation, but that seems like expensive
210  * overkill --- there aren't going to be any cases where a GIN storage
211  * type has a nondefault collation.)
212  */
213  if (OidIsValid(index->rd_indcollation[i]))
214  state->supportCollation[i] = index->rd_indcollation[i];
215  else
216  state->supportCollation[i] = DEFAULT_COLLATION_OID;
217  }
218 }
219 
220 /*
221  * Extract attribute (column) number of stored entry from GIN tuple
222  */
225 {
226  OffsetNumber colN;
227 
228  if (ginstate->oneCol)
229  {
230  /* column number is not stored explicitly */
231  colN = FirstOffsetNumber;
232  }
233  else
234  {
235  Datum res;
236  bool isnull;
237 
238  /*
239  * First attribute is always int16, so we can safely use any tuple
240  * descriptor to obtain first attribute of tuple
241  */
242  res = index_getattr(tuple, FirstOffsetNumber, ginstate->tupdesc[0],
243  &isnull);
244  Assert(!isnull);
245 
246  colN = DatumGetUInt16(res);
247  Assert(colN >= FirstOffsetNumber && colN <= ginstate->origTupdesc->natts);
248  }
249 
250  return colN;
251 }
252 
253 /*
254  * Extract stored datum (and possible null category) from GIN tuple
255  */
256 Datum
258  GinNullCategory *category)
259 {
260  Datum res;
261  bool isnull;
262 
263  if (ginstate->oneCol)
264  {
265  /*
266  * Single column index doesn't store attribute numbers in tuples
267  */
268  res = index_getattr(tuple, FirstOffsetNumber, ginstate->origTupdesc,
269  &isnull);
270  }
271  else
272  {
273  /*
274  * Since the datum type depends on which index column it's from, we
275  * must be careful to use the right tuple descriptor here.
276  */
277  OffsetNumber colN = gintuple_get_attrnum(ginstate, tuple);
278 
280  ginstate->tupdesc[colN - 1],
281  &isnull);
282  }
283 
284  if (isnull)
285  *category = GinGetNullCategory(tuple, ginstate);
286  else
287  *category = GIN_CAT_NORM_KEY;
288 
289  return res;
290 }
291 
292 /*
293  * Allocate a new page (either by recycling, or by extending the index file)
294  * The returned buffer is already pinned and exclusive-locked
295  * Caller is responsible for initializing the page by calling GinInitBuffer
296  */
297 Buffer
299 {
300  Buffer buffer;
301  bool needLock;
302 
303  /* First, try to get a page from FSM */
304  for (;;)
305  {
306  BlockNumber blkno = GetFreeIndexPage(index);
307 
308  if (blkno == InvalidBlockNumber)
309  break;
310 
311  buffer = ReadBuffer(index, blkno);
312 
313  /*
314  * We have to guard against the possibility that someone else already
315  * recycled this page; the buffer may be locked if so.
316  */
317  if (ConditionalLockBuffer(buffer))
318  {
319  if (GinPageIsRecyclable(BufferGetPage(buffer)))
320  return buffer; /* OK to use */
321 
322  LockBuffer(buffer, GIN_UNLOCK);
323  }
324 
325  /* Can't use it, so release buffer and try again */
326  ReleaseBuffer(buffer);
327  }
328 
329  /* Must extend the file */
330  needLock = !RELATION_IS_LOCAL(index);
331  if (needLock)
333 
334  buffer = ReadBuffer(index, P_NEW);
335  LockBuffer(buffer, GIN_EXCLUSIVE);
336 
337  if (needLock)
339 
340  return buffer;
341 }
342 
343 void
344 GinInitPage(Page page, uint32 f, Size pageSize)
345 {
346  GinPageOpaque opaque;
347 
348  PageInit(page, pageSize, sizeof(GinPageOpaqueData));
349 
350  opaque = GinPageGetOpaque(page);
351  opaque->flags = f;
352  opaque->rightlink = InvalidBlockNumber;
353 }
354 
355 void
357 {
359 }
360 
361 void
363 {
364  GinMetaPageData *metadata;
365  Page page = BufferGetPage(b);
366 
368 
369  metadata = GinPageGetMeta(page);
370 
371  metadata->head = metadata->tail = InvalidBlockNumber;
372  metadata->tailFreeSize = 0;
373  metadata->nPendingPages = 0;
374  metadata->nPendingHeapTuples = 0;
375  metadata->nTotalPages = 0;
376  metadata->nEntryPages = 0;
377  metadata->nDataPages = 0;
378  metadata->nEntries = 0;
379  metadata->ginVersion = GIN_CURRENT_VERSION;
380 
381  /*
382  * Set pd_lower just past the end of the metadata. This is essential,
383  * because without doing so, metadata will be lost if xlog.c compresses
384  * the page.
385  */
386  ((PageHeader) page)->pd_lower =
387  ((char *) metadata + sizeof(GinMetaPageData)) - (char *) page;
388 }
389 
390 /*
391  * Compare two keys of the same index column
392  */
393 int
395  Datum a, GinNullCategory categorya,
396  Datum b, GinNullCategory categoryb)
397 {
398  /* if not of same null category, sort by that first */
399  if (categorya != categoryb)
400  return (categorya < categoryb) ? -1 : 1;
401 
402  /* all null items in same category are equal */
403  if (categorya != GIN_CAT_NORM_KEY)
404  return 0;
405 
406  /* both not null, so safe to call the compareFn */
407  return DatumGetInt32(FunctionCall2Coll(&ginstate->compareFn[attnum - 1],
408  ginstate->supportCollation[attnum - 1],
409  a, b));
410 }
411 
412 /*
413  * Compare two keys of possibly different index columns
414  */
415 int
417  OffsetNumber attnuma, Datum a, GinNullCategory categorya,
418  OffsetNumber attnumb, Datum b, GinNullCategory categoryb)
419 {
420  /* attribute number is the first sort key */
421  if (attnuma != attnumb)
422  return (attnuma < attnumb) ? -1 : 1;
423 
424  return ginCompareEntries(ginstate, attnuma, a, categorya, b, categoryb);
425 }
426 
427 
428 /*
429  * Support for sorting key datums in ginExtractEntries
430  *
431  * Note: we only have to worry about null and not-null keys here;
432  * ginExtractEntries never generates more than one placeholder null,
433  * so it doesn't have to sort those.
434  */
435 typedef struct
436 {
438  bool isnull;
439 } keyEntryData;
440 
441 typedef struct
442 {
445  bool haveDups;
446 } cmpEntriesArg;
447 
448 static int
449 cmpEntries(const void *a, const void *b, void *arg)
450 {
451  const keyEntryData *aa = (const keyEntryData *) a;
452  const keyEntryData *bb = (const keyEntryData *) b;
453  cmpEntriesArg *data = (cmpEntriesArg *) arg;
454  int res;
455 
456  if (aa->isnull)
457  {
458  if (bb->isnull)
459  res = 0; /* NULL "=" NULL */
460  else
461  res = 1; /* NULL ">" not-NULL */
462  }
463  else if (bb->isnull)
464  res = -1; /* not-NULL "<" NULL */
465  else
467  data->collation,
468  aa->datum, bb->datum));
469 
470  /*
471  * Detect if we have any duplicates. If there are equal keys, qsort must
472  * compare them at some point, else it wouldn't know whether one should go
473  * before or after the other.
474  */
475  if (res == 0)
476  data->haveDups = true;
477 
478  return res;
479 }
480 
481 
482 /*
483  * Extract the index key values from an indexable item
484  *
485  * The resulting key values are sorted, and any duplicates are removed.
486  * This avoids generating redundant index entries.
487  */
488 Datum *
490  Datum value, bool isNull,
491  int32 *nentries, GinNullCategory **categories)
492 {
493  Datum *entries;
494  bool *nullFlags;
495  int32 i;
496 
497  /*
498  * We don't call the extractValueFn on a null item. Instead generate a
499  * placeholder.
500  */
501  if (isNull)
502  {
503  *nentries = 1;
504  entries = (Datum *) palloc(sizeof(Datum));
505  entries[0] = (Datum) 0;
506  *categories = (GinNullCategory *) palloc(sizeof(GinNullCategory));
507  (*categories)[0] = GIN_CAT_NULL_ITEM;
508  return entries;
509  }
510 
511  /* OK, call the opclass's extractValueFn */
512  nullFlags = NULL; /* in case extractValue doesn't set it */
513  entries = (Datum *)
514  DatumGetPointer(FunctionCall3Coll(&ginstate->extractValueFn[attnum - 1],
515  ginstate->supportCollation[attnum - 1],
516  value,
517  PointerGetDatum(nentries),
518  PointerGetDatum(&nullFlags)));
519 
520  /*
521  * Generate a placeholder if the item contained no keys.
522  */
523  if (entries == NULL || *nentries <= 0)
524  {
525  *nentries = 1;
526  entries = (Datum *) palloc(sizeof(Datum));
527  entries[0] = (Datum) 0;
528  *categories = (GinNullCategory *) palloc(sizeof(GinNullCategory));
529  (*categories)[0] = GIN_CAT_EMPTY_ITEM;
530  return entries;
531  }
532 
533  /*
534  * If the extractValueFn didn't create a nullFlags array, create one,
535  * assuming that everything's non-null.
536  */
537  if (nullFlags == NULL)
538  nullFlags = (bool *) palloc0(*nentries * sizeof(bool));
539 
540  /*
541  * If there's more than one key, sort and unique-ify.
542  *
543  * XXX Using qsort here is notationally painful, and the overhead is
544  * pretty bad too. For small numbers of keys it'd likely be better to use
545  * a simple insertion sort.
546  */
547  if (*nentries > 1)
548  {
549  keyEntryData *keydata;
551 
552  keydata = (keyEntryData *) palloc(*nentries * sizeof(keyEntryData));
553  for (i = 0; i < *nentries; i++)
554  {
555  keydata[i].datum = entries[i];
556  keydata[i].isnull = nullFlags[i];
557  }
558 
559  arg.cmpDatumFunc = &ginstate->compareFn[attnum - 1];
560  arg.collation = ginstate->supportCollation[attnum - 1];
561  arg.haveDups = false;
562  qsort_arg(keydata, *nentries, sizeof(keyEntryData),
563  cmpEntries, (void *) &arg);
564 
565  if (arg.haveDups)
566  {
567  /* there are duplicates, must get rid of 'em */
568  int32 j;
569 
570  entries[0] = keydata[0].datum;
571  nullFlags[0] = keydata[0].isnull;
572  j = 1;
573  for (i = 1; i < *nentries; i++)
574  {
575  if (cmpEntries(&keydata[i - 1], &keydata[i], &arg) != 0)
576  {
577  entries[j] = keydata[i].datum;
578  nullFlags[j] = keydata[i].isnull;
579  j++;
580  }
581  }
582  *nentries = j;
583  }
584  else
585  {
586  /* easy, no duplicates */
587  for (i = 0; i < *nentries; i++)
588  {
589  entries[i] = keydata[i].datum;
590  nullFlags[i] = keydata[i].isnull;
591  }
592  }
593 
594  pfree(keydata);
595  }
596 
597  /*
598  * Create GinNullCategory representation from nullFlags.
599  */
600  *categories = (GinNullCategory *) palloc0(*nentries * sizeof(GinNullCategory));
601  for (i = 0; i < *nentries; i++)
602  (*categories)[i] = (nullFlags[i] ? GIN_CAT_NULL_KEY : GIN_CAT_NORM_KEY);
603 
604  return entries;
605 }
606 
607 bytea *
608 ginoptions(Datum reloptions, bool validate)
609 {
610  static const relopt_parse_elt tab[] = {
611  {"fastupdate", RELOPT_TYPE_BOOL, offsetof(GinOptions, useFastUpdate)},
612  {"gin_pending_list_limit", RELOPT_TYPE_INT, offsetof(GinOptions,
613  pendingListCleanupSize)}
614  };
615 
616  return (bytea *) build_reloptions(reloptions, validate,
618  sizeof(GinOptions),
619  tab, lengthof(tab));
620 }
621 
622 /*
623  * Fetch index's statistical data into *stats
624  *
625  * Note: in the result, nPendingPages can be trusted to be up-to-date,
626  * as can ginVersion; but the other fields are as of the last VACUUM.
627  */
628 void
630 {
631  Buffer metabuffer;
632  Page metapage;
633  GinMetaPageData *metadata;
634 
635  metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
636  LockBuffer(metabuffer, GIN_SHARE);
637  metapage = BufferGetPage(metabuffer);
638  metadata = GinPageGetMeta(metapage);
639 
640  stats->nPendingPages = metadata->nPendingPages;
641  stats->nTotalPages = metadata->nTotalPages;
642  stats->nEntryPages = metadata->nEntryPages;
643  stats->nDataPages = metadata->nDataPages;
644  stats->nEntries = metadata->nEntries;
645  stats->ginVersion = metadata->ginVersion;
646 
647  UnlockReleaseBuffer(metabuffer);
648 }
649 
650 /*
651  * Write the given statistics to the index's metapage
652  *
653  * Note: nPendingPages and ginVersion are *not* copied over
654  */
655 void
656 ginUpdateStats(Relation index, const GinStatsData *stats, bool is_build)
657 {
658  Buffer metabuffer;
659  Page metapage;
660  GinMetaPageData *metadata;
661 
662  metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
663  LockBuffer(metabuffer, GIN_EXCLUSIVE);
664  metapage = BufferGetPage(metabuffer);
665  metadata = GinPageGetMeta(metapage);
666 
668 
669  metadata->nTotalPages = stats->nTotalPages;
670  metadata->nEntryPages = stats->nEntryPages;
671  metadata->nDataPages = stats->nDataPages;
672  metadata->nEntries = stats->nEntries;
673 
674  /*
675  * Set pd_lower just past the end of the metadata. This is essential,
676  * because without doing so, metadata will be lost if xlog.c compresses
677  * the page. (We must do this here because pre-v11 versions of PG did not
678  * set the metapage's pd_lower correctly, so a pg_upgraded index might
679  * contain the wrong value.)
680  */
681  ((PageHeader) metapage)->pd_lower =
682  ((char *) metadata + sizeof(GinMetaPageData)) - (char *) metapage;
683 
684  MarkBufferDirty(metabuffer);
685 
686  if (RelationNeedsWAL(index) && !is_build)
687  {
688  XLogRecPtr recptr;
689  ginxlogUpdateMeta data;
690 
691  data.node = index->rd_node;
692  data.ntuples = 0;
694  memcpy(&data.metadata, metadata, sizeof(GinMetaPageData));
695 
696  XLogBeginInsert();
697  XLogRegisterData((char *) &data, sizeof(ginxlogUpdateMeta));
699 
700  recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_UPDATE_META_PAGE);
701  PageSetLSN(metapage, recptr);
702  }
703 
704  UnlockReleaseBuffer(metabuffer);
705 
707 }
BlockNumber nEntryPages
Definition: ginblock.h:81
BlockNumber prevTail
Definition: ginxlog.h:172
ambeginscan_function ambeginscan
Definition: amapi.h:271
#define GIN_UNLOCK
Definition: gin_private.h:48
uint8 amparallelvacuumoptions
Definition: amapi.h:248
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
BlockNumber nEntryPages
Definition: gin.h:46
Buffer GinNewBuffer(Relation index)
Definition: ginutil.c:298
IndexBulkDeleteResult * ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: ginvacuum.c:688
IndexScanDesc ginbeginscan(Relation rel, int nkeys, int norderbys)
Definition: ginscan.c:25
int64 gingetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition: ginget.c:1917
void ginendscan(IndexScanDesc scan)
Definition: ginscan.c:458
Definition: fmgr.h:56
Oid supportCollation[INDEX_MAX_KEYS]
Definition: gin_private.h:87
ambulkdelete_function ambulkdelete
Definition: amapi.h:262
void ginrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
Definition: ginscan.c:442
bool amcanmulticol
Definition: amapi.h:228
void GinInitMetabuffer(Buffer b)
Definition: ginutil.c:362
uint16 amsupport
Definition: amapi.h:216
RelFileNode node
Definition: ginxlog.h:170
FmgrInfo * cmpDatumFunc
Definition: ginutil.c:443
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:803
#define GIN_EXTRACTQUERY_PROC
Definition: gin.h:24
amgettuple_function amgettuple
Definition: amapi.h:273
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
Relation index
Definition: gin_private.h:58
void gincostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Definition: selfuncs.c:7355
#define DatumGetInt32(X)
Definition: postgres.h:516
#define RelationGetDescr(relation)
Definition: rel.h:503
void GinInitPage(Page page, uint32 f, Size pageSize)
Definition: ginutil.c:344
bool amcanorderbyop
Definition: amapi.h:222
#define DatumGetUInt16(X)
Definition: postgres.h:502
amproperty_function amproperty
Definition: amapi.h:267
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1565
#define ExclusiveLock
Definition: lockdefs.h:44
bool isnull
Definition: ginutil.c:438
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:232
#define PointerGetDatum(X)
Definition: postgres.h:600
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define GinGetNullCategory(itup, ginstate)
Definition: ginblock.h:221
#define RELATION_IS_LOCAL(relation)
Definition: rel.h:621
BlockNumber rightlink
Definition: ginblock.h:32
amparallelrescan_function amparallelrescan
Definition: amapi.h:282
#define END_CRIT_SECTION()
Definition: miscadmin.h:149
bool amstorage
Definition: amapi.h:236
#define REGBUF_WILL_INIT
Definition: xloginsert.h:33
bool canPartialMatch[INDEX_MAX_KEYS]
Definition: gin_private.h:85
#define START_CRIT_SECTION()
Definition: miscadmin.h:147
int ginCompareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, GinNullCategory categorya, Datum b, GinNullCategory categoryb)
Definition: ginutil.c:394
int ginCompareAttEntries(GinState *ginstate, OffsetNumber attnuma, Datum a, GinNullCategory categorya, OffsetNumber attnumb, Datum b, GinNullCategory categoryb)
Definition: ginutil.c:416
int errcode(int sqlerrcode)
Definition: elog.c:698
int64 nEntries
Definition: gin.h:48
#define MemSet(start, val, len)
Definition: c.h:1008
FmgrInfo consistentFn[INDEX_MAX_KEYS]
Definition: gin_private.h:81
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
bool ampredlocks
Definition: amapi.h:240
FmgrInfo extractValueFn[INDEX_MAX_KEYS]
Definition: gin_private.h:79
#define GIN_TRICONSISTENT_PROC
Definition: gin.h:27
BlockNumber nTotalPages
Definition: ginblock.h:80
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3768
#define GinPageGetOpaque(page)
Definition: ginblock.h:111
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:52
Datum ginhandler(PG_FUNCTION_ARGS)
Definition: ginutil.c:38
#define P_NEW
Definition: bufmgr.h:91
void ginbuildempty(Relation index)
Definition: gininsert.c:437
aminsert_function aminsert
Definition: amapi.h:261
#define GIN_COMPARE_PARTIAL_PROC
Definition: gin.h:26
#define lengthof(array)
Definition: c.h:734
int64 nEntries
Definition: ginblock.h:83
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1148
unsigned int Oid
Definition: postgres_ext.h:31
Oid amkeytype
Definition: amapi.h:250
#define OidIsValid(objectId)
Definition: c.h:710
bool amoptionalkey
Definition: amapi.h:230
amvalidate_function amvalidate
Definition: amapi.h:269
Datum datum
Definition: ginutil.c:437
signed int int32
Definition: c.h:429
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1904
uint16 OffsetNumber
Definition: off.h:24
Definition: type.h:89
int64 nPendingHeapTuples
Definition: ginblock.h:75
FmgrInfo cmp_proc_finfo
Definition: typcache.h:76
void pfree(void *pointer)
Definition: mcxt.c:1169
amgetbitmap_function amgetbitmap
Definition: amapi.h:274
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3791
Oid * rd_indcollation
Definition: rel.h:212
#define ERROR
Definition: elog.h:46
IndexBuildResult * ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
Definition: gininsert.c:320
ambuild_function ambuild
Definition: amapi.h:259
#define GIN_META
Definition: ginblock.h:44
signed char GinNullCategory
Definition: ginblock.h:207
bool haveDups
Definition: ginutil.c:445
amoptions_function amoptions
Definition: amapi.h:266
bool ginvalidate(Oid opclassoid)
Definition: ginvalidate.c:33
#define XLOG_GIN_UPDATE_META_PAGE
Definition: ginxlog.h:162
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:754
void ginadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
Definition: ginvalidate.c:279
bool amcaninclude
Definition: amapi.h:244
BlockNumber head
Definition: ginblock.h:62
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
Definition: fmgr.c:608
amcostestimate_function amcostestimate
Definition: amapi.h:265
OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple)
Definition: ginutil.c:224
bool amcanunique
Definition: amapi.h:226
#define GIN_CAT_NORM_KEY
Definition: ginblock.h:209
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:263
amendscan_function amendscan
Definition: amapi.h:275
FmgrInfo comparePartialFn[INDEX_MAX_KEYS]
Definition: gin_private.h:83
bool amcanbackward
Definition: amapi.h:224
BlockNumber tail
Definition: ginblock.h:63
#define FirstOffsetNumber
Definition: off.h:27
#define GIN_CONSISTENT_PROC
Definition: gin.h:25
#define REGBUF_STANDARD
Definition: xloginsert.h:35
void initGinState(GinState *state, Relation index)
Definition: ginutil.c:95
#define RelationGetRelationName(relation)
Definition: rel.h:511
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
unsigned int uint32
Definition: c.h:441
FmgrInfo extractQueryFn[INDEX_MAX_KEYS]
Definition: gin_private.h:80
#define GINNProcs
Definition: gin.h:29
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
Datum gintuple_get_key(GinState *ginstate, IndexTuple tuple, GinNullCategory *category)
Definition: ginutil.c:257
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:583
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
amrescan_function amrescan
Definition: amapi.h:272
bool amcanparallel
Definition: amapi.h:242
bool ConditionalLockBuffer(Buffer buffer)
Definition: bufmgr.c:4033
BlockNumber newRightlink
Definition: ginxlog.h:173
bytea * ginoptions(Datum reloptions, bool validate)
Definition: ginutil.c:608
#define GIN_SHARE
Definition: gin_private.h:49
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:403
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:340
BlockNumber nPendingPages
Definition: gin.h:44
bool amsearchnulls
Definition: amapi.h:234
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:434
#define GIN_OPTIONS_PROC
Definition: gin.h:28
#define GIN_CAT_NULL_KEY
Definition: ginblock.h:210
void * palloc0(Size size)
Definition: mcxt.c:1093
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:453
uintptr_t Datum
Definition: postgres.h:411
void ginGetStats(Relation index, GinStatsData *stats)
Definition: ginutil.c:629
TupleDesc tupdesc[INDEX_MAX_KEYS]
Definition: gin_private.h:73
#define BufferGetPageSize(buffer)
Definition: bufmgr.h:156
#define GIN_EXCLUSIVE
Definition: gin_private.h:50
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4007
#define GIN_CAT_NULL_ITEM
Definition: ginblock.h:212
bool amclusterable
Definition: amapi.h:238
bool amsearcharray
Definition: amapi.h:232
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition: typcache.c:339
#define InvalidOid
Definition: postgres_ext.h:36
BlockNumber nDataPages
Definition: gin.h:47
int16 attnum
Definition: pg_attribute.h:83
static struct @143 value
Oid fn_oid
Definition: fmgr.h:59
#define ereport(elevel,...)
Definition: elog.h:157
Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Definition: fmgr.c:1170
bool amusemaintenanceworkmem
Definition: amapi.h:246
BlockNumber GetFreeIndexPage(Relation rel)
Definition: indexfsm.c:38
GinMetaPageData metadata
Definition: ginxlog.h:171
RelFileNode rd_node
Definition: rel.h:56
#define makeNode(_type_)
Definition: nodes.h:584
PageHeaderData * PageHeader
Definition: bufpage.h:166
uint32 tailFreeSize
Definition: ginblock.h:68
amadjustmembers_function amadjustmembers
Definition: amapi.h:270
#define GIN_EXTRACTVALUE_PROC
Definition: gin.h:23
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
Definition: regguts.h:317
IndexBulkDeleteResult * ginbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: ginvacuum.c:565
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:694
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
size_t Size
Definition: c.h:540
#define GIN_CURRENT_VERSION
Definition: ginblock.h:103
#define InvalidBlockNumber
Definition: block.h:33
void GinInitBuffer(Buffer b, uint32 f)
Definition: ginutil.c:356
BlockNumber nTotalPages
Definition: gin.h:45
#define index_getattr(tup, attnum, tupleDesc, isnull)
Definition: itup.h:100
ammarkpos_function ammarkpos
Definition: amapi.h:276
bool amcanorder
Definition: amapi.h:220
ambuildphasename_function ambuildphasename
Definition: amapi.h:268
Oid collation
Definition: ginutil.c:444
#define VACUUM_OPTION_PARALLEL_BULKDEL
Definition: vacuum.h:45
#define RelationNeedsWAL(relation)
Definition: rel.h:601
int32 ginVersion
Definition: ginblock.h:100
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:280
int32 ginVersion
Definition: gin.h:49
#define DatumGetPointer(X)
Definition: postgres.h:593
uint16 amstrategies
Definition: amapi.h:214
bool GinPageIsRecyclable(Page page)
Definition: ginvacuum.c:802
void ginUpdateStats(Relation index, const GinStatsData *stats, bool is_build)
Definition: ginutil.c:656
void * palloc(Size size)
Definition: mcxt.c:1062
int errmsg(const char *fmt,...)
Definition: elog.c:909
uint16 amoptsprocnum
Definition: amapi.h:218
bool gininsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
Definition: gininsert.c:488
#define elog(elevel,...)
Definition: elog.h:232
ambuildempty_function ambuildempty
Definition: amapi.h:260
int i
void * arg
BlockNumber nDataPages
Definition: ginblock.h:82
Definition: c.h:621
TupleDesc origTupdesc
Definition: gin_private.h:72
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define TYPECACHE_CMP_PROC_FINFO
Definition: typcache.h:142
#define GinPageGetMeta(p)
Definition: ginblock.h:105
FmgrInfo triConsistentFn[INDEX_MAX_KEYS]
Definition: gin_private.h:82
#define GIN_CAT_EMPTY_ITEM
Definition: ginblock.h:211
void XLogBeginInsert(void)
Definition: xloginsert.c:135
#define VACUUM_OPTION_PARALLEL_CLEANUP
Definition: vacuum.h:60
bool oneCol
Definition: gin_private.h:59
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368
int Buffer
Definition: buf.h:23
amcanreturn_function amcanreturn
Definition: amapi.h:264
int16 AttrNumber
Definition: attnum.h:21
Datum * ginExtractEntries(GinState *ginstate, OffsetNumber attnum, Datum value, bool isNull, int32 *nentries, GinNullCategory **categories)
Definition: ginutil.c:489
static int cmpEntries(const void *a, const void *b, void *arg)
Definition: ginutil.c:449
#define offsetof(type, field)
Definition: c.h:727
Pointer Page
Definition: bufpage.h:78
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:281
#define GIN_COMPARE_PROC
Definition: gin.h:22
FmgrInfo compareFn[INDEX_MAX_KEYS]
Definition: gin_private.h:78
amrestrpos_function amrestrpos
Definition: amapi.h:277
BlockNumber nPendingPages
Definition: ginblock.h:74
void PageInit(Page page, Size pageSize, Size specialSize)
Definition: bufpage.c:42
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:769