126 elog(
ERROR,
"index \"%s\" already contains data",
154 if (index->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
159 if (num_buckets >= (
uint32) sort_threshold)
162 buildstate.
spool = NULL;
171 (
void *) &buildstate, NULL);
173 buildstate.indtuples);
175 if (buildstate.spool)
214 Datum index_values[1];
215 bool index_isnull[1];
221 index_values, index_isnull))
225 if (buildstate->
spool)
226 _h_spool(buildstate->
spool, tid, index_values, index_isnull);
231 index_values, index_isnull);
253 Datum index_values[1];
254 bool index_isnull[1];
260 index_values, index_isnull))
265 itup->
t_tid = *ht_ctid;
394 ScanKey orderbys,
int norderbys)
462 double tuples_removed;
463 double num_index_tuples;
473 num_index_tuples = 0;
482 Assert(cachedmetap != NULL);
489 cur_maxbucket = orig_maxbucket;
492 while (cur_bucket <= cur_maxbucket)
500 bool split_cleanup =
false;
505 blkno = bucket_blkno;
526 split_cleanup =
true;
541 Assert(cachedmetap != NULL);
551 &num_index_tuples, split_cleanup,
552 callback, callback_state);
572 Assert(cachedmetap != NULL);
686 double *tuples_removed,
double *num_index_tuples,
693 bool bucket_dirty =
false;
695 blkno = bucket_blkno;
712 bool retain_pin =
false;
713 bool clear_dead_marking =
false;
729 bool kill_tuple =
false;
733 htup = &(itup->
t_tid);
739 if (callback &&
callback(htup, callback_state))
743 *tuples_removed += 1;
745 else if (split_cleanup)
753 if (bucket != cur_bucket)
761 Assert(bucket == new_bucket);
769 deletable[ndeletable++] = offno;
774 if (num_index_tuples)
775 *num_index_tuples += 1;
780 if (blkno == bucket_blkno)
803 if (tuples_removed && *tuples_removed > 0 &&
807 clear_dead_marking =
true;
828 if (!xlrec.is_primary_bucket_page)
867 if (buf != bucket_buf)
ambeginscan_function ambeginscan
void XLogRegisterBufData(uint8 block_id, char *data, int len)
uint8 amparallelvacuumoptions
bytea * hashoptions(Datum reloptions, bool validate)
#define PG_RETURN_POINTER(x)
HashScanOpaqueData * HashScanOpaque
#define BUFFER_LOCK_UNLOCK
void LockBufferForCleanup(Buffer buffer)
ambulkdelete_function ambulkdelete
bool hashgettuple(IndexScanDesc scan, ScanDirection dir)
void _hash_doinsert(Relation rel, IndexTuple itup, Relation heapRel)
#define HTMaxStrategyNumber
void _hash_dropscanbuf(Relation rel, HashScanOpaque so)
amgettuple_function amgettuple
#define RelationGetDescr(relation)
Bucket _hash_hashkey2bucket(uint32 hashkey, uint32 maxbucket, uint32 highmask, uint32 lowmask)
IndexBulkDeleteResult * hashbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
amproperty_function amproperty
void MarkBufferDirty(Buffer buffer)
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
#define HashScanPosIsValid(scanpos)
Buffer _hash_getbuf_with_strategy(Relation rel, BlockNumber blkno, int access, int flags, BufferAccessStrategy bstrategy)
void pgstat_progress_update_param(int index, int64 val)
void tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids, bool recheck)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
amparallelrescan_function amparallelrescan
#define END_CRIT_SECTION()
BufferAccessStrategy strategy
void hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
#define START_CRIT_SECTION()
#define XLOG_HASH_SPLIT_CLEANUP
void hashbucketcleanup(Relation rel, Bucket cur_bucket, Buffer bucket_buf, BlockNumber bucket_blkno, BufferAccessStrategy bstrategy, uint32 maxbucket, uint32 highmask, uint32 lowmask, double *tuples_removed, double *num_index_tuples, bool split_cleanup, IndexBulkDeleteCallback callback, void *callback_state)
#define PROGRESS_CREATEIDX_TUPLES_TOTAL
IndexScanDesc hashbeginscan(Relation rel, int nkeys, int norderbys)
aminsert_function aminsert
void _hash_dropbuf(Relation rel, Buffer buf)
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
#define BUFFER_LOCK_EXCLUSIVE
#define LH_BUCKET_NEEDS_SPLIT_CLEANUP
#define PageGetMaxOffsetNumber(page)
amvalidate_function amvalidate
void hashbuildempty(Relation index)
#define BUCKET_TO_BLKNO(metap, B)
IndexTuple index_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
void pfree(void *pointer)
amgetbitmap_function amgetbitmap
#define H_NEEDS_SPLIT_CLEANUP(opaque)
BlockNumber hasho_prevblkno
uint32 _hash_get_indextuple_hashkey(IndexTuple itup)
bool _hash_first(IndexScanDesc scan, ScanDirection dir)
amoptions_function amoptions
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)
IndexBuildResult * hashbuild(Relation heap, Relation index, IndexInfo *indexInfo)
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
bool _hash_convert_tuple(Relation index, Datum *user_values, bool *user_isnull, Datum *index_values, bool *index_isnull)
amcostestimate_function amcostestimate
bool is_primary_bucket_page
bool _hash_next(IndexScanDesc scan, ScanDirection dir)
#define BufferIsInvalid(buffer)
amvacuumcleanup_function amvacuumcleanup
amendscan_function amendscan
#define FirstOffsetNumber
IndexTupleData * IndexTuple
Bucket _hash_get_newbucket_from_oldbucket(Relation rel, Bucket old_bucket, uint32 lowmask, uint32 maxbucket)
void _h_spool(HSpool *hspool, ItemPointer self, Datum *values, bool *isnull)
void _h_indexbuild(HSpool *hspool, Relation heapRel)
#define RelationGetRelationName(relation)
void estimate_rel_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
#define BufferGetPage(buffer)
amrescan_function amrescan
int64 hashgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
bool IsBufferCleanupOK(Buffer buffer)
#define SizeOfHashUpdateMetaPage
#define PageGetItemId(page, offsetNumber)
void XLogRegisterData(char *data, int len)
void hashendscan(IndexScanDesc scan)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void _hash_checkpage(Relation rel, Buffer buf, int flags)
void * palloc0(Size size)
#define HashScanPosInvalidate(scanpos)
bool hashso_buc_populated
void LockBuffer(Buffer buffer, int mode)
#define RelationGetNumberOfBlocks(reln)
HashMetaPage _hash_getcachedmetap(Relation rel, Buffer *metabuf, bool force_refresh)
void _hash_relbuf(Relation rel, Buffer buf)
bool amusemaintenanceworkmem
#define BlockNumberIsValid(blockNumber)
IndexBulkDeleteResult * hashvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
#define H_BUCKET_BEING_SPLIT(opaque)
Datum hashhandler(PG_FUNCTION_ARGS)
amadjustmembers_function amadjustmembers
#define Assert(condition)
void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
#define OffsetNumberNext(offsetNumber)
#define PageGetSpecialPointer(page)
#define InvalidBlockNumber
HashPageOpaqueData * HashPageOpaque
void _hash_kill_items(IndexScanDesc scan)
void _hash_squeezebucket(Relation rel, Bucket bucket, BlockNumber bucket_blkno, Buffer bucket_buf, BufferAccessStrategy bstrategy)
ammarkpos_function ammarkpos
ambuildphasename_function ambuildphasename
#define VACUUM_OPTION_PARALLEL_BULKDEL
#define RelationNeedsWAL(relation)
amestimateparallelscan_function amestimateparallelscan
struct ScanKeyData * keyData
uint32 _hash_init(Relation rel, double num_tuples, ForkNumber forkNum)
bool hashvalidate(Oid opclassoid)
static Datum values[MAXATTR]
void _h_spooldestroy(HSpool *hspool)
#define MaxIndexTuplesPerPage
#define HashPageGetMeta(page)
void hashadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
ambuildempty_function ambuildempty
Buffer hashso_split_bucket_buf
bool hashinsert(Relation rel, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
BlockNumber hasho_nextblkno
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
static void hashbuildCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
HSpool * _h_spoolinit(Relation heap, Relation index, uint32 num_buckets)
void vacuum_delay_point(void)
void XLogBeginInsert(void)
#define XLOG_HASH_UPDATE_META_PAGE
#define PageSetLSN(page, lsn)
amcanreturn_function amcanreturn
#define H_HAS_DEAD_TUPLES(opaque)
void hashrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
#define LH_PAGE_HAS_DEAD_TUPLES
#define PageGetItem(page, itemId)
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
aminitparallelscan_function aminitparallelscan
HashScanPosItem items[MaxIndexTuplesPerPage]
#define PG_USED_FOR_ASSERTS_ONLY
amrestrpos_function amrestrpos