PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hash.c File Reference
#include "postgres.h"
#include "access/hash.h"
#include "access/hash_xlog.h"
#include "access/relscan.h"
#include "access/stratnum.h"
#include "access/tableam.h"
#include "access/xloginsert.h"
#include "commands/progress.h"
#include "commands/vacuum.h"
#include "miscadmin.h"
#include "nodes/execnodes.h"
#include "optimizer/plancat.h"
#include "pgstat.h"
#include "utils/fmgrprotos.h"
#include "utils/index_selfuncs.h"
#include "utils/rel.h"
Include dependency graph for hash.c:

Go to the source code of this file.

Data Structures

struct  HashBuildState
 

Functions

static void hashbuildCallback (Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
 
Datum hashhandler (PG_FUNCTION_ARGS)
 
IndexBuildResulthashbuild (Relation heap, Relation index, IndexInfo *indexInfo)
 
void hashbuildempty (Relation index)
 
bool hashinsert (Relation rel, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
 
bool hashgettuple (IndexScanDesc scan, ScanDirection dir)
 
int64 hashgetbitmap (IndexScanDesc scan, TIDBitmap *tbm)
 
IndexScanDesc hashbeginscan (Relation rel, int nkeys, int norderbys)
 
void hashrescan (IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
 
void hashendscan (IndexScanDesc scan)
 
IndexBulkDeleteResulthashbulkdelete (IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
 
IndexBulkDeleteResulthashvacuumcleanup (IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
 
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)
 
CompareType hashtranslatestrategy (StrategyNumber strategy, Oid opfamily)
 
StrategyNumber hashtranslatecmptype (CompareType cmptype, Oid opfamily)
 

Function Documentation

◆ hashbeginscan()

IndexScanDesc hashbeginscan ( Relation  rel,
int  nkeys,
int  norderbys 
)

Definition at line 374 of file hash.c.

375{
376 IndexScanDesc scan;
378
379 /* no order by operators allowed */
380 Assert(norderbys == 0);
381
382 scan = RelationGetIndexScan(rel, nkeys, norderbys);
383
388
389 so->hashso_buc_populated = false;
390 so->hashso_buc_split = false;
391
392 so->killedItems = NULL;
393 so->numKilled = 0;
394
395 scan->opaque = so;
396
397 return scan;
398}
#define InvalidBuffer
Definition: buf.h:25
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
Definition: genam.c:80
#define HashScanPosInvalidate(scanpos)
Definition: hash.h:144
HashScanOpaqueData * HashScanOpaque
Definition: hash.h:192
Assert(PointerIsAligned(start, uint64))
void * palloc(Size size)
Definition: mcxt.c:1943
bool hashso_buc_split
Definition: hash.h:180
HashScanPosData currPos
Definition: hash.h:189
bool hashso_buc_populated
Definition: hash.h:174
Buffer hashso_split_bucket_buf
Definition: hash.h:171
Buffer hashso_bucket_buf
Definition: hash.h:164
int * killedItems
Definition: hash.h:182

References Assert(), HashScanOpaqueData::currPos, HashScanPosInvalidate, HashScanOpaqueData::hashso_buc_populated, HashScanOpaqueData::hashso_buc_split, HashScanOpaqueData::hashso_bucket_buf, HashScanOpaqueData::hashso_split_bucket_buf, InvalidBuffer, HashScanOpaqueData::killedItems, HashScanOpaqueData::numKilled, IndexScanDescData::opaque, palloc(), and RelationGetIndexScan().

Referenced by hashhandler().

◆ hashbucketcleanup()

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 
)

Definition at line 690 of file hash.c.

696{
697 BlockNumber blkno;
698 Buffer buf;
700 bool bucket_dirty = false;
701
702 blkno = bucket_blkno;
703 buf = bucket_buf;
704
705 if (split_cleanup)
706 new_bucket = _hash_get_newbucket_from_oldbucket(rel, cur_bucket,
707 lowmask, maxbucket);
708
709 /* Scan each page in bucket */
710 for (;;)
711 {
712 HashPageOpaque opaque;
713 OffsetNumber offno;
714 OffsetNumber maxoffno;
715 Buffer next_buf;
716 Page page;
717 OffsetNumber deletable[MaxOffsetNumber];
718 int ndeletable = 0;
719 bool retain_pin = false;
720 bool clear_dead_marking = false;
721
722 vacuum_delay_point(false);
723
724 page = BufferGetPage(buf);
725 opaque = HashPageGetOpaque(page);
726
727 /* Scan each tuple in page */
728 maxoffno = PageGetMaxOffsetNumber(page);
729 for (offno = FirstOffsetNumber;
730 offno <= maxoffno;
731 offno = OffsetNumberNext(offno))
732 {
733 ItemPointer htup;
734 IndexTuple itup;
735 Bucket bucket;
736 bool kill_tuple = false;
737
738 itup = (IndexTuple) PageGetItem(page,
739 PageGetItemId(page, offno));
740 htup = &(itup->t_tid);
741
742 /*
743 * To remove the dead tuples, we strictly want to rely on results
744 * of callback function. refer btvacuumpage for detailed reason.
745 */
746 if (callback && callback(htup, callback_state))
747 {
748 kill_tuple = true;
749 if (tuples_removed)
750 *tuples_removed += 1;
751 }
752 else if (split_cleanup)
753 {
754 /* delete the tuples that are moved by split. */
756 maxbucket,
757 highmask,
758 lowmask);
759 /* mark the item for deletion */
760 if (bucket != cur_bucket)
761 {
762 /*
763 * We expect tuples to either belong to current bucket or
764 * new_bucket. This is ensured because we don't allow
765 * further splits from bucket that contains garbage. See
766 * comments in _hash_expandtable.
767 */
768 Assert(bucket == new_bucket);
769 kill_tuple = true;
770 }
771 }
772
773 if (kill_tuple)
774 {
775 /* mark the item for deletion */
776 deletable[ndeletable++] = offno;
777 }
778 else
779 {
780 /* we're keeping it, so count it */
781 if (num_index_tuples)
782 *num_index_tuples += 1;
783 }
784 }
785
786 /* retain the pin on primary bucket page till end of bucket scan */
787 if (blkno == bucket_blkno)
788 retain_pin = true;
789 else
790 retain_pin = false;
791
792 blkno = opaque->hasho_nextblkno;
793
794 /*
795 * Apply deletions, advance to next page and write page if needed.
796 */
797 if (ndeletable > 0)
798 {
799 /* No ereport(ERROR) until changes are logged */
801
802 PageIndexMultiDelete(page, deletable, ndeletable);
803 bucket_dirty = true;
804
805 /*
806 * Let us mark the page as clean if vacuum removes the DEAD tuples
807 * from an index page. We do this by clearing
808 * LH_PAGE_HAS_DEAD_TUPLES flag.
809 */
810 if (tuples_removed && *tuples_removed > 0 &&
811 H_HAS_DEAD_TUPLES(opaque))
812 {
813 opaque->hasho_flag &= ~LH_PAGE_HAS_DEAD_TUPLES;
814 clear_dead_marking = true;
815 }
816
818
819 /* XLOG stuff */
820 if (RelationNeedsWAL(rel))
821 {
822 xl_hash_delete xlrec;
823 XLogRecPtr recptr;
824
825 xlrec.clear_dead_marking = clear_dead_marking;
826 xlrec.is_primary_bucket_page = (buf == bucket_buf);
827
830
831 /*
832 * bucket buffer was not changed, but still needs to be
833 * registered to ensure that we can acquire a cleanup lock on
834 * it during replay.
835 */
836 if (!xlrec.is_primary_bucket_page)
837 {
839
840 XLogRegisterBuffer(0, bucket_buf, flags);
841 }
842
844 XLogRegisterBufData(1, deletable,
845 ndeletable * sizeof(OffsetNumber));
846
847 recptr = XLogInsert(RM_HASH_ID, XLOG_HASH_DELETE);
848 PageSetLSN(BufferGetPage(buf), recptr);
849 }
850
852 }
853
854 /* bail out if there are no more pages to scan. */
855 if (!BlockNumberIsValid(blkno))
856 break;
857
858 next_buf = _hash_getbuf_with_strategy(rel, blkno, HASH_WRITE,
860 bstrategy);
861
862 /*
863 * release the lock on previous page after acquiring the lock on next
864 * page
865 */
866 if (retain_pin)
868 else
869 _hash_relbuf(rel, buf);
870
871 buf = next_buf;
872 }
873
874 /*
875 * lock the bucket page to clear the garbage flag and squeeze the bucket.
876 * if the current buffer is same as bucket buffer, then we already have
877 * lock on bucket page.
878 */
879 if (buf != bucket_buf)
880 {
881 _hash_relbuf(rel, buf);
883 }
884
885 /*
886 * Clear the garbage flag from bucket after deleting the tuples that are
887 * moved by split. We purposefully clear the flag before squeeze bucket,
888 * so that after restart, vacuum shouldn't again try to delete the moved
889 * by split tuples.
890 */
891 if (split_cleanup)
892 {
893 HashPageOpaque bucket_opaque;
894 Page page;
895
896 page = BufferGetPage(bucket_buf);
897 bucket_opaque = HashPageGetOpaque(page);
898
899 /* No ereport(ERROR) until changes are logged */
901
902 bucket_opaque->hasho_flag &= ~LH_BUCKET_NEEDS_SPLIT_CLEANUP;
903 MarkBufferDirty(bucket_buf);
904
905 /* XLOG stuff */
906 if (RelationNeedsWAL(rel))
907 {
908 XLogRecPtr recptr;
909
911 XLogRegisterBuffer(0, bucket_buf, REGBUF_STANDARD);
912
913 recptr = XLogInsert(RM_HASH_ID, XLOG_HASH_SPLIT_CLEANUP);
914 PageSetLSN(page, recptr);
915 }
916
918 }
919
920 /*
921 * If we have deleted anything, try to compact free space. For squeezing
922 * the bucket, we must have a cleanup lock, else it can impact the
923 * ordering of tuples for a scan that has started before it.
924 */
925 if (bucket_dirty && IsBufferCleanupOK(bucket_buf))
926 _hash_squeezebucket(rel, cur_bucket, bucket_blkno, bucket_buf,
927 bstrategy);
928 else
929 LockBuffer(bucket_buf, BUFFER_LOCK_UNLOCK);
930}
uint32 BlockNumber
Definition: block.h:31
static bool BlockNumberIsValid(BlockNumber blockNumber)
Definition: block.h:71
int Buffer
Definition: buf.h:23
bool IsBufferCleanupOK(Buffer buffer)
Definition: bufmgr.c:5913
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:2952
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:5607
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:196
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:417
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:198
void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
Definition: bufpage.c:1160
static Item PageGetItem(const PageData *page, const ItemIdData *itemId)
Definition: bufpage.h:354
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:244
static void PageSetLSN(Page page, XLogRecPtr lsn)
Definition: bufpage.h:391
PageData * Page
Definition: bufpage.h:82
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
Definition: bufpage.h:372
uint8_t uint8
Definition: c.h:500
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:224
#define HashPageGetOpaque(page)
Definition: hash.h:88
#define HASH_WRITE
Definition: hash.h:340
#define H_HAS_DEAD_TUPLES(opaque)
Definition: hash.h:93
uint32 Bucket
Definition: hash.h:35
#define LH_OVERFLOW_PAGE
Definition: hash.h:54
#define InvalidBucket
Definition: hash.h:37
#define XLOG_HASH_SPLIT_CLEANUP
Definition: hash_xlog.h:37
#define SizeOfHashDelete
Definition: hash_xlog.h:186
#define XLOG_HASH_DELETE
Definition: hash_xlog.h:36
void _hash_squeezebucket(Relation rel, Bucket bucket, BlockNumber bucket_blkno, Buffer bucket_buf, BufferAccessStrategy bstrategy)
Definition: hashovfl.c:842
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:266
Buffer _hash_getbuf_with_strategy(Relation rel, BlockNumber blkno, int access, int flags, BufferAccessStrategy bstrategy)
Definition: hashpage.c:239
uint32 _hash_get_indextuple_hashkey(IndexTuple itup)
Definition: hashutil.c:291
Bucket _hash_hashkey2bucket(uint32 hashkey, uint32 maxbucket, uint32 highmask, uint32 lowmask)
Definition: hashutil.c:125
Bucket _hash_get_newbucket_from_oldbucket(Relation rel, Bucket old_bucket, uint32 lowmask, uint32 maxbucket)
Definition: hashutil.c:494
IndexTupleData * IndexTuple
Definition: itup.h:53
#define START_CRIT_SECTION()
Definition: miscadmin.h:150
#define END_CRIT_SECTION()
Definition: miscadmin.h:152
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
#define MaxOffsetNumber
Definition: off.h:28
static char * buf
Definition: pg_test_fsync.c:72
#define RelationNeedsWAL(relation)
Definition: rel.h:639
BlockNumber hasho_nextblkno
Definition: hash.h:80
uint16 hasho_flag
Definition: hash.h:82
ItemPointerData t_tid
Definition: itup.h:37
bool clear_dead_marking
Definition: hash_xlog.h:180
bool is_primary_bucket_page
Definition: hash_xlog.h:182
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
void vacuum_delay_point(bool is_analyze)
Definition: vacuum.c:2404
uint64 XLogRecPtr
Definition: xlogdefs.h:21
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:474
void XLogRegisterBufData(uint8 block_id, const void *data, uint32 len)
Definition: xloginsert.c:405
void XLogRegisterData(const void *data, uint32 len)
Definition: xloginsert.c:364
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:242
void XLogBeginInsert(void)
Definition: xloginsert.c:149
#define REGBUF_NO_CHANGE
Definition: xloginsert.h:37
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define REGBUF_NO_IMAGE
Definition: xloginsert.h:33

References _hash_get_indextuple_hashkey(), _hash_get_newbucket_from_oldbucket(), _hash_getbuf_with_strategy(), _hash_hashkey2bucket(), _hash_relbuf(), _hash_squeezebucket(), Assert(), BlockNumberIsValid(), buf, BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_UNLOCK, BufferGetPage(), callback(), xl_hash_delete::clear_dead_marking, END_CRIT_SECTION, FirstOffsetNumber, H_HAS_DEAD_TUPLES, HASH_WRITE, HashPageOpaqueData::hasho_flag, HashPageOpaqueData::hasho_nextblkno, HashPageGetOpaque, InvalidBucket, xl_hash_delete::is_primary_bucket_page, IsBufferCleanupOK(), LH_OVERFLOW_PAGE, LockBuffer(), MarkBufferDirty(), MaxOffsetNumber, OffsetNumberNext, PageGetItem(), PageGetItemId(), PageGetMaxOffsetNumber(), PageIndexMultiDelete(), PageSetLSN(), PG_USED_FOR_ASSERTS_ONLY, REGBUF_NO_CHANGE, REGBUF_NO_IMAGE, REGBUF_STANDARD, RelationNeedsWAL, SizeOfHashDelete, START_CRIT_SECTION, IndexTupleData::t_tid, vacuum_delay_point(), XLOG_HASH_DELETE, XLOG_HASH_SPLIT_CLEANUP, XLogBeginInsert(), XLogInsert(), XLogRegisterBufData(), XLogRegisterBuffer(), and XLogRegisterData().

Referenced by _hash_expandtable(), _hash_splitbucket(), and hashbulkdelete().

◆ hashbuild()

IndexBuildResult * hashbuild ( Relation  heap,
Relation  index,
IndexInfo indexInfo 
)

Definition at line 122 of file hash.c.

123{
124 IndexBuildResult *result;
125 BlockNumber relpages;
126 double reltuples;
127 double allvisfrac;
128 uint32 num_buckets;
129 Size sort_threshold;
130 HashBuildState buildstate;
131
132 /*
133 * We expect to be called exactly once for any index relation. If that's
134 * not the case, big trouble's what we have.
135 */
137 elog(ERROR, "index \"%s\" already contains data",
139
140 /* Estimate the number of rows currently present in the table */
141 estimate_rel_size(heap, NULL, &relpages, &reltuples, &allvisfrac);
142
143 /* Initialize the hash index metadata page and initial buckets */
144 num_buckets = _hash_init(index, reltuples, MAIN_FORKNUM);
145
146 /*
147 * If we just insert the tuples into the index in scan order, then
148 * (assuming their hash codes are pretty random) there will be no locality
149 * of access to the index, and if the index is bigger than available RAM
150 * then we'll thrash horribly. To prevent that scenario, we can sort the
151 * tuples by (expected) bucket number. However, such a sort is useless
152 * overhead when the index does fit in RAM. We choose to sort if the
153 * initial index size exceeds maintenance_work_mem, or the number of
154 * buffers usable for the index, whichever is less. (Limiting by the
155 * number of buffers should reduce thrashing between PG buffers and kernel
156 * buffers, which seems useful even if no physical I/O results. Limiting
157 * by maintenance_work_mem is useful to allow easy testing of the sort
158 * code path, and may be useful to DBAs as an additional control knob.)
159 *
160 * NOTE: this test will need adjustment if a bucket is ever different from
161 * one page. Also, "initial index size" accounting does not include the
162 * metapage, nor the first bitmap page.
163 */
164 sort_threshold = (maintenance_work_mem * (Size) 1024) / BLCKSZ;
165 if (index->rd_rel->relpersistence != RELPERSISTENCE_TEMP)
166 sort_threshold = Min(sort_threshold, NBuffers);
167 else
168 sort_threshold = Min(sort_threshold, NLocBuffer);
169
170 if (num_buckets >= sort_threshold)
171 buildstate.spool = _h_spoolinit(heap, index, num_buckets);
172 else
173 buildstate.spool = NULL;
174
175 /* prepare to build the index */
176 buildstate.indtuples = 0;
177 buildstate.heapRel = heap;
178
179 /* do the heap scan */
180 reltuples = table_index_build_scan(heap, index, indexInfo, true, true,
182 &buildstate, NULL);
184 buildstate.indtuples);
185
186 if (buildstate.spool)
187 {
188 /* sort the tuples and insert them into the index */
189 _h_indexbuild(buildstate.spool, buildstate.heapRel);
190 _h_spooldestroy(buildstate.spool);
191 }
192
193 /*
194 * Return statistics
195 */
196 result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
197
198 result->heap_tuples = reltuples;
199 result->index_tuples = buildstate.indtuples;
200
201 return result;
202}
void pgstat_progress_update_param(int index, int64 val)
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:283
#define Min(x, y)
Definition: c.h:975
uint32_t uint32
Definition: c.h:502
size_t Size
Definition: c.h:576
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
int NBuffers
Definition: globals.c:143
int maintenance_work_mem
Definition: globals.c:134
static void hashbuildCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
Definition: hash.c:217
uint32 _hash_init(Relation rel, double num_tuples, ForkNumber forkNum)
Definition: hashpage.c:327
void _h_indexbuild(HSpool *hspool, Relation heapRel)
Definition: hashsort.c:120
HSpool * _h_spoolinit(Relation heap, Relation index, uint32 num_buckets)
Definition: hashsort.c:60
void _h_spooldestroy(HSpool *hspool)
Definition: hashsort.c:99
int NLocBuffer
Definition: localbuf.c:44
void estimate_rel_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: plancat.c:1069
#define PROGRESS_CREATEIDX_TUPLES_TOTAL
Definition: progress.h:89
#define RelationGetRelationName(relation)
Definition: rel.h:550
@ MAIN_FORKNUM
Definition: relpath.h:58
HSpool * spool
Definition: hash.c:40
Relation heapRel
Definition: hash.c:42
double indtuples
Definition: hash.c:41
double heap_tuples
Definition: genam.h:55
double index_tuples
Definition: genam.h:56
Definition: type.h:96
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)
Definition: tableam.h:1735

References _h_indexbuild(), _h_spooldestroy(), _h_spoolinit(), _hash_init(), elog, ERROR, estimate_rel_size(), hashbuildCallback(), IndexBuildResult::heap_tuples, HashBuildState::heapRel, IndexBuildResult::index_tuples, HashBuildState::indtuples, MAIN_FORKNUM, maintenance_work_mem, Min, NBuffers, NLocBuffer, palloc(), pgstat_progress_update_param(), PROGRESS_CREATEIDX_TUPLES_TOTAL, RelationGetNumberOfBlocks, RelationGetRelationName, HashBuildState::spool, and table_index_build_scan().

Referenced by hashhandler().

◆ hashbuildCallback()

static void hashbuildCallback ( Relation  index,
ItemPointer  tid,
Datum values,
bool *  isnull,
bool  tupleIsAlive,
void *  state 
)
static

Definition at line 217 of file hash.c.

223{
224 HashBuildState *buildstate = (HashBuildState *) state;
225 Datum index_values[1];
226 bool index_isnull[1];
227 IndexTuple itup;
228
229 /* convert data to a hash key; on failure, do not insert anything */
231 values, isnull,
232 index_values, index_isnull))
233 return;
234
235 /* Either spool the tuple for sorting, or just put it into the index */
236 if (buildstate->spool)
237 _h_spool(buildstate->spool, tid, index_values, index_isnull);
238 else
239 {
240 /* form an index tuple and point it at the heap tuple */
242 index_values, index_isnull);
243 itup->t_tid = *tid;
244 _hash_doinsert(index, itup, buildstate->heapRel, false);
245 pfree(itup);
246 }
247
248 buildstate->indtuples += 1;
249}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
void _hash_doinsert(Relation rel, IndexTuple itup, Relation heapRel, bool sorted)
Definition: hashinsert.c:38
void _h_spool(HSpool *hspool, ItemPointer self, const Datum *values, const bool *isnull)
Definition: hashsort.c:109
bool _hash_convert_tuple(Relation index, Datum *user_values, bool *user_isnull, Datum *index_values, bool *index_isnull)
Definition: hashutil.c:318
IndexTuple index_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: indextuple.c:44
void pfree(void *pointer)
Definition: mcxt.c:2150
uintptr_t Datum
Definition: postgres.h:69
#define RelationGetDescr(relation)
Definition: rel.h:542
Definition: regguts.h:323

