Skip to content

Commit 7d535eb

Browse files
committed
Dept of second thoughts: after studying index_getnext() a bit more I realize
that it can scribble on scan->xs_ctup.t_self while following HOT chains, so we can't rely on that to stay valid between hashgettuple() calls. Introduce a private variable in HashScanOpaque, instead.
1 parent c4afdca commit 7d535eb

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/backend/access/hash/hash.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.114 2009/11/01 21:25:25 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.115 2009/11/01 22:30:54 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -251,7 +251,7 @@ hashgettuple(PG_FUNCTION_ARGS)
251251
IndexTuple itup;
252252

253253
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
254-
if (ItemPointerEquals(&scan->xs_ctup.t_self, &itup->t_tid))
254+
if (ItemPointerEquals(&(so->hashso_heappos), &(itup->t_tid)))
255255
break;
256256
}
257257
if (offnum > maxoffnum)
@@ -304,6 +304,9 @@ hashgettuple(PG_FUNCTION_ARGS)
304304
if (BufferIsValid(so->hashso_curbuf))
305305
_hash_chgbufaccess(rel, so->hashso_curbuf, HASH_READ, HASH_NOLOCK);
306306

307+
/* Return current heap TID on success */
308+
scan->xs_ctup.t_self = so->hashso_heappos;
309+
307310
PG_RETURN_BOOL(res);
308311
}
309312

@@ -345,7 +348,7 @@ hashgetbitmap(PG_FUNCTION_ARGS)
345348
if (add_tuple)
346349
{
347350
/* Note we mark the tuple ID as requiring recheck */
348-
tbm_add_tuples(tbm, &scan->xs_ctup.t_self, 1, true);
351+
tbm_add_tuples(tbm, &(so->hashso_heappos), 1, true);
349352
ntids++;
350353
}
351354

@@ -375,6 +378,7 @@ hashbeginscan(PG_FUNCTION_ARGS)
375378
so->hashso_curbuf = InvalidBuffer;
376379
/* set position invalid (this will cause _hash_first call) */
377380
ItemPointerSetInvalid(&(so->hashso_curpos));
381+
ItemPointerSetInvalid(&(so->hashso_heappos));
378382

379383
scan->opaque = so;
380384

@@ -410,6 +414,7 @@ hashrescan(PG_FUNCTION_ARGS)
410414

411415
/* set position invalid (this will cause _hash_first call) */
412416
ItemPointerSetInvalid(&(so->hashso_curpos));
417+
ItemPointerSetInvalid(&(so->hashso_heappos));
413418
}
414419

415420
/* Update scan key, if a new one is given */

src/backend/access/hash/hashsearch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.57 2009/06/11 14:48:53 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.58 2009/11/01 22:30:54 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -58,7 +58,7 @@ _hash_next(IndexScanDesc scan, ScanDirection dir)
5858
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
5959
page = BufferGetPage(buf);
6060
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
61-
scan->xs_ctup.t_self = itup->t_tid;
61+
so->hashso_heappos = itup->t_tid;
6262

6363
return true;
6464
}
@@ -242,7 +242,7 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
242242
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
243243
page = BufferGetPage(buf);
244244
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
245-
scan->xs_ctup.t_self = itup->t_tid;
245+
so->hashso_heappos = itup->t_tid;
246246

247247
return true;
248248
}

src/include/access/hash.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/hash.h,v 1.94 2009/11/01 21:25:25 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/access/hash.h,v 1.95 2009/11/01 22:30:54 tgl Exp $
1111
*
1212
* NOTES
1313
* modeled after Margo Seltzer's hash implementation for unix.
@@ -99,8 +99,11 @@ typedef struct HashScanOpaqueData
9999
*/
100100
Buffer hashso_curbuf;
101101

102-
/* Current position of the scan */
102+
/* Current position of the scan, as an index TID */
103103
ItemPointerData hashso_curpos;
104+
105+
/* Current position of the scan, as a heap TID */
106+
ItemPointerData hashso_heappos;
104107
} HashScanOpaqueData;
105108

106109
typedef HashScanOpaqueData *HashScanOpaque;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy