PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
hashutil.c File Reference
#include "postgres.h"
#include "access/hash.h"
#include "access/reloptions.h"
#include "access/relscan.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "storage/buf_internals.h"
Include dependency graph for hashutil.c:

Go to the source code of this file.

Macros

#define CALC_NEW_BUCKET(old_bucket, lowmask)   old_bucket | (lowmask + 1)
 

Functions

bool _hash_checkqual (IndexScanDesc scan, IndexTuple itup)
 
uint32 _hash_datum2hashkey (Relation rel, Datum key)
 
uint32 _hash_datum2hashkey_type (Relation rel, Datum key, Oid keytype)
 
Bucket _hash_hashkey2bucket (uint32 hashkey, uint32 maxbucket, uint32 highmask, uint32 lowmask)
 
uint32 _hash_log2 (uint32 num)
 
void _hash_checkpage (Relation rel, Buffer buf, int flags)
 
byteahashoptions (Datum reloptions, bool validate)
 
uint32 _hash_get_indextuple_hashkey (IndexTuple itup)
 
bool _hash_convert_tuple (Relation index, Datum *user_values, bool *user_isnull, Datum *index_values, bool *index_isnull)
 
OffsetNumber _hash_binsearch (Page page, uint32 hash_value)
 
OffsetNumber _hash_binsearch_last (Page page, uint32 hash_value)
 
BlockNumber _hash_get_oldblock_from_newbucket (Relation rel, Bucket new_bucket)
 
BlockNumber _hash_get_newblock_from_oldbucket (Relation rel, Bucket old_bucket)
 
Bucket _hash_get_newbucket_from_oldbucket (Relation rel, Bucket old_bucket, uint32 lowmask, uint32 maxbucket)
 
void _hash_kill_items (IndexScanDesc scan)
 

Macro Definition Documentation

#define CALC_NEW_BUCKET (   old_bucket,
  lowmask 
)    old_bucket | (lowmask + 1)

Definition at line 24 of file hashutil.c.

Referenced by _hash_get_newbucket_from_oldbucket().

Function Documentation

OffsetNumber _hash_binsearch ( Page  page,
uint32  hash_value 
)

Definition at line 292 of file hashutil.c.

References _hash_get_indextuple_hashkey(), Assert, FirstOffsetNumber, lower(), OffsetNumberIsValid, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, and upper().

Referenced by _hash_pgaddmultitup(), _hash_pgaddtup(), and _hash_step().

293 {
296 
297  /* Loop invariant: lower <= desired place <= upper */
298  upper = PageGetMaxOffsetNumber(page) + 1;
299  lower = FirstOffsetNumber;
300 
301  while (upper > lower)
302  {
303  OffsetNumber off;
304  IndexTuple itup;
305  uint32 hashkey;
306 
307  off = (upper + lower) / 2;
309 
310  itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, off));
311  hashkey = _hash_get_indextuple_hashkey(itup);
312  if (hashkey < hash_value)
313  lower = off + 1;
314  else
315  upper = off;
316  }
317 
318  return lower;
319 }
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:43
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:74
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
uint16 OffsetNumber
Definition: off.h:24
uint32 _hash_get_indextuple_hashkey(IndexTuple itup)
Definition: hashutil.c:233
#define FirstOffsetNumber
Definition: off.h:27
IndexTupleData * IndexTuple
Definition: itup.h:53
unsigned int uint32
Definition: c.h:268
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
#define Assert(condition)
Definition: c.h:675
#define OffsetNumberIsValid(offsetNumber)
Definition: off.h:40
#define PageGetItem(page, itemId)
Definition: bufpage.h:337
OffsetNumber _hash_binsearch_last ( Page  page,
uint32  hash_value 
)

Definition at line 330 of file hashutil.c.

References _hash_get_indextuple_hashkey(), Assert, FirstOffsetNumber, lower(), OffsetNumberIsValid, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, and upper().

Referenced by _hash_step().