References _h_spool(), _hash_convert_tuple(), _hash_doinsert(), HashBuildState::heapRel, index_form_tuple(), HashBuildState::indtuples, pfree(), RelationGetDescr, HashBuildState::spool, IndexTupleData::t_tid, and values.

Referenced by hashbuild().

◆ hashbuildempty()

void hashbuildempty ( Relation  index)

Definition at line 208 of file hash.c.

209{
211}
@ INIT_FORKNUM
Definition: relpath.h:61

References _hash_init(), and INIT_FORKNUM.

Referenced by hashhandler().

◆ hashbulkdelete()

IndexBulkDeleteResult * hashbulkdelete ( IndexVacuumInfo info,
IndexBulkDeleteResult stats,
IndexBulkDeleteCallback  callback,
void *  callback_state 
)

Definition at line 465 of file hash.c.

467{
468 Relation rel = info->index;
469 double tuples_removed;
470 double num_index_tuples;
471 double orig_ntuples;
472 Bucket orig_maxbucket;
473 Bucket cur_maxbucket;
474 Bucket cur_bucket;
475 Buffer metabuf = InvalidBuffer;
476 HashMetaPage metap;
477 HashMetaPage cachedmetap;
478
479 tuples_removed = 0;
480 num_index_tuples = 0;
481
482 /*
483 * We need a copy of the metapage so that we can use its hashm_spares[]
484 * values to compute bucket page addresses, but a cached copy should be
485 * good enough. (If not, we'll detect that further down and refresh the
486 * cache as necessary.)
487 */
488 cachedmetap = _hash_getcachedmetap(rel, &metabuf, false);
489 Assert(cachedmetap != NULL);
490
491 orig_maxbucket = cachedmetap->hashm_maxbucket;
492 orig_ntuples = cachedmetap->hashm_ntuples;
493
494 /* Scan the buckets that we know exist */
495 cur_bucket = 0;
496 cur_maxbucket = orig_maxbucket;
497
498loop_top:
499 while (cur_bucket <= cur_maxbucket)
500 {
501 BlockNumber bucket_blkno;
502 BlockNumber blkno;
503 Buffer bucket_buf;
504 Buffer buf;
505 HashPageOpaque bucket_opaque;
506 Page page;
507 bool split_cleanup = false;
508
509 /* Get address of bucket's start page */
510 bucket_blkno = BUCKET_TO_BLKNO(cachedmetap, cur_bucket);
511
512 blkno = bucket_blkno;
513
514 /*
515 * We need to acquire a cleanup lock on the primary bucket page to out
516 * wait concurrent scans before deleting the dead tuples.
517 */
521
522 page = BufferGetPage(buf);
523 bucket_opaque = HashPageGetOpaque(page);
524
525 /*
526 * If the bucket contains tuples that are moved by split, then we need
527 * to delete such tuples. We can't delete such tuples if the split
528 * operation on bucket is not finished as those are needed by scans.
529 */
530 if (!H_BUCKET_BEING_SPLIT(bucket_opaque) &&
531 H_NEEDS_SPLIT_CLEANUP(bucket_opaque))
532 {
533 split_cleanup = true;
534
535 /*
536 * This bucket might have been split since we last held a lock on
537 * the metapage. If so, hashm_maxbucket, hashm_highmask and
538 * hashm_lowmask might be old enough to cause us to fail to remove
539 * tuples left behind by the most recent split. To prevent that,
540 * now that the primary page of the target bucket has been locked
541 * (and thus can't be further split), check whether we need to
542 * update our cached metapage data.
543 */
544 Assert(bucket_opaque->hasho_prevblkno != InvalidBlockNumber);
545 if (bucket_opaque->hasho_prevblkno > cachedmetap->hashm_maxbucket)
546 {
547 cachedmetap = _hash_getcachedmetap(rel, &metabuf, true);
548 Assert(cachedmetap != NULL);
549 }
550 }
551
552 bucket_buf = buf;
553
554 hashbucketcleanup(rel, cur_bucket, bucket_buf, blkno, info->strategy,
555 cachedmetap->hashm_maxbucket,
556 cachedmetap->hashm_highmask,
557 cachedmetap->hashm_lowmask, &tuples_removed,
558 &num_index_tuples, split_cleanup,
559 callback, callback_state);
560
561 _hash_dropbuf(rel, bucket_buf);
562
563 /* Advance to next bucket */
564 cur_bucket++;
565 }
566
567 if (BufferIsInvalid(metabuf))
569
570 /* Write-lock metapage and check for split since we started */
572 metap = HashPageGetMeta(BufferGetPage(metabuf));
573
574 if (cur_maxbucket != metap->hashm_maxbucket)
575 {
576 /* There's been a split, so process the additional bucket(s) */
578 cachedmetap = _hash_getcachedmetap(rel, &metabuf, true);
579 Assert(cachedmetap != NULL);
580 cur_maxbucket = cachedmetap->hashm_maxbucket;
581 goto loop_top;
582 }
583
584 /* Okay, we're really done. Update tuple count in metapage. */
586
587 if (orig_maxbucket == metap->hashm_maxbucket &&
588 orig_ntuples == metap->hashm_ntuples)
589 {
590 /*
591 * No one has split or inserted anything since start of scan, so
592 * believe our count as gospel.
593 */
594 metap->hashm_ntuples = num_index_tuples;
595 }
596 else
597 {
598 /*
599 * Otherwise, our count is untrustworthy since we may have
600 * double-scanned tuples in split buckets. Proceed by dead-reckoning.
601 * (Note: we still return estimated_count = false, because using this
602 * count is better than not updating reltuples at all.)
603 */
604 if (metap->hashm_ntuples > tuples_removed)
605 metap->hashm_ntuples -= tuples_removed;
606 else
607 metap->hashm_ntuples = 0;
608 num_index_tuples = metap->hashm_ntuples;
609 }
610
611 MarkBufferDirty(metabuf);
612
613 /* XLOG stuff */
614 if (RelationNeedsWAL(rel))
615 {
617 XLogRecPtr recptr;
618
619 xlrec.ntuples = metap->hashm_ntuples;
620
623
625
626 recptr = XLogInsert(RM_HASH_ID, XLOG_HASH_UPDATE_META_PAGE);
627 PageSetLSN(BufferGetPage(metabuf), recptr);
628 }
629
631
632 _hash_relbuf(rel, metabuf);
633
634 /* return statistics */
635 if (stats == NULL)
637 stats->estimated_count = false;
638 stats->num_index_tuples = num_index_tuples;
639 stats->tuples_removed += tuples_removed;
640 /* hashvacuumcleanup will fill in num_pages */
641
642 return stats;
643}
#define InvalidBlockNumber
Definition: block.h:33
#define BufferIsInvalid(buffer)
Definition: buf.h:31
void LockBufferForCleanup(Buffer buffer)
Definition: bufmgr.c:5687
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:805
@ RBM_NORMAL
Definition: bufmgr.h:46
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)
Definition: hash.c:690
#define HASH_NOLOCK
Definition: hash.h:341
#define LH_BUCKET_PAGE
Definition: hash.h:55
#define H_BUCKET_BEING_SPLIT(opaque)
Definition: hash.h:91
#define LH_META_PAGE
Definition: hash.h:57
#define HashPageGetMeta(page)
Definition: hash.h:323
#define BUCKET_TO_BLKNO(metap, B)
Definition: hash.h:39
#define HASH_METAPAGE
Definition: hash.h:198
#define H_NEEDS_SPLIT_CLEANUP(opaque)
Definition: hash.h:90
#define XLOG_HASH_UPDATE_META_PAGE
Definition: hash_xlog.h:38
#define SizeOfHashUpdateMetaPage
Definition: hash_xlog.h:200
HashMetaPage _hash_getcachedmetap(Relation rel, Buffer *metabuf, bool force_refresh)
Definition: hashpage.c:1501
void _hash_dropbuf(Relation rel, Buffer buf)
Definition: hashpage.c:277
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:70
void _hash_checkpage(Relation rel, Buffer buf, int flags)
Definition: hashutil.c:210
void * palloc0(Size size)
Definition: mcxt.c:1973
uint32 hashm_lowmask
Definition: hash.h:256
uint32 hashm_maxbucket
Definition: hash.h:254
double hashm_ntuples
Definition: hash.h:248
uint32 hashm_highmask
Definition: hash.h:255
BlockNumber hasho_prevblkno
Definition: hash.h:79
double tuples_removed
Definition: genam.h:103
double num_index_tuples
Definition: genam.h:102
Relation index
Definition: genam.h:69
BufferAccessStrategy strategy
Definition: genam.h:76

