24#include "utils/fmgrprotos.h"
49 elog(
ERROR,
"failed to add item to GiST index page, item %d out of %d, size %d bytes",
61 unsigned int size = freespace,
117 memmove(&itvec[*
len], additvec,
sizeof(
IndexTuple) * addlen);
135 for (
i = 0;
i < veclen;
i++)
138 ptr = ret =
palloc(*memlen);
140 for (
i = 0;
i < veclen;
i++)
156 Datum *attr,
bool *isnull)
236 Datum *dst,
bool *dstisnull)
249 if (isnull1 && isnull2)
256 if (isnull1 ==
false && isnull2 ==
false)
258 evec->
vector[0] = *entry1;
259 evec->
vector[1] = *entry2;
261 else if (isnull1 ==
false)
263 evec->
vector[0] = *entry1;
264 evec->
vector[1] = *entry1;
268 evec->
vector[0] = *entry2;
269 evec->
vector[1] = *entry2;
318 bool neednew =
false;
337 oldentries +
i, oldisnull[
i],
338 addentries +
i, addisnull[
i],
339 attr +
i, isnull +
i);
384 int keep_current_best;
405 best_penalty[0] = -1;
430 keep_current_best = -1;
459 &identry[
j], isnull[
j]);
461 zero_penalty =
false;
463 if (best_penalty[
j] < 0 || usize < best_penalty[
j])
474 best_penalty[
j] = usize;
477 best_penalty[
j + 1] = -1;
480 keep_current_best = -1;
482 else if (best_penalty[
j] == usize)
497 zero_penalty =
false;
508 if (keep_current_best == -1)
513 if (keep_current_best == 0)
518 keep_current_best = -1;
530 if (keep_current_best == -1)
535 if (keep_current_best == 1)
576 const Datum *attdata,
const bool *isnull,
bool isleaf)
597 const Datum *attdata,
const bool *isnull,
bool isleaf,
Datum *compatt)
623 compatt[
i] = cep->
key;
637 compatt[
i] = attdata[
i];
731 (isNullOrig ==
false && isNullAdd ==
false))
739 if (isnan(penalty) || penalty < 0.0)
742 else if (isNullOrig && isNullAdd)
797 (
errcode(ERRCODE_INDEX_CORRUPTED),
798 errmsg(
"index \"%s\" contains unexpected zero page at block %u",
801 errhint(
"Please REINDEX it.")));
808 (
errcode(ERRCODE_INDEX_CORRUPTED),
809 errmsg(
"index \"%s\" contains corrupted page at block %u",
812 errhint(
"Please REINDEX it.")));
935 bool *
res,
bool *isnull)
1018 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
1055 Assert(rel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED);
@ AMPROP_DISTANCE_ORDERABLE
#define InvalidBlockNumber
BlockNumber BufferGetBlockNumber(Buffer buffer)
Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)
bool ConditionalLockBuffer(Buffer buffer)
void ReleaseBuffer(Buffer buffer)
void LockBuffer(Buffer buffer, int mode)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
static Page BufferGetPage(Buffer buffer)
void PageInit(Page page, Size pageSize, Size specialSize)
Size PageGetFreeSpace(Page page)
static bool PageIsEmpty(Page page)
static Item PageGetItem(Page page, ItemId itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static bool PageIsNew(Page page)
static OffsetNumber PageGetMaxOffsetNumber(Page page)
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
static uint16 PageGetSpecialSize(Page page)
#define Assert(condition)
#define OidIsValid(objectId)
static void PGresult * res
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
static float4 get_float4_infinity(void)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Datum OidFunctionCall1Coll(Oid functionId, Oid collation, Datum arg1)
Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
#define PG_GETARG_UINT16(n)
#define PG_RETURN_UINT16(x)
#define GIST_STRATNUM_PROC
struct GISTENTRY GISTENTRY
#define GIST_COMPRESS_PROC
#define GistPageIsLeaf(page)
#define GIST_DISTANCE_PROC
static FullTransactionId GistPageGetDeleteXid(Page page)
#define GistPageIsDeleted(page)
#define GistPageGetOpaque(page)
#define gistentryinit(e, k, r, pg, o, l)
void gistDeCompressAtt(GISTSTATE *giststate, Relation r, IndexTuple tuple, Page p, OffsetNumber o, GISTENTRY *attdata, bool *isnull)
bytea * gistoptions(Datum reloptions, bool validate)
Buffer gistNewBuffer(Relation r, Relation heaprel)
bool gistproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
bool gistPageRecyclable(Page page)
void gistMakeUnionKey(GISTSTATE *giststate, int attno, GISTENTRY *entry1, bool isnull1, GISTENTRY *entry2, bool isnull2, Datum *dst, bool *dstisnull)
void gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, Datum *attr, bool *isnull)
bool gistnospace(Page page, IndexTuple *itvec, int len, OffsetNumber todelete, Size freespace)
HeapTuple gistFetchTuple(GISTSTATE *giststate, Relation r, IndexTuple tuple)
bool gistKeyIsEQ(GISTSTATE *giststate, int attno, Datum a, Datum b)
static Datum gistFetchAtt(GISTSTATE *giststate, int nkey, Datum k, Relation r)
void gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off)
IndexTuple gistFormTuple(GISTSTATE *giststate, Relation r, const Datum *attdata, const bool *isnull, bool isleaf)
IndexTuple * gistextractpage(Page page, int *len)
void gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e, Datum k, Relation r, Page pg, OffsetNumber o, bool l, bool isNull)
bool gistfitpage(IndexTuple *itvec, int len)
IndexTuple gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate)
OffsetNumber gistchoose(Relation r, Page p, IndexTuple it, GISTSTATE *giststate)
XLogRecPtr gistGetFakeLSN(Relation rel)
void gistCompressValues(GISTSTATE *giststate, Relation r, const Datum *attdata, const bool *isnull, bool isleaf, Datum *compatt)
IndexTuple * gistjoinvector(IndexTuple *itvec, int *len, IndexTuple *additvec, int addlen)
Datum gist_stratnum_identity(PG_FUNCTION_ARGS)
StrategyNumber GistTranslateStratnum(Oid opclass, StrategyNumber strat)
void gistinitpage(Page page, uint32 f)
IndexTuple gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
void GISTInitBuffer(Buffer b, uint32 f)
void gistcheckpage(Relation rel, Buffer buf)
IndexTupleData * gistfillitupvec(IndexTuple *vec, int veclen, int *memlen)
float gistpenalty(GISTSTATE *giststate, int attno, GISTENTRY *orig, bool isNullOrig, GISTENTRY *add, bool isNullAdd)
XLogRecPtr gistXLogAssignLSN(void)
void gistXLogPageReuse(Relation rel, Relation heaprel, BlockNumber blkno, FullTransactionId deleteXid)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
BlockNumber GetFreeIndexPage(Relation rel)
IndexTuple index_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
struct ItemIdData ItemIdData
static void ItemPointerSetOffsetNumber(ItemPointerData *pointer, OffsetNumber offsetNumber)
IndexTupleData * IndexTuple
#define IndexTupleSize(itup)
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
bool get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Oid get_index_column_opclass(Oid index_oid, int attno)
void * repalloc(void *pointer, Size size)
#define InvalidOffsetNumber
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
pg_prng_state pg_global_prng_state
bool pg_prng_bool(pg_prng_state *state)
static Datum PointerGetDatum(const void *X)
static Datum Int16GetDatum(int16 X)
static Datum UInt16GetDatum(uint16 X)
static Datum ObjectIdGetDatum(Oid X)
static uint16 DatumGetUInt16(Datum X)
static Pointer DatumGetPointer(Datum X)
bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid)
MemoryContextSwitchTo(old_ctx)
#define RelationGetRelationName(relation)
#define RelationNeedsWAL(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
#define RelationIsPermanent(relation)
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
static pg_noinline void Size size
FmgrInfo fetchFn[INDEX_MAX_KEYS]
FmgrInfo penaltyFn[INDEX_MAX_KEYS]
Oid supportCollation[INDEX_MAX_KEYS]
FmgrInfo decompressFn[INDEX_MAX_KEYS]
FmgrInfo compressFn[INDEX_MAX_KEYS]
FmgrInfo equalFn[INDEX_MAX_KEYS]
FmgrInfo unionFn[INDEX_MAX_KEYS]
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
#define SearchSysCacheExists4(cacheId, key1, key2, key3, key4)
XLogRecPtr GetXLogInsertRecPtr(void)
XLogRecPtr GetFakeLSNForUnloggedRel(void)
#define XLogStandbyInfoActive()
#define FirstNormalUnloggedLSN
#define XLogRecPtrIsInvalid(r)
#define InvalidXLogRecPtr