331 {
334 
335  /* Loop invariant: lower <= desired place <= upper */
336  upper = PageGetMaxOffsetNumber(page);
337  lower = FirstOffsetNumber - 1;
338 
339  while (upper > lower)
340  {
341  IndexTuple itup;
342  OffsetNumber off;
343  uint32 hashkey;
344 
345  off = (upper + lower + 1) / 2;
347 
348  itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, off));
349  hashkey = _hash_get_indextuple_hashkey(itup);
350  if (hashkey > hash_value)
351  upper = off - 1;
352  else
353  lower = off;
354  }
355 
356  return lower;
357 }
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:43
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:74
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
uint16 OffsetNumber
Definition: off.h:24
uint32 _hash_get_indextuple_hashkey(IndexTuple itup)
Definition: hashutil.c:233
#define FirstOffsetNumber
Definition: off.h:27
IndexTupleData * IndexTuple
Definition: itup.h:53
unsigned int uint32
Definition: c.h:268
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
#define Assert(condition)
Definition: c.h:675
#define OffsetNumberIsValid(offsetNumber)
Definition: off.h:40
#define PageGetItem(page, itemId)
Definition: bufpage.h:337
void _hash_checkpage ( Relation  rel,
Buffer  buf,
int  flags 
)

Definition at line 159 of file hashutil.c.

References BufferGetBlockNumber(), BufferGetPage, ereport, errcode(), errhint(), errmsg(), ERROR, HASH_MAGIC, HASH_VERSION, HashMetaPageData::hashm_magic, HashMetaPageData::hashm_version, HashPageOpaqueData::hasho_flag, HashPageGetMeta, LH_META_PAGE, MAXALIGN, PageGetSpecialPointer, PageGetSpecialSize, PageIsNew, and RelationGetRelationName.

Referenced by _hash_addovflpage(), _hash_expandtable(), _hash_first(), _hash_freeovflpage(), _hash_getbuf(), _hash_getbuf_with_condlock_cleanup(), _hash_getbuf_with_strategy(), _hash_next(), _hash_pgaddmultitup(), _hash_pgaddtup(), _hash_step(), and hashbulkdelete().