References _hash_checkpage(), _hash_dropbuf(), _hash_getbuf(), _hash_getcachedmetap(), _hash_relbuf(), Assert(), BUCKET_TO_BLKNO, buf, BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_UNLOCK, BufferGetPage(), BufferIsInvalid, callback(), END_CRIT_SECTION, IndexBulkDeleteResult::estimated_count, H_BUCKET_BEING_SPLIT, H_NEEDS_SPLIT_CLEANUP, HASH_METAPAGE, HASH_NOLOCK, hashbucketcleanup(), HashMetaPageData::hashm_highmask, HashMetaPageData::hashm_lowmask, HashMetaPageData::hashm_maxbucket, HashMetaPageData::hashm_ntuples, HashPageOpaqueData::hasho_prevblkno, HashPageGetMeta, HashPageGetOpaque, IndexVacuumInfo::index, InvalidBlockNumber, InvalidBuffer, LH_BUCKET_PAGE, LH_META_PAGE, LockBuffer(), LockBufferForCleanup(), MAIN_FORKNUM, MarkBufferDirty(), xl_hash_update_meta_page::ntuples, IndexBulkDeleteResult::num_index_tuples, PageSetLSN(), palloc0(), RBM_NORMAL, ReadBufferExtended(), REGBUF_STANDARD, RelationNeedsWAL, SizeOfHashUpdateMetaPage, START_CRIT_SECTION, IndexVacuumInfo::strategy, IndexBulkDeleteResult::tuples_removed, XLOG_HASH_UPDATE_META_PAGE, XLogBeginInsert(), XLogInsert(), XLogRegisterBuffer(), and XLogRegisterData().

Referenced by hashhandler().

◆ hashendscan()

void hashendscan ( IndexScanDesc  scan)

Definition at line 434 of file hash.c.

435{
437 Relation rel = scan->indexRelation;
438
440 {
441 /* Before leaving current page, deal with any killed items */
442 if (so->numKilled > 0)
443 _hash_kill_items(scan);
444 }
445
446 _hash_dropscanbuf(rel, so);
447
448 if (so->killedItems != NULL)
449 pfree(so->killedItems);
450 pfree(so);
451 scan->opaque = NULL;
452}
#define HashScanPosIsValid(scanpos)
Definition: hash.h:137
void _hash_dropscanbuf(Relation rel, HashScanOpaque so)
Definition: hashpage.c:289
void _hash_kill_items(IndexScanDesc scan)
Definition: hashutil.c:536
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
Relation indexRelation
Definition: relscan.h:137

References _hash_dropscanbuf(), _hash_kill_items(), HashScanOpaqueData::currPos, HashScanPosIsValid, if(), IndexScanDescData::indexRelation, HashScanOpaqueData::killedItems, HashScanOpaqueData::numKilled, IndexScanDescData::opaque, and pfree().

Referenced by hashhandler().

◆ hashgetbitmap()

int64 hashgetbitmap ( IndexScanDesc  scan,
TIDBitmap tbm 
)

