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,
438 nnullkeys = (
int *) ptr;
457 for (
int keyno = 0; keyno < scan->
numberOfKeys; keyno++)
468 (
key->sk_collation ==
470 keyattno - 1)->attcollation));
482 if (consistentFn[keyattno - 1].fn_oid ==
InvalidOid)
487 Assert(nkeys[keyattno - 1] == 0);
488 Assert(nnullkeys[keyattno - 1] == 0);
499 nullkeys[keyattno - 1][nnullkeys[keyattno - 1]] =
key;
500 nnullkeys[keyattno - 1]++;
504 keys[keyattno - 1][nkeys[keyattno - 1]] =
key;
505 nkeys[keyattno - 1]++;
529 bool gottuple =
false;
588 if (nkeys[attno - 1] == 0 && nnullkeys[attno - 1] == 0)
614 nnullkeys[attno - 1]))
634 if (!nkeys[attno - 1])
637 Assert((nkeys[attno - 1] > 0) &&
664 if (consistentFn[attno - 1].fn_nargs >= 4)
687 for (keyno = 0; keyno < nkeys[attno - 1]; keyno++)
690 keys[attno - 1][keyno]->sk_collation,
715 for (pageno = heapBlk;
738 return totalpages * 10;
746 ScanKey orderbys,
int norderbys)
757 memmove(scan->
keyData, scankey,
800 while (thisblock >
state->bs_currRangeStart +
state->bs_pagesPerRange - 1)
804 "brinbuildCallback: completed a range: %u--%u",
805 state->bs_currRangeStart,
806 state->bs_currRangeStart +
state->bs_pagesPerRange));
812 state->bs_currRangeStart +=
state->bs_pagesPerRange;
841 elog(
ERROR,
"index \"%s\" already contains data",
895 idxtuples =
state->bs_numtuples;
1027 int save_sec_context;
1029 double numSummarized = 0;
1033 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1034 errmsg(
"recovery is in progress"),
1035 errhint(
"BRIN control functions cannot be executed during recovery.")));
1039 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1040 errmsg(
"block number out of range: %lld",
1041 (
long long) heapBlk64)));
1073 save_sec_context = -1;
1074 save_nestlevel = -1;
1080 if (indexRel->
rd_rel->relkind != RELKIND_INDEX ||
1081 indexRel->
rd_rel->relam != BRIN_AM_OID)
1083 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1084 errmsg(
"\"%s\" is not a BRIN index",
1088 if (heapRel != NULL && !
object_ownercheck(RelationRelationId, indexoid, save_userid))
1100 errmsg(
"could not open parent table of index \"%s\"",
1104 brinsummarize(indexRel, heapRel, heapBlk,
true, &numSummarized, NULL);
1134 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1135 errmsg(
"recovery is in progress"),
1136 errhint(
"BRIN control functions cannot be executed during recovery.")));
1140 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1141 errmsg(
"block number out of range: %lld",
1142 (
long long) heapBlk64)));
1163 if (indexRel->
rd_rel->relkind != RELKIND_INDEX ||
1164 indexRel->
rd_rel->relam != BRIN_AM_OID)
1166 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1167 errmsg(
"\"%s\" is not a BRIN index",
1183 errmsg(
"could not open parent table of index \"%s\"",
1208 int totalstored = 0;
1225 for (keyno = 0; keyno < tupdesc->
natts; keyno++)
1238 totalsize = offsetof(
BrinDesc, bd_info) +
1241 bdesc =
palloc(totalsize);
1248 for (keyno = 0; keyno < tupdesc->
natts; keyno++)
1249 bdesc->
bd_info[keyno] = opcinfo[keyno];
1298 state->bs_irel = idxRel;
1299 state->bs_numtuples = 0;
1301 state->bs_pagesPerRange = pagesPerRange;
1302 state->bs_currRangeStart = 0;
1303 state->bs_rmAccess = revmap;
1374 state->bs_rmAccess, &phbuf,
1375 heapBlk, phtup, phsz);
1382 if (heapBlk +
state->bs_pagesPerRange > heapNumBlks)
1396 state->bs_pagesPerRange);
1401 scanNumBlks =
state->bs_pagesPerRange;
1414 state->bs_currRangeStart = heapBlk;
1416 heapBlk, scanNumBlks,
1438 heapBlk,
state->bs_dtuple, &newsize);
1442 state->bs_rmAccess, heapBlk, phbuf, offset,
1443 phtup, phsz, newtup, newsize, samepage);
1462 elog(
ERROR,
"missing placeholder tuple");
1486 bool include_partial,
double *numSummarized,
double *numExisting)
1504 startBlk = (pageRange / pagesPerRange) * pagesPerRange;
1505 heapNumBlocks =
Min(heapNumBlocks, startBlk + pagesPerRange);
1507 if (startBlk > heapNumBlocks)
1518 for (; startBlk < heapNumBlocks; startBlk += pagesPerRange)
1530 if (!include_partial &&
1531 (startBlk + pagesPerRange > heapNumBlocks))
1555 *numSummarized += 1.0;
1560 *numExisting += 1.0;
1588 state->bs_dtuple, &size);
1590 &
state->bs_currentInsertBuf,
state->bs_currRangeStart,
1592 state->bs_numtuples++;
1643 if (
a->bt_empty_range)
1667 a->bt_empty_range =
false;
1753 for (blkno = 0; blkno < nblocks; blkno++)
1878 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)
void brinRevmapTerminate(BrinRevmap *revmap)
BrinTuple * brinGetTupleForHeapBlock(BrinRevmap *revmap, BlockNumber heapBlk, Buffer *buf, OffsetNumber *off, Size *size, int mode)
BrinRevmap * brinRevmapInitialize(Relation idxrel, BlockNumber *pagesPerRange)
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)
Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)
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)
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
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)