Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2b7334d

Browse files
author
Neil Conway
committed
Refactor the index AM API slightly: move currentItemData and
currentMarkData from IndexScanDesc to the opaque structs for theAMs that need this information (currently gist and hash).Patch from Heikki Linnakangas, fixes by Neil Conway.
1 parent978fff7 commit2b7334d

File tree

9 files changed

+57
-59
lines changed

9 files changed

+57
-59
lines changed

‎src/backend/access/gist/gistget.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.63 2007/01/05 22:19:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.64 2007/01/20 18:43:35 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -106,8 +106,8 @@ gistgettuple(PG_FUNCTION_ARGS)
106106
* If we have produced an index tuple in the past and the executor has
107107
* informed us we need to mark it as "killed", do so now.
108108
*/
109-
if (scan->kill_prior_tuple&&ItemPointerIsValid(&(scan->currentItemData)))
110-
killtuple(scan->indexRelation,so,&(scan->currentItemData));
109+
if (scan->kill_prior_tuple&&ItemPointerIsValid(&(so->curpos)))
110+
killtuple(scan->indexRelation,so,&(so->curpos));
111111

112112
/*
113113
* Get the next tuple that matches the search key. If asked to skip killed
@@ -138,7 +138,8 @@ gistgetmulti(PG_FUNCTION_ARGS)
138138
* tuples. Returns true iff a matching tuple was found.
139139
*/
140140
staticint
141-
gistnext(IndexScanDescscan,ScanDirectiondir,ItemPointertids,intmaxtids,boolignore_killed_tuples)
141+
gistnext(IndexScanDescscan,ScanDirectiondir,ItemPointertids,
142+
intmaxtids,boolignore_killed_tuples)
142143
{
143144
Pagep;
144145
OffsetNumbern;
@@ -151,7 +152,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids, int maxtids, b
151152

152153
so= (GISTScanOpaque)scan->opaque;
153154

154-
if (ItemPointerIsValid(&scan->currentItemData)== false)
155+
if (ItemPointerIsValid(&so->curpos)== false)
155156
{
156157
/* Being asked to fetch the first entry, so start at the root */
157158
Assert(so->curbuf==InvalidBuffer);
@@ -226,7 +227,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids, int maxtids, b
226227
}
227228

228229
if (!GistPageIsLeaf(p)||resetoffset||
229-
!ItemPointerIsValid(&scan->currentItemData))
230+
!ItemPointerIsValid(&so->curpos))
230231
{
231232
if (ScanDirectionIsBackward(dir))
232233
n=PageGetMaxOffsetNumber(p);
@@ -235,7 +236,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids, int maxtids, b
235236
}
236237
else
237238
{
238-
n=ItemPointerGetOffsetNumber(&(scan->currentItemData));
239+
n=ItemPointerGetOffsetNumber(&(so->curpos));
239240

240241
if (ScanDirectionIsBackward(dir))
241242
n=OffsetNumberPrev(n);
@@ -285,7 +286,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids, int maxtids, b
285286
* we can efficiently resume the index scan later.
286287
*/
287288

288-
ItemPointerSet(&(scan->currentItemData),
289+
ItemPointerSet(&(so->curpos),
289290
BufferGetBlockNumber(so->curbuf),n);
290291

291292
if (!(ignore_killed_tuples&&ItemIdDeleted(PageGetItemId(p,n))))

‎src/backend/access/gist/gistscan.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.66 2007/01/05 22:19:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.67 2007/01/20 18:43:35 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -42,12 +42,6 @@ gistrescan(PG_FUNCTION_ARGS)
4242
GISTScanOpaqueso;
4343
inti;
4444

45-
/*
46-
* Clear all the pointers.
47-
*/
48-
ItemPointerSetInvalid(&scan->currentItemData);
49-
ItemPointerSetInvalid(&scan->currentMarkData);
50-
5145
so= (GISTScanOpaque)scan->opaque;
5246
if (so!=NULL)
5347
{
@@ -82,6 +76,12 @@ gistrescan(PG_FUNCTION_ARGS)
8276
scan->opaque=so;
8377
}
8478

79+
/*
80+
* Clear all the pointers.
81+
*/
82+
ItemPointerSetInvalid(&so->curpos);
83+
ItemPointerSetInvalid(&so->markpos);
84+
8585
/* Update scan key, if a new one is given */
8686
if (key&&scan->numberOfKeys>0)
8787
{
@@ -111,8 +111,8 @@ gistmarkpos(PG_FUNCTION_ARGS)
111111
*n,
112112
*tmp;
113113

114-
scan->currentMarkData=scan->currentItemData;
115114
so= (GISTScanOpaque)scan->opaque;
115+
so->markpos=so->curpos;
116116
if (so->flags&GS_CURBEFORE)
117117
so->flags |=GS_MRKBEFORE;
118118
else
@@ -160,8 +160,8 @@ gistrestrpos(PG_FUNCTION_ARGS)
160160
*n,
161161
*tmp;
162162

163-
scan->currentItemData=scan->currentMarkData;
164163
so= (GISTScanOpaque)scan->opaque;
164+
so->curpos=so->markpos;
165165
if (so->flags&GS_MRKBEFORE)
166166
so->flags |=GS_CURBEFORE;
167167
else

‎src/backend/access/hash/hash.c

Lines changed: 22 additions & 22 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.92 2007/01/05 22:19:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.93 2007/01/20 18:43:35 neilc Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -185,7 +185,7 @@ hashgettuple(PG_FUNCTION_ARGS)
185185
* appropriate direction. If we haven't done so yet, we call a routine to
186186
* get the first item in the scan.
187187
*/
188-
if (ItemPointerIsValid(&(scan->currentItemData)))
188+
if (ItemPointerIsValid(&(so->hashso_curpos)))
189189
{
190190
/*
191191
* Check to see if we should kill the previously-fetched tuple.
@@ -195,7 +195,7 @@ hashgettuple(PG_FUNCTION_ARGS)
195195
/*
196196
* Yes, so mark it by setting the LP_DELETE bit in the item flags.
197197
*/
198-
offnum=ItemPointerGetOffsetNumber(&(scan->currentItemData));
198+
offnum=ItemPointerGetOffsetNumber(&(so->hashso_curpos));
199199
page=BufferGetPage(so->hashso_curbuf);
200200
PageGetItemId(page,offnum)->lp_flags |=LP_DELETE;
201201

@@ -222,7 +222,7 @@ hashgettuple(PG_FUNCTION_ARGS)
222222
{
223223
while (res)
224224
{
225-
offnum=ItemPointerGetOffsetNumber(&(scan->currentItemData));
225+
offnum=ItemPointerGetOffsetNumber(&(so->hashso_curpos));
226226
page=BufferGetPage(so->hashso_curbuf);
227227
if (!ItemIdDeleted(PageGetItemId(page,offnum)))
228228
break;
@@ -269,7 +269,7 @@ hashgetmulti(PG_FUNCTION_ARGS)
269269
/*
270270
* Start scan, or advance to next tuple.
271271
*/
272-
if (ItemPointerIsValid(&(scan->currentItemData)))
272+
if (ItemPointerIsValid(&(so->hashso_curpos)))
273273
res=_hash_next(scan,ForwardScanDirection);
274274
else
275275
res=_hash_first(scan,ForwardScanDirection);
@@ -284,7 +284,7 @@ hashgetmulti(PG_FUNCTION_ARGS)
284284
Pagepage;
285285
OffsetNumberoffnum;
286286

287-
offnum=ItemPointerGetOffsetNumber(&(scan->currentItemData));
287+
offnum=ItemPointerGetOffsetNumber(&(so->hashso_curpos));
288288
page=BufferGetPage(so->hashso_curbuf);
289289
if (!ItemIdDeleted(PageGetItemId(page,offnum)))
290290
break;
@@ -325,6 +325,10 @@ hashbeginscan(PG_FUNCTION_ARGS)
325325
so->hashso_bucket_valid= false;
326326
so->hashso_bucket_blkno=0;
327327
so->hashso_curbuf=so->hashso_mrkbuf=InvalidBuffer;
328+
/* set positions invalid (this will cause _hash_first call) */
329+
ItemPointerSetInvalid(&(so->hashso_curpos));
330+
ItemPointerSetInvalid(&(so->hashso_mrkpos));
331+
328332
scan->opaque=so;
329333

330334
/* register scan in case we change pages it's using */
@@ -360,11 +364,11 @@ hashrescan(PG_FUNCTION_ARGS)
360364
if (so->hashso_bucket_blkno)
361365
_hash_droplock(rel,so->hashso_bucket_blkno,HASH_SHARE);
362366
so->hashso_bucket_blkno=0;
363-
}
364367

365-
/* set positions invalid (this will cause _hash_first call) */
366-
ItemPointerSetInvalid(&(scan->currentItemData));
367-
ItemPointerSetInvalid(&(scan->currentMarkData));
368+
/* set positions invalid (this will cause _hash_first call) */
369+
ItemPointerSetInvalid(&(so->hashso_curpos));
370+
ItemPointerSetInvalid(&(so->hashso_mrkpos));
371+
}
368372

369373
/* Update scan key, if a new one is given */
370374
if (scankey&&scan->numberOfKeys>0)
@@ -406,10 +410,6 @@ hashendscan(PG_FUNCTION_ARGS)
406410
_hash_droplock(rel,so->hashso_bucket_blkno,HASH_SHARE);
407411
so->hashso_bucket_blkno=0;
408412

409-
/* be tidy */
410-
ItemPointerSetInvalid(&(scan->currentItemData));
411-
ItemPointerSetInvalid(&(scan->currentMarkData));
412-
413413
pfree(so);
414414
scan->opaque=NULL;
415415

@@ -430,14 +430,14 @@ hashmarkpos(PG_FUNCTION_ARGS)
430430
if (BufferIsValid(so->hashso_mrkbuf))
431431
_hash_dropbuf(rel,so->hashso_mrkbuf);
432432
so->hashso_mrkbuf=InvalidBuffer;
433-
ItemPointerSetInvalid(&(scan->currentMarkData));
433+
ItemPointerSetInvalid(&(so->hashso_mrkpos));
434434

435-
/* bump pin count oncurrentItemDataand copy tocurrentMarkData */
436-
if (ItemPointerIsValid(&(scan->currentItemData)))
435+
/* bump pin count oncurrent bufferand copy tomarked buffer */
436+
if (ItemPointerIsValid(&(so->hashso_curpos)))
437437
{
438438
IncrBufferRefCount(so->hashso_curbuf);
439439
so->hashso_mrkbuf=so->hashso_curbuf;
440-
scan->currentMarkData=scan->currentItemData;
440+
so->hashso_mrkpos=so->hashso_curpos;
441441
}
442442

443443
PG_RETURN_VOID();
@@ -457,14 +457,14 @@ hashrestrpos(PG_FUNCTION_ARGS)
457457
if (BufferIsValid(so->hashso_curbuf))
458458
_hash_dropbuf(rel,so->hashso_curbuf);
459459
so->hashso_curbuf=InvalidBuffer;
460-
ItemPointerSetInvalid(&(scan->currentItemData));
460+
ItemPointerSetInvalid(&(so->hashso_curpos));
461461

462-
/* bump pin count oncurrentMarkDataand copy tocurrentItemData */
463-
if (ItemPointerIsValid(&(scan->currentMarkData)))
462+
/* bump pin count onmarked bufferand copy tocurrent buffer */
463+
if (ItemPointerIsValid(&(so->hashso_mrkpos)))
464464
{
465465
IncrBufferRefCount(so->hashso_mrkbuf);
466466
so->hashso_curbuf=so->hashso_mrkbuf;
467-
scan->currentItemData=scan->currentMarkData;
467+
so->hashso_curpos=so->hashso_mrkpos;
468468
}
469469

470470
PG_RETURN_VOID();

‎src/backend/access/hash/hashsearch.c

Lines changed: 6 additions & 6 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.46 2007/01/05 22:19:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.47 2007/01/20 18:43:35 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -21,7 +21,7 @@
2121
/*
2222
*_hash_next() -- Get the next item in a scan.
2323
*
24-
*On entry, we have a validcurrentItemData in the scan, and a
24+
*On entry, we have a validhashso_curpos in the scan, and a
2525
*pin and read lock on the page that contains that item.
2626
*We find the next item in the scan, if any.
2727
*On success exit, we have the page containing the next item
@@ -49,7 +49,7 @@ _hash_next(IndexScanDesc scan, ScanDirection dir)
4949
return false;
5050

5151
/* if we're here, _hash_step found a valid tuple */
52-
current=&(scan->currentItemData);
52+
current=&(so->hashso_curpos);
5353
offnum=ItemPointerGetOffsetNumber(current);
5454
_hash_checkpage(rel,buf,LH_BUCKET_PAGE |LH_OVERFLOW_PAGE);
5555
page=BufferGetPage(buf);
@@ -129,7 +129,7 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
129129

130130
pgstat_count_index_scan(&scan->xs_pgstat_info);
131131

132-
current=&(scan->currentItemData);
132+
current=&(so->hashso_curpos);
133133
ItemPointerSetInvalid(current);
134134

135135
/*
@@ -224,7 +224,7 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
224224
*_hash_step() -- step to the next valid item in a scan in the bucket.
225225
*
226226
*If no valid record exists in the requested direction, return
227-
*false.Else, return true and set theCurrentItemData for the
227+
*false.Else, return true and set thehashso_curpos for the
228228
*scan to the right thing.
229229
*
230230
*'bufP' points to the current buffer, which is pinned and read-locked.
@@ -245,7 +245,7 @@ _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
245245
BlockNumberblkno;
246246
IndexTupleitup;
247247

248-
current=&(scan->currentItemData);
248+
current=&(so->hashso_curpos);
249249

250250
buf=*bufP;
251251
_hash_checkpage(rel,buf,LH_BUCKET_PAGE |LH_OVERFLOW_PAGE);

‎src/backend/access/index/genam.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.60 2007/01/05 22:19:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.61 2007/01/20 18:43:35 neilc Exp $
1212
*
1313
* NOTES
1414
* many of the old access method routines have been turned into
@@ -92,9 +92,6 @@ RelationGetIndexScan(Relation indexRelation,
9292

9393
scan->opaque=NULL;
9494

95-
ItemPointerSetInvalid(&scan->currentItemData);
96-
ItemPointerSetInvalid(&scan->currentMarkData);
97-
9895
ItemPointerSetInvalid(&scan->xs_ctup.t_self);
9996
scan->xs_ctup.t_data=NULL;
10097
scan->xs_cbuf=InvalidBuffer;

‎src/include/access/gist_private.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.25 2007/01/05 22:19:51 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.26 2007/01/20 18:43:35 neilc Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -72,7 +72,9 @@ typedef struct GISTScanOpaqueData
7272
GISTSTATE*giststate;
7373
MemoryContexttempCxt;
7474
Buffercurbuf;
75+
ItemPointerDatacurpos;
7576
Buffermarkbuf;
77+
ItemPointerDatamarkpos;
7678
}GISTScanOpaqueData;
7779

7880
typedefGISTScanOpaqueData*GISTScanOpaque;

‎src/include/access/hash.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, 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.74 2007/01/05 22:19:51 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/hash.h,v 1.75 2007/01/20 18:43:35 neilc Exp $
1111
*
1212
* NOTES
1313
*modeled after Margo Seltzer's hash implementation for unix.
@@ -97,6 +97,10 @@ typedef struct HashScanOpaqueData
9797
*/
9898
Bufferhashso_curbuf;
9999
Bufferhashso_mrkbuf;
100+
101+
/* Current and marked position of the scan */
102+
ItemPointerDatahashso_curpos;
103+
ItemPointerDatahashso_mrkpos;
100104
}HashScanOpaqueData;
101105

102106
typedefHashScanOpaqueData*HashScanOpaque;

‎src/include/access/nbtree.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.108 2007/01/09 02:14:15 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.109 2007/01/20 18:43:35 neilc Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -390,9 +390,6 @@ typedef BTStackData *BTStack;
390390
* items were killed, we re-lock the page to mark them killed, then unlock.
391391
* Finally we drop the pin and step to the next page in the appropriate
392392
* direction.
393-
*
394-
* NOTE: in this implementation, btree does not use or set the
395-
* currentItemData and currentMarkData fields of IndexScanDesc at all.
396393
*/
397394

398395
typedefstructBTScanPosItem/* what we remember about each match */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp