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