71 #define BRIN_ALL_BLOCKRANGES InvalidBlockNumber
77 bool include_partial,
double *numSummarized,
double *numExisting);
179 heapBlk = (origHeapBlk / pagesPerRange) * pagesPerRange;
183 bool need_insert =
false;
197 heapBlk == origHeapBlk &&
215 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
216 errmsg(
"request for BRIN range summarization for index \"%s\" page %u was not recorded",
296 buf, off, origtup, origsz, newtup, newsz,
439 nnullkeys = (
int *) ptr;
458 for (
int keyno = 0; keyno < scan->
numberOfKeys; keyno++)
469 (
key->sk_collation ==
471 keyattno - 1)->attcollation));
483 if (consistentFn[keyattno - 1].fn_oid ==
InvalidOid)
488 Assert(nkeys[keyattno - 1] == 0);
489 Assert(nnullkeys[keyattno - 1] == 0);
500 nullkeys[keyattno - 1][nnullkeys[keyattno - 1]] =
key;
501 nnullkeys[keyattno - 1]++;
505 keys[keyattno - 1][nkeys[keyattno - 1]] =
key;
506 nkeys[keyattno - 1]++;
530 bool gottuple =
false;
590 if (nkeys[attno - 1] == 0 && nnullkeys[attno - 1] == 0)
605 nnullkeys[attno - 1]))
625 if (!nkeys[attno - 1])
628 Assert((nkeys[attno - 1] > 0) &&
655 if (consistentFn[attno - 1].fn_nargs >= 4)
678 for (keyno = 0; keyno < nkeys[attno - 1]; keyno++)
681 keys[attno - 1][keyno]->sk_collation,
706 for (pageno = heapBlk;
729 return totalpages * 10;
737 ScanKey orderbys,
int norderbys)
748 memmove(scan->
keyData, scankey,
791 while (thisblock >
state->bs_currRangeStart +
state->bs_pagesPerRange - 1)
795 "brinbuildCallback: completed a range: %u--%u",
796 state->bs_currRangeStart,
797 state->bs_currRangeStart +
state->bs_pagesPerRange));
803 state->bs_currRangeStart +=
state->bs_pagesPerRange;
832 elog(
ERROR,
"index \"%s\" already contains data",
886 idxtuples =
state->bs_numtuples;
1019 int save_sec_context;
1021 double numSummarized = 0;
1025 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1026 errmsg(
"recovery is in progress"),
1027 errhint(
"BRIN control functions cannot be executed during recovery.")));
1031 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1032 errmsg(
"block number out of range: %lld",
1033 (
long long) heapBlk64)));
1065 save_sec_context = -1;
1066 save_nestlevel = -1;
1072 if (indexRel->
rd_rel->relkind != RELKIND_INDEX ||
1073 indexRel->
rd_rel->relam != BRIN_AM_OID)
1075 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1076 errmsg(
"\"%s\" is not a BRIN index",
1080 if (heapRel != NULL && !
object_ownercheck(RelationRelationId, indexoid, save_userid))
1092 errmsg(
"could not open parent table of index \"%s\"",
1096 brinsummarize(indexRel, heapRel, heapBlk,
true, &numSummarized, NULL);
1126 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1127 errmsg(
"recovery is in progress"),
1128 errhint(
"BRIN control functions cannot be executed during recovery.")));
1132 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1133 errmsg(
"block number out of range: %lld",
1134 (
long long) heapBlk64)));
1155 if (indexRel->
rd_rel->relkind != RELKIND_INDEX ||
1156 indexRel->
rd_rel->relam != BRIN_AM_OID)
1158 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1159 errmsg(
"\"%s\" is not a BRIN index",
1175 errmsg(
"could not open parent table of index \"%s\"",
1200 int totalstored = 0;
1217 for (keyno = 0; keyno < tupdesc->
natts; keyno++)
1230 totalsize = offsetof(
BrinDesc, bd_info) +
1233 bdesc =
palloc(totalsize);
1240 for (keyno = 0; keyno < tupdesc->
natts; keyno++)
1241 bdesc->
bd_info[keyno] = opcinfo[keyno];
1290 state->bs_irel = idxRel;
1291 state->bs_numtuples = 0;
1293 state->bs_pagesPerRange = pagesPerRange;
1294 state->bs_currRangeStart = 0;
1295 state->bs_rmAccess = revmap;
1366 state->bs_rmAccess, &phbuf,
1367 heapBlk, phtup, phsz);
1374 if (heapBlk +
state->bs_pagesPerRange > heapNumBlks)
1388 state->bs_pagesPerRange);
1393 scanNumBlks =
state->bs_pagesPerRange;
1406 state->bs_currRangeStart = heapBlk;
1408 heapBlk, scanNumBlks,
1430 heapBlk,
state->bs_dtuple, &newsize);
1434 state->bs_rmAccess, heapBlk, phbuf, offset,
1435 phtup, phsz, newtup, newsize, samepage);
1455 elog(
ERROR,
"missing placeholder tuple");
1479 bool include_partial,
double *numSummarized,
double *numExisting)
1497 startBlk = (pageRange / pagesPerRange) * pagesPerRange;
1498 heapNumBlocks =
Min(heapNumBlocks, startBlk + pagesPerRange);
1500 if (startBlk > heapNumBlocks)
1511 for (; startBlk < heapNumBlocks; startBlk += pagesPerRange)
1523 if (!include_partial &&
1524 (startBlk + pagesPerRange > heapNumBlocks))
1548 *numSummarized += 1.0;
1553 *numExisting += 1.0;
1581 state->bs_dtuple, &size);
1583 &
state->bs_currentInsertBuf,
state->bs_currRangeStart,
1585 state->bs_numtuples++;
1680 for (blkno = 0; blkno < nblocks; blkno++)
1707 bool modified =
false;
1763 for (keyno = 0; keyno < nnullkeys; keyno++)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
bool AutoVacuumRequestWork(AutoVacuumWorkItemType type, Oid relationId, BlockNumber blkno)
static Datum values[MAXATTR]
IndexBulkDeleteResult * brinvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
static void brin_vacuum_scan(Relation idxrel, BufferAccessStrategy strategy)
static BrinBuildState * initialize_brin_buildstate(Relation idxRel, BrinRevmap *revmap, BlockNumber pagesPerRange)
Datum brin_desummarize_range(PG_FUNCTION_ARGS)
void brinrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
static void terminate_brin_buildstate(BrinBuildState *state)
Datum brin_summarize_range(PG_FUNCTION_ARGS)
#define BRIN_ALL_BLOCKRANGES
Datum brin_summarize_new_values(PG_FUNCTION_ARGS)
IndexScanDesc brinbeginscan(Relation r, int nkeys, int norderbys)
IndexBuildResult * brinbuild(Relation heap, Relation index, IndexInfo *indexInfo)
int64 bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
static void brinsummarize(Relation index, Relation heapRel, BlockNumber pageRange, bool include_partial, double *numSummarized, double *numExisting)
static bool add_values_to_range(Relation idxRel, BrinDesc *bdesc, BrinMemTuple *dtup, Datum *values, bool *nulls)
static void form_and_insert_tuple(BrinBuildState *state)
void brinbuildempty(Relation index)
void brin_free_desc(BrinDesc *bdesc)
static void union_tuples(BrinDesc *bdesc, BrinMemTuple *a, BrinTuple *b)
void brinGetStats(Relation index, BrinStatsData *stats)
BrinDesc * brin_build_desc(Relation rel)
struct BrinBuildState BrinBuildState
struct BrinOpaque BrinOpaque
static void summarize_range(IndexInfo *indexInfo, BrinBuildState *state, Relation heapRel, BlockNumber heapBlk, BlockNumber heapNumBlks)
bool brininsert(Relation idxRel, Datum *values, bool *nulls, ItemPointer heaptid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
Datum brinhandler(PG_FUNCTION_ARGS)
bytea * brinoptions(Datum reloptions, bool validate)
IndexBulkDeleteResult * brinbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
static void brinbuildCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *brstate)
void brinendscan(IndexScanDesc scan)
static bool check_null_keys(BrinValues *bval, ScanKey *nullkeys, int nnullkeys)
#define BrinGetPagesPerRange(relation)
#define BrinGetAutoSummarize(relation)
#define BRIN_LAST_OPTIONAL_PROCNUM
#define BRIN_PROCNUM_UNION
#define BRIN_PROCNUM_OPTIONS
#define BRIN_PROCNUM_OPCINFO
#define BRIN_PROCNUM_CONSISTENT
#define BRIN_PROCNUM_ADDVALUE
#define BRIN_CURRENT_VERSION
#define BRIN_METAPAGE_BLKNO
bool brin_doupdate(Relation idxrel, BlockNumber pagesPerRange, BrinRevmap *revmap, BlockNumber heapBlk, Buffer oldbuf, OffsetNumber oldoff, const BrinTuple *origtup, Size origsz, const BrinTuple *newtup, Size newsz, bool samepage)
void brin_page_cleanup(Relation idxrel, Buffer buf)
OffsetNumber brin_doinsert(Relation idxrel, BlockNumber pagesPerRange, BrinRevmap *revmap, Buffer *buffer, BlockNumber heapBlk, BrinTuple *tup, Size itemsz)
void brin_metapage_init(Page page, BlockNumber pagesPerRange, uint16 version)
bool brin_can_do_samepage_update(Buffer buffer, Size origsz, Size newsz)
bool brinRevmapDesummarizeRange(Relation idxrel, BlockNumber heapBlk)
BrinTuple * brinGetTupleForHeapBlock(BrinRevmap *revmap, BlockNumber heapBlk, Buffer *buf, OffsetNumber *off, Size *size, int mode, Snapshot snapshot)
BrinRevmap * brinRevmapInitialize(Relation idxrel, BlockNumber *pagesPerRange, Snapshot snapshot)
void brinRevmapTerminate(BrinRevmap *revmap)
BrinTuple * brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple, Size *size)
BrinMemTuple * brin_new_memtuple(BrinDesc *brdesc)
BrinMemTuple * brin_deform_tuple(BrinDesc *brdesc, BrinTuple *tuple, BrinMemTuple *dMemtuple)
BrinMemTuple * brin_memtuple_initialize(BrinMemTuple *dtuple, BrinDesc *brdesc)
BrinTuple * brin_copy_tuple(BrinTuple *tuple, Size len, BrinTuple *dest, Size *destsz)
void brin_free_tuple(BrinTuple *tuple)
BrinTuple * brin_form_placeholder_tuple(BrinDesc *brdesc, BlockNumber blkno, Size *size)
bool brinvalidate(Oid opclassoid)
#define SizeOfBrinCreateIdx
#define XLOG_BRIN_CREATE_INDEX
#define BufferIsInvalid(buffer)
BlockNumber BufferGetBlockNumber(Buffer buffer)
void ReleaseBuffer(Buffer buffer)
void UnlockReleaseBuffer(Buffer buffer)
void MarkBufferDirty(Buffer buffer)
void LockBuffer(Buffer buffer, int mode)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
#define BUFFER_LOCK_UNLOCK
#define BUFFER_LOCK_SHARE
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
#define BUFFER_LOCK_EXCLUSIVE
static bool BufferIsValid(Buffer bufnum)
Size PageGetFreeSpace(Page page)
static char * PageGetContents(Page page)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static void PageSetLSN(Page page, XLogRecPtr lsn)
#define PG_USED_FOR_ASSERTS_ONLY
#define OidIsValid(objectId)
Datum datumCopy(Datum value, bool typByVal, int typLen)
elog(ERROR, "%s: %s", p2, msg)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define palloc0_array(type, count)
#define palloc0_object(type)
Datum FunctionCall4Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Datum Int64GetDatum(int64 X)
Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_INT64(n)
#define FunctionCall1(flinfo, arg1)
#define PG_RETURN_INT32(x)
#define PG_RETURN_POINTER(x)
void FreeSpaceMapVacuumRange(Relation rel, BlockNumber start, BlockNumber end)
void FreeSpaceMapVacuum(Relation rel)
void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail)
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
int NewGUCNestLevel(void)
void AtEOXact_GUC(bool isCommit, int nestLevel)
Oid IndexGetRelation(Oid indexId, bool missing_ok)
IndexInfo * BuildIndexInfo(Relation index)
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Relation index_open(Oid relationId, LOCKMODE lockmode)
#define ItemIdGetLength(itemId)
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Assert(fmt[strlen(fmt) - 1] !='\n')
#define ShareUpdateExclusiveLock
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SMALL_SIZES
#define MemoryContextResetAndDeleteChildren(ctx)
#define SECURITY_RESTRICTED_OPERATION
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define END_CRIT_SECTION()
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
void SetUserIdAndSecContext(Oid userid, int sec_context)
#define FirstOffsetNumber
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
FormData_pg_attribute * Form_pg_attribute
#define ERRCODE_UNDEFINED_TABLE
#define pgstat_count_index_scan(rel)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
static void addrange(struct cvec *cv, chr from, chr to)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationNeedsWAL(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)
void brincostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
void relation_close(Relation relation, LOCKMODE lockmode)
BlockNumber bs_pagesPerRange
Buffer bs_currentInsertBuf
BlockNumber bs_currRangeStart
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER]
BlockNumber lastRevmapPage
BlockNumber pagesPerRange
BlockNumber bo_pagesPerRange
TypeCacheEntry * oi_typcache[FLEXIBLE_ARRAY_MEMBER]
BlockNumber revmapNumPages
BlockNumber pagesPerRange
ambuildphasename_function ambuildphasename
ambuildempty_function ambuildempty
amvacuumcleanup_function amvacuumcleanup
amoptions_function amoptions
amestimateparallelscan_function amestimateparallelscan
amrestrpos_function amrestrpos
aminsert_function aminsert
amendscan_function amendscan
amparallelrescan_function amparallelrescan
amcostestimate_function amcostestimate
amadjustmembers_function amadjustmembers
amgettuple_function amgettuple
amcanreturn_function amcanreturn
amgetbitmap_function amgetbitmap
amproperty_function amproperty
ambulkdelete_function ambulkdelete
amvalidate_function amvalidate
ammarkpos_function ammarkpos
bool amusemaintenanceworkmem
ambeginscan_function ambeginscan
amrescan_function amrescan
aminitparallelscan_function aminitparallelscan
uint8 amparallelvacuumoptions
struct ScanKeyData * keyData
struct SnapshotData * xs_snapshot
BufferAccessStrategy strategy
BlockNumber pagesPerRange
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
static double table_index_build_range_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, bool allow_sync, bool anyvisible, bool progress, BlockNumber start_blockno, BlockNumber numblocks, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
static double table_index_build_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, bool allow_sync, bool progress, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
void tbm_add_page(TIDBitmap *tbm, BlockNumber pageno)
#define TupleDescAttr(tupdesc, i)
#define VACUUM_OPTION_PARALLEL_CLEANUP
bool RecoveryInProgress(void)
void XLogRegisterData(char *data, uint32 len)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std)
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
void XLogBeginInsert(void)