160 {
161  Page page = BufferGetPage(buf);
162 
163  /*
164  * ReadBuffer verifies that every newly-read page passes
165  * PageHeaderIsValid, which means it either contains a reasonably sane
166  * page header or is all-zero. We have to defend against the all-zero
167  * case, however.
168  */
169  if (PageIsNew(page))
170  ereport(ERROR,
171  (errcode(ERRCODE_INDEX_CORRUPTED),
172  errmsg("index \"%s\" contains unexpected zero page at block %u",
175  errhint("Please REINDEX it.")));
176 
177  /*
178  * Additionally check that the special area looks sane.
179  */
180  if (PageGetSpecialSize(page) != MAXALIGN(sizeof(HashPageOpaqueData)))
181  ereport(ERROR,
182  (errcode(ERRCODE_INDEX_CORRUPTED),
183  errmsg("index \"%s\" contains corrupted page at block %u",
186  errhint("Please REINDEX it.")));
187 
188  if (flags)
189  {
191 
192  if ((opaque->hasho_flag & flags) == 0)
193  ereport(ERROR,
194  (errcode(ERRCODE_INDEX_CORRUPTED),
195  errmsg("index \"%s\" contains corrupted page at block %u",
198  errhint("Please REINDEX it.")));
199  }
200 
201  /*
202  * When checking the metapage, also verify magic number and version.
203  */
204  if (flags == LH_META_PAGE)
205  {
206  HashMetaPage metap = HashPageGetMeta(page);
207 
208  if (metap->hashm_magic != HASH_MAGIC)
209  ereport(ERROR,
210  (errcode(ERRCODE_INDEX_CORRUPTED),
211  errmsg("index \"%s\" is not a hash index",
212  RelationGetRelationName(rel))));
213 
214  if (metap->hashm_version != HASH_VERSION)
215  ereport(ERROR,
216  (errcode(ERRCODE_INDEX_CORRUPTED),
217  errmsg("index \"%s\" has wrong hash version",
219  errhint("Please REINDEX it.")));
220  }
221 }
int errhint(const char *fmt,...)
Definition: elog.c:987
#define LH_META_PAGE
Definition: hash.h:56
uint32 hashm_magic
Definition: hash.h:188
int errcode(int sqlerrcode)
Definition: elog.c:575
#define HASH_VERSION
Definition: hash.h:161
#define HASH_MAGIC
Definition: hash.h:160
#define ERROR
Definition: elog.h:43
uint32 hashm_version
Definition: hash.h:189
static char * buf
Definition: pg_test_fsync.c:65
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
#define PageGetSpecialPointer(page)
Definition: bufpage.h:323
HashPageOpaqueData * HashPageOpaque
Definition: hash.h:85
#define MAXALIGN(LEN)
Definition: c.h:588
#define PageGetSpecialSize(page)
Definition: bufpage.h:297
uint16 hasho_flag
Definition: hash.h:81
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
#define PageIsNew(page)
Definition: bufpage.h:226
#define HashPageGetMeta(page)
Definition: hash.h:250
int errmsg(const char *fmt,...)
Definition: elog.c:797
Pointer Page
Definition: bufpage.h:74
bool _hash_checkqual ( IndexScanDesc  scan,
IndexTuple  itup 
)

Definition at line 31 of file hashutil.c.

References DatumGetBool, FunctionCall2Coll(), index_getattr, IndexScanDescData::indexRelation, IndexScanDescData::keyData, IndexScanDescData::numberOfKeys, RelationGetDescr, ScanKeyData::sk_argument, ScanKeyData::sk_attno, ScanKeyData::sk_collation, ScanKeyData::sk_flags, ScanKeyData::sk_func, SK_ISNULL, and test().

Referenced by _hash_step().

32 {
33  /*
34  * Currently, we can't check any of the scan conditions since we do not
35  * have the original index entry value to supply to the sk_func. Always
36  * return true; we expect that hashgettuple already set the recheck flag
37  * to make the main indexscan code do it.
38  */
39 #ifdef NOT_USED
40  TupleDesc tupdesc = RelationGetDescr(scan->indexRelation);
41  ScanKey key = scan->keyData;
42  int scanKeySize = scan->numberOfKeys;
43 
44  while (scanKeySize > 0)
45  {
46  Datum datum;
47  bool isNull;
48  Datum test;
49 
50  datum = index_getattr(itup,
51  key->sk_attno,
52  tupdesc,
53  &isNull);
54 
55  /* assume sk_func is strict */
56  if (isNull)
57  return false;
58  if (key->sk_flags & SK_ISNULL)
59  return false;
60 
61  test = FunctionCall2Coll(&key->sk_func, key->sk_collation,
62  datum, key->sk_argument);
63 
64  if (!DatumGetBool(test))
65  return false;
66 
67  key++;
68  scanKeySize--;
69  }
70 #endif
71 
72  return true;
73 }
static void test(void)
#define RelationGetDescr(relation)
Definition: rel.h:429
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1356
Relation indexRelation
Definition: relscan.h:89
FmgrInfo sk_func
Definition: skey.h:71
#define DatumGetBool(X)
Definition: postgres.h:399
#define SK_ISNULL
Definition: skey.h:115
uintptr_t Datum
Definition: postgres.h:372
int sk_flags
Definition: skey.h:66
#define index_getattr(tup, attnum, tupleDesc, isnull)
Definition: itup.h:100
ScanKey keyData
Definition: relscan.h:93
Oid sk_collation
Definition: skey.h:70
Datum sk_argument
Definition: skey.h:72
AttrNumber sk_attno
Definition: skey.h:67
bool _hash_convert_tuple ( Relation  index,
Datum user_values,
bool user_isnull,
Datum index_values,
bool index_isnull 
)

Definition at line 260 of file hashutil.c.

References _hash_datum2hashkey(), and UInt32GetDatum.

Referenced by hashbuildCallback(), and hashinsert().

263 {
264  uint32 hashkey;
265 
266  /*
267  * We do not insert null values into hash indexes. This is okay because
268  * the only supported search operator is '=', and we assume it is strict.
269  */
270  if (user_isnull[0])
271  return false;
272 
273  hashkey = _hash_datum2hashkey(index, user_values[0]);
274  index_values[0] = UInt32GetDatum(hashkey);
275  index_isnull[0] = false;
276  return true;
277 }
uint32 _hash_datum2hashkey(Relation rel, Datum key)
Definition: hashutil.c:82
unsigned int uint32
Definition: c.h:268
#define UInt32GetDatum(X)
Definition: postgres.h:499
uint32 _hash_datum2hashkey ( Relation  rel,
Datum  key 
)

Definition at line 82 of file hashutil.c.

References DatumGetUInt32, FunctionCall1Coll(), HASHPROC, index_getprocinfo(), and RelationData::rd_indcollation.

Referenced by _hash_convert_tuple(), and _hash_first().

83 {
84  FmgrInfo *procinfo;
85  Oid collation;
86 
87  /* XXX assumes index has only one attribute */
88  procinfo = index_getprocinfo(rel, 1, HASHPROC);
89  collation = rel->rd_indcollation[0];
90 
91  return DatumGetUInt32(FunctionCall1Coll(procinfo, collation, key));
92 }
#define DatumGetUInt32(X)
Definition: postgres.h:492
Definition: fmgr.h:56
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:855
unsigned int Oid
Definition: postgres_ext.h:31
Oid * rd_indcollation
Definition: rel.h:193
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1336
#define HASHPROC
Definition: hash.h:281
uint32 _hash_datum2hashkey_type ( Relation  rel,
Datum  key,
Oid  keytype 
)

Definition at line 102 of file hashutil.c.

References DatumGetUInt32, elog, ERROR, get_opfamily_proc(), HASHPROC, OidFunctionCall1Coll(), RelationData::rd_indcollation, RelationData::rd_opfamily, RegProcedureIsValid, and RelationGetRelationName.

Referenced by _hash_first().

103 {
104  RegProcedure hash_proc;
105  Oid collation;
106 
107  /* XXX assumes index has only one attribute */
108  hash_proc = get_opfamily_proc(rel->rd_opfamily[0],
109  keytype,
110  keytype,
111  HASHPROC);
112  if (!RegProcedureIsValid(hash_proc))
113  elog(ERROR, "missing support function %d(%u,%u) for index \"%s\"",
114  HASHPROC, keytype, keytype,
116  collation = rel->rd_indcollation[0];
117 
118  return DatumGetUInt32(OidFunctionCall1Coll(hash_proc, collation, key));
119 }
#define DatumGetUInt32(X)
Definition: postgres.h:492
regproc RegProcedure
Definition: c.h:395
unsigned int Oid
Definition: postgres_ext.h:31
Oid * rd_indcollation
Definition: rel.h:193
#define ERROR
Definition: elog.h:43
#define RegProcedureIsValid(p)
Definition: c.h:540
#define RelationGetRelationName(relation)
Definition: rel.h:437
Oid * rd_opfamily
Definition: rel.h:182
Datum OidFunctionCall1Coll(Oid functionId, Oid collation, Datum arg1)
Definition: fmgr.c:1628
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Definition: lsyscache.c:744
#define HASHPROC
Definition: hash.h:281
#define elog
Definition: elog.h:219
uint32 _hash_get_indextuple_hashkey ( IndexTuple  itup)

Definition at line 233 of file hashutil.c.

References IndexInfoFindDataOffset, and IndexTupleData::t_info.

Referenced by _h_indexbuild(), _hash_binsearch(), _hash_binsearch_last(), _hash_doinsert(), _hash_pgaddmultitup(), _hash_pgaddtup(), _hash_splitbucket(), _hash_step(), hash_page_items(), and hashbucketcleanup().

234 {
235  char *attp;
236 
237  /*
238  * We assume the hash key is the first attribute and can't be null, so
239  * this can be done crudely but very very cheaply ...
240  */
241  attp = (char *) itup + IndexInfoFindDataOffset(itup->t_info);
242  return *((uint32 *) attp);
243 }
#define IndexInfoFindDataOffset(t_info)
Definition: itup.h:80
unsigned int uint32
Definition: c.h:268
unsigned short t_info
Definition: itup.h:49
BlockNumber _hash_get_newblock_from_oldbucket ( Relation  rel,
Bucket  old_bucket 
)

Definition at line 403 of file hashutil.c.

References _hash_get_newbucket_from_oldbucket(), _hash_getbuf(), _hash_relbuf(), BUCKET_TO_BLKNO, BufferGetPage, HASH_METAPAGE, HASH_READ, HashMetaPageData::hashm_lowmask, HashMetaPageData::hashm_maxbucket, HashPageGetMeta, and LH_META_PAGE.

Referenced by _hash_finish_split().

404 {
405  Bucket new_bucket;
406  Buffer metabuf;
407  HashMetaPage metap;
408  BlockNumber blkno;
409 
411  metap = HashPageGetMeta(BufferGetPage(metabuf));
412 
413  new_bucket = _hash_get_newbucket_from_oldbucket(rel, old_bucket,
414  metap->hashm_lowmask,
415  metap->hashm_maxbucket);
416  blkno = BUCKET_TO_BLKNO(metap, new_bucket);
417 
418  _hash_relbuf(rel, metabuf);
419 
420  return blkno;
421 }
#define LH_META_PAGE
Definition: hash.h:56
uint32 BlockNumber
Definition: block.h:31
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:78
uint32 hashm_lowmask
Definition: hash.h:198
#define BUCKET_TO_BLKNO(metap, B)
Definition: hash.h:38
#define HASH_READ
Definition: hash.h:266
uint32 Bucket
Definition: hash.h:34
Bucket _hash_get_newbucket_from_oldbucket(Relation rel, Bucket old_bucket, uint32 lowmask, uint32 maxbucket)
Definition: hashutil.c:436
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define HASH_METAPAGE
Definition: hash.h:158
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:274
uint32 hashm_maxbucket
Definition: hash.h:196
#define HashPageGetMeta(page)
Definition: hash.h:250
int Buffer
Definition: buf.h:23
Bucket _hash_get_newbucket_from_oldbucket ( Relation  rel,
Bucket  old_bucket,
uint32  lowmask,
uint32  maxbucket 
)

Definition at line 436 of file hashutil.c.

References CALC_NEW_BUCKET.

Referenced by _hash_get_newblock_from_oldbucket(), and hashbucketcleanup().

438 {
439  Bucket new_bucket;
440 
441  new_bucket = CALC_NEW_BUCKET(old_bucket, lowmask);
442  if (new_bucket > maxbucket)
443  {
444  lowmask = lowmask >> 1;
445  new_bucket = CALC_NEW_BUCKET(old_bucket, lowmask);
446  }
447 
448  return new_bucket;
449 }
#define CALC_NEW_BUCKET(old_bucket, lowmask)
Definition: hashutil.c:24
uint32 Bucket
Definition: hash.h:34
BlockNumber _hash_get_oldblock_from_newbucket ( Relation  rel,
Bucket  new_bucket 
)

Definition at line 364 of file hashutil.c.

References _hash_getbuf(), _hash_relbuf(), BUCKET_TO_BLKNO, BufferGetPage, fls(), HASH_METAPAGE, HASH_READ, HashPageGetMeta, and LH_META_PAGE.

Referenced by _hash_first().

365 {
366  Bucket old_bucket;
367  uint32 mask;
368  Buffer metabuf;
369  HashMetaPage metap;
370  BlockNumber blkno;
371 
372  /*
373  * To get the old bucket from the current bucket, we need a mask to modulo
374  * into lower half of table. This mask is stored in meta page as
375  * hashm_lowmask, but here we can't rely on the same, because we need a
376  * value of lowmask that was prevalent at the time when bucket split was
377  * started. Masking the most significant bit of new bucket would give us
378  * old bucket.
379  */
380  mask = (((uint32) 1) << (fls(new_bucket) - 1)) - 1;
381  old_bucket = new_bucket & mask;
382 
384  metap = HashPageGetMeta(BufferGetPage(metabuf));
385 
386  blkno = BUCKET_TO_BLKNO(metap, old_bucket);
387 
388  _hash_relbuf(rel, metabuf);
389 
390  return blkno;
391 }
#define LH_META_PAGE
Definition: hash.h:56
uint32 BlockNumber
Definition: block.h:31
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:78
#define BUCKET_TO_BLKNO(metap, B)
Definition: hash.h:38
int fls(int mask)
Definition: fls.c:55
#define HASH_READ
Definition: hash.h:266
uint32 Bucket
Definition: hash.h:34
unsigned int uint32
Definition: c.h:268
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define HASH_METAPAGE
Definition: hash.h:158
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:274
#define HashPageGetMeta(page)
Definition: hash.h:250
int Buffer
Definition: buf.h:23
Bucket _hash_hashkey2bucket ( uint32  hashkey,
uint32  maxbucket,
uint32  highmask,
uint32  lowmask 
)

Definition at line 125 of file hashutil.c.

Referenced by _hash_getbucketbuf_from_hashkey(), _hash_splitbucket(), and hashbucketcleanup().

127 {
128  Bucket bucket;
129 
130  bucket = hashkey & highmask;
131  if (bucket > maxbucket)
132  bucket = bucket & lowmask;
133 
134  return bucket;
135 }
uint32 Bucket
Definition: hash.h:34
void _hash_kill_items ( IndexScanDesc  scan)

Definition at line 463 of file hashutil.c.

References Assert, BufferGetPage, HashScanOpaqueData::hashso_curbuf, HashScanPosItem::heapTid, i, HashScanPosItem::indexOffset, ItemIdMarkDead, ItemPointerEquals(), HashScanOpaqueData::killedItems, LH_PAGE_HAS_DEAD_TUPLES, MarkBufferDirtyHint(), NULL, HashScanOpaqueData::numKilled, OffsetNumberNext, IndexScanDescData::opaque, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, PageGetSpecialPointer, and IndexTupleData::t_tid.

Referenced by _hash_step(), hashendscan(), and hashrescan().

464 {
465  HashScanOpaque so = (HashScanOpaque) scan->opaque;
466  Page page;
467  HashPageOpaque opaque;
468  OffsetNumber offnum, maxoff;
469  int numKilled = so->numKilled;
470  int i;
471  bool killedsomething = false;
472 
473  Assert(so->numKilled > 0);
474  Assert(so->killedItems != NULL);
475 
476  /*
477  * Always reset the scan state, so we don't look for same
478  * items on other pages.
479  */
480  so->numKilled = 0;
481 
482  page = BufferGetPage(so->hashso_curbuf);
483  opaque = (HashPageOpaque) PageGetSpecialPointer(page);
484  maxoff = PageGetMaxOffsetNumber(page);
485 
486  for (i = 0; i < numKilled; i++)
487  {
488  offnum = so->killedItems[i].indexOffset;
489 
490  while (offnum <= maxoff)
491  {
492  ItemId iid = PageGetItemId(page, offnum);
493  IndexTuple ituple = (IndexTuple) PageGetItem(page, iid);
494 
495  if (ItemPointerEquals(&ituple->t_tid, &so->killedItems[i].heapTid))
496  {
497  /* found the item */
498  ItemIdMarkDead(iid);
499  killedsomething = true;
500  break; /* out of inner search loop */
501  }
502  offnum = OffsetNumberNext(offnum);
503  }
504  }
505 
506  /*
507  * Since this can be redone later if needed, mark as dirty hint.
508  * Whenever we mark anything LP_DEAD, we also set the page's
509  * LH_PAGE_HAS_DEAD_TUPLES flag, which is likewise just a hint.
510  */
511  if (killedsomething)
512  {
513  opaque->hasho_flag |= LH_PAGE_HAS_DEAD_TUPLES;
515  }
516 }
HashScanOpaqueData * HashScanOpaque
Definition: hash.h:152
void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
Definition: bufmgr.c:3379
#define ItemIdMarkDead(itemId)
Definition: itemid.h:178
ItemPointerData t_tid
Definition: itup.h:37
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
uint16 OffsetNumber
Definition: off.h:24
IndexTupleData * IndexTuple
Definition: itup.h:53
HashScanPosItem * killedItems
Definition: hash.h:148
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define OffsetNumberNext(offsetNumber)
Definition: off.h:53
#define PageGetSpecialPointer(page)
Definition: bufpage.h:323
HashPageOpaqueData * HashPageOpaque
Definition: hash.h:85
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
OffsetNumber indexOffset
Definition: hash.h:103
int i
ItemPointerData heapTid
Definition: hash.h:102
Buffer hashso_curbuf
Definition: hash.h:121
#define LH_PAGE_HAS_DEAD_TUPLES
Definition: hash.h:60
#define PageGetItem(page, itemId)
Definition: bufpage.h:337
Pointer Page
Definition: bufpage.h:74
uint32 _hash_log2 ( uint32  num)

Definition at line 141 of file hashutil.c.

References i.

Referenced by _h_spoolinit(), _hash_expandtable(), and _hash_init_metabuffer().

142 {
143  uint32 i,
144  limit;
145 
146  limit = 1;
147  for (i = 0; limit < num; limit <<= 1, i++)
148  ;
149  return i;
150 }
unsigned int uint32
Definition: c.h:268
int i
bytea* hashoptions ( Datum  reloptions,
bool  validate 
)

Definition at line 224 of file hashutil.c.

References default_reloptions(), and RELOPT_KIND_HASH.

Referenced by hashhandler().

225 {
226  return default_reloptions(reloptions, validate, RELOPT_KIND_HASH);
227 }
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1309