Definition at line 342 of file hash.c.

343{
345 bool res;
346 int64 ntids = 0;
347 HashScanPosItem *currItem;
348
350
351 while (res)
352 {
353 currItem = &so->currPos.items[so->currPos.itemIndex];
354
355 /*
356 * _hash_first and _hash_next handle eliminate dead index entries
357 * whenever scan->ignore_killed_tuples is true. Therefore, there's
358 * nothing to do here except add the results to the TIDBitmap.
359 */
360 tbm_add_tuples(tbm, &(currItem->heapTid), 1, true);
361 ntids++;
362
363 res = _hash_next(scan, ForwardScanDirection);
364 }
365
366 return ntids;
367}
int64_t int64
Definition: c.h:499
bool _hash_first(IndexScanDesc scan, ScanDirection dir)
Definition: hashsearch.c:288
bool _hash_next(IndexScanDesc scan, ScanDirection dir)
Definition: hashsearch.c:48
@ ForwardScanDirection
Definition: sdir.h:28
HashScanPosItem items[MaxIndexTuplesPerPage]
Definition: hash.h:127
int itemIndex
Definition: hash.h:125
void tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids, bool recheck)
Definition: tidbitmap.c:366

References _hash_first(), _hash_next(), HashScanOpaqueData::currPos, ForwardScanDirection, HashScanPosData::itemIndex, HashScanPosData::items, IndexScanDescData::opaque, and tbm_add_tuples().

