70 #define BRIN_ALL_BLOCKRANGES InvalidBlockNumber
76 bool include_partial,
double *numSummarized,
double *numExisting);
178 heapBlk = (origHeapBlk / pagesPerRange) * pagesPerRange;
182 bool need_insert =
false;
196 heapBlk == origHeapBlk &&
214 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
215 errmsg(
"request for BRIN range summarization for index \"%s\" page %u was not recorded",
295 buf, off, origtup, origsz, newtup, newsz,
439 nnullkeys = (
int *) ptr;
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,
699 for (pageno = heapBlk;
722 return totalpages * 10;
730 ScanKey orderbys,
int norderbys)
741 memmove(scan->
keyData, scankey,
784 while (thisblock >
state->bs_currRangeStart +
state->bs_pagesPerRange - 1)
788 "brinbuildCallback: completed a range: %u--%u",
789 state->bs_currRangeStart,
790 state->bs_currRangeStart +
state->bs_pagesPerRange));
796 state->bs_currRangeStart +=
state->bs_pagesPerRange;
825 elog(
ERROR,
"index \"%s\" already contains data",
879 idxtuples =
state->bs_numtuples;
1012 int save_sec_context;
1014 double numSummarized = 0;
1018 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1019 errmsg(
"recovery is in progress"),
1020 errhint(
"BRIN control functions cannot be executed during recovery.")));
1024 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1025 errmsg(
"block number out of range: %lld",
1026 (
long long) heapBlk64)));
1059 if (indexRel->
rd_rel->relkind != RELKIND_INDEX ||
1060 indexRel->
rd_rel->relam != BRIN_AM_OID)
1062 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1063 errmsg(
"\"%s\" is not a BRIN index",
1079 errmsg(
"could not open parent table of index \"%s\"",
1083 brinsummarize(indexRel, heapRel, heapBlk,
true, &numSummarized, NULL);
1113 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1114 errmsg(
"recovery is in progress"),
1115 errhint(
"BRIN control functions cannot be executed during recovery.")));
1119 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1120 errmsg(
"block number out of range: %lld",
1121 (
long long) heapBlk64)));
1142 if (indexRel->
rd_rel->relkind != RELKIND_INDEX ||
1143 indexRel->
rd_rel->relam != BRIN_AM_OID)
1145 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1146 errmsg(
"\"%s\" is not a BRIN index",
1162 errmsg(
"could not open parent table of index \"%s\"",
1187 int totalstored = 0;
1204 for (keyno = 0; keyno < tupdesc->
natts; keyno++)
1220 bdesc =
palloc(totalsize);
1227 for (keyno = 0; keyno < tupdesc->
natts; keyno++)
1228 bdesc->
bd_info[keyno] = opcinfo[keyno];
1277 state->bs_irel = idxRel;
1278 state->bs_numtuples = 0;
1280 state->bs_pagesPerRange = pagesPerRange;
1281 state->bs_currRangeStart = 0;
1282 state->bs_rmAccess = revmap;
1353 state->bs_rmAccess, &phbuf,
1354 heapBlk, phtup, phsz);
1361 if (heapBlk +
state->bs_pagesPerRange > heapNumBlks)
1375 state->bs_pagesPerRange);
1380 scanNumBlks =
state->bs_pagesPerRange;
1393 state->bs_currRangeStart = heapBlk;
1395 heapBlk, scanNumBlks,
1417 heapBlk,
state->bs_dtuple, &newsize);
1421 state->bs_rmAccess, heapBlk, phbuf, offset,
1422 phtup, phsz, newtup, newsize, samepage);
1442 elog(
ERROR,
"missing placeholder tuple");
1466 bool include_partial,
double *numSummarized,
double *numExisting)
1484 startBlk = (pageRange / pagesPerRange) * pagesPerRange;
1485 heapNumBlocks =
Min(heapNumBlocks, startBlk + pagesPerRange);
1487 if (startBlk > heapNumBlocks)
1498 for (; startBlk < heapNumBlocks; startBlk += pagesPerRange)
1510 if (!include_partial &&
1511 (startBlk + pagesPerRange > heapNumBlocks))
1535 *numSummarized += 1.0;
1540 *numExisting += 1.0;
1568 state->bs_dtuple, &size);
1570 &
state->bs_currentInsertBuf,
state->bs_currRangeStart,
1572 state->bs_numtuples++;
1667 for (blkno = 0; blkno < nblocks; blkno++)
1694 bool modified =
false;
1750 for (keyno = 0; keyno < nnullkeys; keyno++)
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
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)
#define BufferIsValid(bufnum)
#define BUFFER_LOCK_EXCLUSIVE
#define BufferGetPage(buffer)
Size PageGetFreeSpace(Page page)
#define PageGetItemId(page, offsetNumber)
#define PageSetLSN(page, lsn)
#define PageGetContents(page)
#define offsetof(type, field)
#define PG_USED_FOR_ASSERTS_ONLY
#define OidIsValid(objectId)
Datum datumCopy(Datum value, bool typByVal, int typLen)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
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)
#define ItemPointerGetBlockNumber(pointer)
#define ItemPointerGetOffsetNumber(pointer)
Assert(fmt[strlen(fmt) - 1] !='\n')
#define ShareUpdateExclusiveLock
void pfree(void *pointer)
void * palloc0(Size size)
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)
#define DatumGetPointer(X)
#define PointerGetDatum(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)
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)
void XLogRegisterData(char *data, int len)