32 #include "utils/fmgrprotos.h"
131 elog(
ERROR,
"index \"%s\" already contains data",
159 if (
index->rd_rel->relpersistence != RELPERSISTENCE_TEMP)
164 if (num_buckets >= (
uint32) sort_threshold)
167 buildstate.
spool = NULL;
176 (
void *) &buildstate, NULL);
180 if (buildstate.
spool)
219 Datum index_values[1];
220 bool index_isnull[1];
226 index_values, index_isnull))
230 if (buildstate->
spool)
231 _h_spool(buildstate->
spool, tid, index_values, index_isnull);
236 index_values, index_isnull);
258 Datum index_values[1];
259 bool index_isnull[1];
265 index_values, index_isnull))
270 itup->
t_tid = *ht_ctid;
399 ScanKey orderbys,
int norderbys)
463 double tuples_removed;
464 double num_index_tuples;
474 num_index_tuples = 0;
483 Assert(cachedmetap != NULL);
490 cur_maxbucket = orig_maxbucket;
493 while (cur_bucket <= cur_maxbucket)
501 bool split_cleanup =
false;
506 blkno = bucket_blkno;
527 split_cleanup =
true;
542 Assert(cachedmetap != NULL);
552 &num_index_tuples, split_cleanup,
573 Assert(cachedmetap != NULL);
687 double *tuples_removed,
double *num_index_tuples,
694 bool bucket_dirty =
false;
696 blkno = bucket_blkno;
713 bool retain_pin =
false;
714 bool clear_dead_marking =
false;
730 bool kill_tuple =
false;
734 htup = &(itup->
t_tid);
744 *tuples_removed += 1;
746 else if (split_cleanup)
754 if (bucket != cur_bucket)
762 Assert(bucket == new_bucket);
770 deletable[ndeletable++] = offno;
775 if (num_index_tuples)
776 *num_index_tuples += 1;
781 if (blkno == bucket_blkno)
804 if (tuples_removed && *tuples_removed > 0 &&
808 clear_dead_marking =
true;
873 if (
buf != bucket_buf)
void pgstat_progress_update_param(int index, int64 val)
#define InvalidBlockNumber
static bool BlockNumberIsValid(BlockNumber blockNumber)
static Datum values[MAXATTR]
#define BufferIsInvalid(buffer)
bool IsBufferCleanupOK(Buffer buffer)
void MarkBufferDirty(Buffer buffer)
void LockBufferForCleanup(Buffer buffer)
void LockBuffer(Buffer buffer, int mode)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
#define BUFFER_LOCK_UNLOCK
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
#define BUFFER_LOCK_EXCLUSIVE
void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
static Item PageGetItem(Page page, ItemId itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static void PageSetLSN(Page page, XLogRecPtr lsn)
static OffsetNumber PageGetMaxOffsetNumber(Page page)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
static void PGresult * res
#define PG_RETURN_POINTER(x)
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
bool hashinsert(Relation rel, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
IndexBulkDeleteResult * hashvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Datum hashhandler(PG_FUNCTION_ARGS)
IndexBulkDeleteResult * hashbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
bool hashgettuple(IndexScanDesc scan, ScanDirection dir)
static void hashbuildCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
void hashbuildempty(Relation index)
IndexScanDesc hashbeginscan(Relation rel, int nkeys, int norderbys)
void hashrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
void hashendscan(IndexScanDesc scan)
IndexBuildResult * hashbuild(Relation heap, Relation index, IndexInfo *indexInfo)
int64 hashgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
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 HashPageGetOpaque(page)
#define H_BUCKET_BEING_SPLIT(opaque)
#define HashScanPosInvalidate(scanpos)
#define HashPageGetMeta(page)
#define BUCKET_TO_BLKNO(metap, B)
#define H_HAS_DEAD_TUPLES(opaque)
#define H_NEEDS_SPLIT_CLEANUP(opaque)
#define LH_BUCKET_NEEDS_SPLIT_CLEANUP
HashScanOpaqueData * HashScanOpaque
#define HashScanPosIsValid(scanpos)
#define LH_PAGE_HAS_DEAD_TUPLES
#define XLOG_HASH_SPLIT_CLEANUP
#define XLOG_HASH_UPDATE_META_PAGE
#define SizeOfHashUpdateMetaPage
void _hash_doinsert(Relation rel, IndexTuple itup, Relation heapRel, bool sorted)
void _hash_squeezebucket(Relation rel, Bucket bucket, BlockNumber bucket_blkno, Buffer bucket_buf, BufferAccessStrategy bstrategy)
HashMetaPage _hash_getcachedmetap(Relation rel, Buffer *metabuf, bool force_refresh)
void _hash_relbuf(Relation rel, Buffer buf)
uint32 _hash_init(Relation rel, double num_tuples, ForkNumber forkNum)
void _hash_dropbuf(Relation rel, Buffer buf)
void _hash_dropscanbuf(Relation rel, HashScanOpaque so)
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Buffer _hash_getbuf_with_strategy(Relation rel, BlockNumber blkno, int access, int flags, BufferAccessStrategy bstrategy)
bool _hash_first(IndexScanDesc scan, ScanDirection dir)
bool _hash_next(IndexScanDesc scan, ScanDirection dir)
void _h_spool(HSpool *hspool, ItemPointer self, const Datum *values, const bool *isnull)
void _h_indexbuild(HSpool *hspool, Relation heapRel)
HSpool * _h_spoolinit(Relation heap, Relation index, uint32 num_buckets)
void _h_spooldestroy(HSpool *hspool)
uint32 _hash_get_indextuple_hashkey(IndexTuple itup)
Bucket _hash_hashkey2bucket(uint32 hashkey, uint32 maxbucket, uint32 highmask, uint32 lowmask)
void _hash_checkpage(Relation rel, Buffer buf, int flags)
Bucket _hash_get_newbucket_from_oldbucket(Relation rel, Bucket old_bucket, uint32 lowmask, uint32 maxbucket)
void _hash_kill_items(IndexScanDesc scan)
bytea * hashoptions(Datum reloptions, bool validate)
bool _hash_convert_tuple(Relation index, Datum *user_values, bool *user_isnull, Datum *index_values, bool *index_isnull)
void hashadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
bool hashvalidate(Oid opclassoid)
IndexTuple index_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
if(TABLE==NULL||TABLE_index==NULL)
IndexTupleData * IndexTuple
#define MaxIndexTuplesPerPage
void pfree(void *pointer)
void * palloc0(Size size)
#define START_CRIT_SECTION()
#define END_CRIT_SECTION()
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
void estimate_rel_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
#define PROGRESS_CREATEIDX_TUPLES_TOTAL
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationNeedsWAL(relation)
void hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
#define HTMaxStrategyNumber
BlockNumber hasho_nextblkno
BlockNumber hasho_prevblkno
bool hashso_buc_populated
Buffer hashso_split_bucket_buf
HashScanPosItem items[MaxIndexTuplesPerPage]
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
aminsertcleanup_function aminsertcleanup
amgettreeheight_function amgettreeheight
struct ScanKeyData * keyData
BufferAccessStrategy strategy
bool is_primary_bucket_page
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_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids, bool recheck)
void vacuum_delay_point(void)
#define VACUUM_OPTION_PARALLEL_BULKDEL
void XLogRegisterBufData(uint8 block_id, const char *data, uint32 len)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogRegisterData(const char *data, uint32 len)
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
void XLogBeginInsert(void)