Referenced by hashhandler().

◆ hashgettuple()

bool hashgettuple ( IndexScanDesc  scan,
ScanDirection  dir 
)

Definition at line 290 of file hash.c.

291{
293 bool res;
294
295 /* Hash indexes are always lossy since we store only the hash code */
296 scan->xs_recheck = true;
297
298 /*
299 * If we've already initialized this scan, we can just advance it in the
300 * appropriate direction. If we haven't done so yet, we call a routine to
301 * get the first item in the scan.
302 */
304 res = _hash_first(scan, dir);
305 else
306 {
307 /*
308 * Check to see if we should kill the previously-fetched tuple.
309 */
310 if (scan->kill_prior_tuple)
311 {
312 /*
313 * Yes, so remember it for later. (We'll deal with all such tuples
314 * at once right after leaving the index page or at end of scan.)
315 * In case if caller reverses the indexscan direction it is quite
316 * possible that the same item might get entered multiple times.
317 * But, we don't detect that; instead, we just forget any excess
318 * entries.
319 */
320 if (so->killedItems == NULL)
321 so->killedItems = (int *)
322 palloc(MaxIndexTuplesPerPage * sizeof(int));
323
325 so->killedItems[so->numKilled++] = so->currPos.itemIndex;
326 }
327
328 /*
329 * Now continue the scan.
330 */
331 res = _hash_next(scan, dir);
332 }
333
334 return res;
335}
#define MaxIndexTuplesPerPage
Definition: itup.h:181
bool kill_prior_tuple
Definition: relscan.h:147

References _hash_first(), _hash_next(), HashScanOpaqueData::currPos, HashScanPosIsValid, if(), HashScanPosData::itemIndex, IndexScanDescData::kill_prior_tuple, HashScanOpaqueData::killedItems, MaxIndexTuplesPerPage, HashScanOpaqueData::numKilled, IndexScanDescData::opaque, palloc(), and IndexScanDescData::xs_recheck.

Referenced by hashhandler().

◆ hashhandler()

Datum hashhandler ( PG_FUNCTION_ARGS  )

Definition at line 58 of file hash.c.

59{
61
63 amroutine->amsupport = HASHNProcs;
65 amroutine->amcanorder = false;
66 amroutine->amcanorderbyop = false;
67 amroutine->amcanhash = true;
68 amroutine->amconsistentequality = true;
69 amroutine->amconsistentordering = false;
70 amroutine->amcanbackward = true;
71 amroutine->amcanunique = false;
72 amroutine->amcanmulticol = false;
73 amroutine->amoptionalkey = false;
74 amroutine->amsearcharray = false;
75 amroutine->amsearchnulls = false;
76 amroutine->amstorage = false;
77 amroutine->amclusterable = false;
78 amroutine->ampredlocks = true;
79 amroutine->amcanparallel = false;
80 amroutine->amcanbuildparallel = false;
81 amroutine->amcaninclude = false;
82 amroutine->amusemaintenanceworkmem = false;
83 amroutine->amsummarizing = false;
84 amroutine->amparallelvacuumoptions =
86 amroutine->amkeytype = INT4OID;
87
88 amroutine->ambuild = hashbuild;
89 amroutine->ambuildempty = hashbuildempty;
90 amroutine->aminsert = hashinsert;
91 amroutine->aminsertcleanup = NULL;
92 amroutine->ambulkdelete = hashbulkdelete;
94 amroutine->amcanreturn = NULL;
96 amroutine->amgettreeheight = NULL;
97 amroutine->amoptions = hashoptions;
98 amroutine->amproperty = NULL;
99 amroutine->ambuildphasename = NULL;
100 amroutine->amvalidate = hashvalidate;
102 amroutine->ambeginscan = hashbeginscan;
103 amroutine->amrescan = hashrescan;
104 amroutine->amgettuple = hashgettuple;
105 amroutine->amgetbitmap = hashgetbitmap;
106 amroutine->amendscan = hashendscan;
107 amroutine->ammarkpos = NULL;
108 amroutine->amrestrpos = NULL;
109 amroutine->amestimateparallelscan = NULL;
110 amroutine->aminitparallelscan = NULL;
111 amroutine->amparallelrescan = NULL;
114
115 PG_RETURN_POINTER(amroutine);
116}
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
bool hashinsert(Relation rel, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
Definition: hash.c:258
IndexBulkDeleteResult * hashvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: hash.c:651
IndexBuildResult * hashbuild(Relation heap, Relation index, IndexInfo *indexInfo)
Definition: hash.c:122
bool hashgettuple(IndexScanDesc scan, ScanDirection dir)
Definition: hash.c:290
CompareType hashtranslatestrategy(StrategyNumber strategy, Oid opfamily)
Definition: hash.c:933
void hashbuildempty(Relation index)
Definition: hash.c:208
IndexScanDesc hashbeginscan(Relation rel, int nkeys, int norderbys)
Definition: hash.c:374
StrategyNumber hashtranslatecmptype(CompareType cmptype, Oid opfamily)
Definition: hash.c:941
IndexBulkDeleteResult * hashbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: hash.c:465
void hashrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
Definition: hash.c:404
void hashendscan(IndexScanDesc scan)
Definition: hash.c:434
int64 hashgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition: hash.c:342
#define HASHNProcs
Definition: hash.h:358
#define HASHOPTIONS_PROC
Definition: hash.h:357
bytea * hashoptions(Datum reloptions, bool validate)
Definition: hashutil.c:275
void hashadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
Definition: hashvalidate.c:263
bool hashvalidate(Oid opclassoid)
Definition: hashvalidate.c:40
#define makeNode(_type_)
Definition: nodes.h:161
void hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Definition: selfuncs.c:7689
#define HTMaxStrategyNumber
Definition: stratnum.h:43
ambuildphasename_function ambuildphasename
Definition: amapi.h:304
ambuildempty_function ambuildempty
Definition: amapi.h:294
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:298
bool amclusterable
Definition: amapi.h:268
amoptions_function amoptions
Definition: amapi.h:302
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:316
amrestrpos_function amrestrpos
Definition: amapi.h:313
aminsert_function aminsert
Definition: amapi.h:295
amendscan_function amendscan
Definition: amapi.h:311
amtranslate_strategy_function amtranslatestrategy
Definition: amapi.h:321
uint16 amoptsprocnum
Definition: amapi.h:242
amparallelrescan_function amparallelrescan
Definition: amapi.h:318
Oid amkeytype
Definition: amapi.h:284
bool amconsistentordering
Definition: amapi.h:252
bool ampredlocks
Definition: amapi.h:270
uint16 amsupport
Definition: amapi.h:240
amtranslate_cmptype_function amtranslatecmptype
Definition: amapi.h:322
amcostestimate_function amcostestimate
Definition: amapi.h:300
bool amcanorderbyop
Definition: amapi.h:246
amadjustmembers_function amadjustmembers
Definition: amapi.h:306
ambuild_function ambuild
Definition: amapi.h:293
bool amstorage
Definition: amapi.h:266
uint16 amstrategies
Definition: amapi.h:238
bool amoptionalkey
Definition: amapi.h:260
amgettuple_function amgettuple
Definition: amapi.h:309
amcanreturn_function amcanreturn
Definition: amapi.h:299
bool amcanunique
Definition: amapi.h:256
amgetbitmap_function amgetbitmap
Definition: amapi.h:310
amproperty_function amproperty
Definition: amapi.h:303
ambulkdelete_function ambulkdelete
Definition: amapi.h:297
bool amsearcharray
Definition: amapi.h:262
bool amsummarizing
Definition: amapi.h:280
amvalidate_function amvalidate
Definition: amapi.h:305
ammarkpos_function ammarkpos
Definition: amapi.h:312
bool amcanmulticol
Definition: amapi.h:258
bool amusemaintenanceworkmem
Definition: amapi.h:278
ambeginscan_function ambeginscan
Definition: amapi.h:307
bool amcanparallel
Definition: amapi.h:272
amrescan_function amrescan
Definition: amapi.h:308
bool amcanorder
Definition: amapi.h:244
bool amcanbuildparallel
Definition: amapi.h:274
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:317
uint8 amparallelvacuumoptions
Definition: amapi.h:282
aminsertcleanup_function aminsertcleanup
Definition: amapi.h:296
bool amcanbackward
Definition: amapi.h:254
amgettreeheight_function amgettreeheight
Definition: amapi.h:301
bool amcaninclude
Definition: amapi.h:276
bool amsearchnulls
Definition: amapi.h:264
bool amconsistentequality
Definition: amapi.h:250
bool amcanhash
Definition: amapi.h:248
#define VACUUM_OPTION_PARALLEL_BULKDEL
Definition: vacuum.h:48

References IndexAmRoutine::amadjustmembers, IndexAmRoutine::ambeginscan, IndexAmRoutine::ambuild, IndexAmRoutine::ambuildempty, IndexAmRoutine::ambuildphasename, IndexAmRoutine::ambulkdelete, IndexAmRoutine::amcanbackward, IndexAmRoutine::amcanbuildparallel, IndexAmRoutine::amcanhash, IndexAmRoutine::amcaninclude, IndexAmRoutine::amcanmulticol, IndexAmRoutine::amcanorder, IndexAmRoutine::amcanorderbyop, IndexAmRoutine::amcanparallel, IndexAmRoutine::amcanreturn, IndexAmRoutine::amcanunique, IndexAmRoutine::amclusterable, IndexAmRoutine::amconsistentequality, IndexAmRoutine::amconsistentordering, IndexAmRoutine::amcostestimate, IndexAmRoutine::amendscan, IndexAmRoutine::amestimateparallelscan, IndexAmRoutine::amgetbitmap, IndexAmRoutine::amgettreeheight, IndexAmRoutine::amgettuple, IndexAmRoutine::aminitparallelscan, IndexAmRoutine::aminsert, IndexAmRoutine::aminsertcleanup, IndexAmRoutine::amkeytype, IndexAmRoutine::ammarkpos, IndexAmRoutine::amoptionalkey, IndexAmRoutine::amoptions, IndexAmRoutine::amoptsprocnum, IndexAmRoutine::amparallelrescan, IndexAmRoutine::amparallelvacuumoptions, IndexAmRoutine::ampredlocks, IndexAmRoutine::amproperty, IndexAmRoutine::amrescan, IndexAmRoutine::amrestrpos, IndexAmRoutine::amsearcharray, IndexAmRoutine::amsearchnulls, IndexAmRoutine::amstorage, IndexAmRoutine::amstrategies, IndexAmRoutine::amsummarizing, IndexAmRoutine::amsupport, IndexAmRoutine::amtranslatecmptype, IndexAmRoutine::amtranslatestrategy, IndexAmRoutine::amusemaintenanceworkmem, IndexAmRoutine::amvacuumcleanup, IndexAmRoutine::amvalidate, hashadjustmembers(), hashbeginscan(), hashbuild(), hashbuildempty(), hashbulkdelete(), hashcostestimate(), hashendscan(), hashgetbitmap(), hashgettuple(), hashinsert(), HASHNProcs, hashoptions(), HASHOPTIONS_PROC, hashrescan(), hashtranslatecmptype(), hashtranslatestrategy(), hashvacuumcleanup(), hashvalidate(), HTMaxStrategyNumber, makeNode, PG_RETURN_POINTER, and VACUUM_OPTION_PARALLEL_BULKDEL.

◆ hashinsert()

bool hashinsert ( Relation  rel,
Datum values,
bool *  isnull,
ItemPointer  ht_ctid,
Relation  heapRel,
IndexUniqueCheck  checkUnique,
bool  indexUnchanged,
IndexInfo indexInfo 
)

Definition at line 258 of file hash.c.

263{
264 Datum index_values[1];
265 bool index_isnull[1];
266 IndexTuple itup;
267
268 /* convert data to a hash key; on failure, do not insert anything */
269 if (!_hash_convert_tuple(rel,
270 values, isnull,
271 index_values, index_isnull))
272 return false;
273
274 /* form an index tuple and point it at the heap tuple */
275 itup = index_form_tuple(RelationGetDescr(rel), index_values, index_isnull);
276 itup->t_tid = *ht_ctid;
277
278 _hash_doinsert(rel, itup, heapRel, false);
279
280 pfree(itup);
281
282 return false;
283}

References _hash_convert_tuple(), _hash_doinsert(), index_form_tuple(), pfree(), RelationGetDescr, IndexTupleData::t_tid, and values.

Referenced by hashhandler().

◆ hashrescan()

void hashrescan ( IndexScanDesc  scan,
ScanKey  scankey,
int  nscankeys,
ScanKey  orderbys,
int  norderbys 
)

Definition at line 404 of file hash.c.

406{
408 Relation rel = scan->indexRelation;
409
411 {
412 /* Before leaving current page, deal with any killed items */
413 if (so->numKilled > 0)
414 _hash_kill_items(scan);
415 }
416
417 _hash_dropscanbuf(rel, so);
418
419 /* set position invalid (this will cause _hash_first call) */
421
422 /* Update scan key, if a new one is given */
423 if (scankey && scan->numberOfKeys > 0)
424 memcpy(scan->keyData, scankey, scan->numberOfKeys * sizeof(ScanKeyData));
425
426 so->hashso_buc_populated = false;
427 so->hashso_buc_split = false;
428}
struct ScanKeyData * keyData
Definition: relscan.h:141

References _hash_dropscanbuf(), _hash_kill_items(), HashScanOpaqueData::currPos, HashScanPosInvalidate, HashScanPosIsValid, HashScanOpaqueData::hashso_buc_populated, HashScanOpaqueData::hashso_buc_split, if(), IndexScanDescData::indexRelation, IndexScanDescData::keyData, IndexScanDescData::numberOfKeys, HashScanOpaqueData::numKilled, and IndexScanDescData::opaque.

Referenced by hashhandler().

◆ hashtranslatecmptype()

StrategyNumber hashtranslatecmptype ( CompareType  cmptype,
Oid  opfamily 
)

Definition at line 941 of file hash.c.

942{
943 if (cmptype == COMPARE_EQ)
945 return InvalidStrategy;
946}
@ COMPARE_EQ
Definition: cmptype.h:36
#define InvalidStrategy
Definition: stratnum.h:24
#define HTEqualStrategyNumber
Definition: stratnum.h:41

References COMPARE_EQ, HTEqualStrategyNumber, and InvalidStrategy.

Referenced by hashhandler().

◆ hashtranslatestrategy()

CompareType hashtranslatestrategy ( StrategyNumber  strategy,
Oid  opfamily 
)

Definition at line 933 of file hash.c.

934{
935 if (strategy == HTEqualStrategyNumber)
936 return COMPARE_EQ;
937 return COMPARE_INVALID;
938}
@ COMPARE_INVALID
Definition: cmptype.h:33

References COMPARE_EQ, COMPARE_INVALID, and HTEqualStrategyNumber.

Referenced by hashhandler().

◆ hashvacuumcleanup()

IndexBulkDeleteResult * hashvacuumcleanup ( IndexVacuumInfo info,
IndexBulkDeleteResult stats 
)

Definition at line 651 of file hash.c.

652{
653 Relation rel = info->index;
654 BlockNumber num_pages;
655
656 /* If hashbulkdelete wasn't called, return NULL signifying no change */
657 /* Note: this covers the analyze_only case too */
658 if (stats == NULL)
659 return NULL;
660
661 /* update statistics */
662 num_pages = RelationGetNumberOfBlocks(rel);
663 stats->num_pages = num_pages;
664
665 return stats;
666}
BlockNumber num_pages
Definition: genam.h:100

References IndexVacuumInfo::index, IndexBulkDeleteResult::num_pages, and RelationGetNumberOfBlocks.

Referenced by hashhandler().