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

Commit737651f

Browse files
author
Neil Conway
committed
Cleanup the usage of ScanDirection: use the symbolic names for the
possible ScanDirection alternatives rather than magic numbers(-1, 0, 1). Also, use the ScanDirection macros in a few placesrather than directly checking whether `dir == ForwardScanDirection'and the like. Per patch from James William Pye. His patch alsochanged ScanDirection to be a "char" rather than an enum, whichI haven't applied.
1 parent3666260 commit737651f

File tree

3 files changed

+30
-48
lines changed

3 files changed

+30
-48
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.206 2006/01/11 08:43:11 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.207 2006/02/21 23:01:53 neilc Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -172,7 +172,8 @@ heapgetpage(HeapScanDesc scan, BlockNumber page)
172172
*tuple as indicated by "dir"; return the next tuple in scan->rs_ctup,
173173
*or set scan->rs_ctup.t_data = NULL if no more tuples.
174174
*
175-
* dir == 0 means "re-fetch the tuple indicated by scan->rs_ctup".
175+
* dir == NoMovementScanDirection means "re-fetch the tuple indicated
176+
* by scan->rs_ctup".
176177
*
177178
* Note: the reason nkeys/key are passed separately, even though they are
178179
* kept in the scan descriptor, is that the caller may not want us to check
@@ -189,12 +190,13 @@ heapgetpage(HeapScanDesc scan, BlockNumber page)
189190
*/
190191
staticvoid
191192
heapgettup(HeapScanDescscan,
192-
intdir,
193+
ScanDirectiondir,
193194
intnkeys,
194195
ScanKeykey)
195196
{
196197
HeapTupletuple=&(scan->rs_ctup);
197198
Snapshotsnapshot=scan->rs_snapshot;
199+
boolbackward=ScanDirectionIsBackward(dir);
198200
BlockNumberpage;
199201
Pagedp;
200202
intlines;
@@ -205,11 +207,8 @@ heapgettup(HeapScanDesc scan,
205207
/*
206208
* calculate next starting lineoff, given scan direction
207209
*/
208-
if (dir>0)
210+
if (ScanDirectionIsForward(dir))
209211
{
210-
/*
211-
* forward scan direction
212-
*/
213212
if (!scan->rs_inited)
214213
{
215214
/*
@@ -242,11 +241,8 @@ heapgettup(HeapScanDesc scan,
242241

243242
linesleft=lines-lineoff+1;
244243
}
245-
elseif (dir<0)
244+
elseif (backward)
246245
{
247-
/*
248-
* reverse scan direction
249-
*/
250246
if (!scan->rs_inited)
251247
{
252248
/*
@@ -352,7 +348,7 @@ heapgettup(HeapScanDesc scan,
352348
* otherwise move to the next item on the page
353349
*/
354350
--linesleft;
355-
if (dir<0)
351+
if (backward)
356352
{
357353
--lpp;/* move back in this page's ItemId array */
358354
--lineoff;
@@ -373,7 +369,7 @@ heapgettup(HeapScanDesc scan,
373369
/*
374370
* return NULL if we've exhausted all the pages
375371
*/
376-
if ((dir<0) ? (page==0) : (page+1 >=scan->rs_nblocks))
372+
if (backward ? (page==0) : (page+1 >=scan->rs_nblocks))
377373
{
378374
if (BufferIsValid(scan->rs_cbuf))
379375
ReleaseBuffer(scan->rs_cbuf);
@@ -384,7 +380,7 @@ heapgettup(HeapScanDesc scan,
384380
return;
385381
}
386382

387-
page=(dir<0) ? (page-1) : (page+1);
383+
page=backward ? (page-1) : (page+1);
388384

389385
heapgetpage(scan,page);
390386

@@ -393,7 +389,7 @@ heapgettup(HeapScanDesc scan,
393389
dp= (Page)BufferGetPage(scan->rs_cbuf);
394390
lines=PageGetMaxOffsetNumber((Page)dp);
395391
linesleft=lines;
396-
if (dir<0)
392+
if (backward)
397393
{
398394
lineoff=lines;
399395
lpp=PageGetItemId(dp,lines);
@@ -421,11 +417,12 @@ heapgettup(HeapScanDesc scan,
421417
*/
422418
staticvoid
423419
heapgettup_pagemode(HeapScanDescscan,
424-
intdir,
420+
ScanDirectiondir,
425421
intnkeys,
426422
ScanKeykey)
427423
{
428424
HeapTupletuple=&(scan->rs_ctup);
425+
boolbackward=ScanDirectionIsBackward(dir);
429426
BlockNumberpage;
430427
Pagedp;
431428
intlines;
@@ -437,11 +434,8 @@ heapgettup_pagemode(HeapScanDesc scan,
437434
/*
438435
* calculate next starting lineindex, given scan direction
439436
*/
440-
if (dir>0)
437+
if (ScanDirectionIsForward(dir))
441438
{
442-
/*
443-
* forward scan direction
444-
*/
445439
if (!scan->rs_inited)
446440
{
447441
/*
@@ -471,11 +465,8 @@ heapgettup_pagemode(HeapScanDesc scan,
471465

472466
linesleft=lines-lineindex;
473467
}
474-
elseif (dir<0)
468+
elseif (backward)
475469
{
476-
/*
477-
* reverse scan direction
478-
*/
479470
if (!scan->rs_inited)
480471
{
481472
/*
@@ -584,14 +575,10 @@ heapgettup_pagemode(HeapScanDesc scan,
584575
* otherwise move to the next item on the page
585576
*/
586577
--linesleft;
587-
if (dir<0)
588-
{
578+
if (backward)
589579
--lineindex;
590-
}
591580
else
592-
{
593581
++lineindex;
594-
}
595582
}
596583

597584
/*
@@ -602,7 +589,7 @@ heapgettup_pagemode(HeapScanDesc scan,
602589
/*
603590
* return NULL if we've exhausted all the pages
604591
*/
605-
if ((dir<0) ? (page==0) : (page+1 >=scan->rs_nblocks))
592+
if (backward ? (page==0) : (page+1 >=scan->rs_nblocks))
606593
{
607594
if (BufferIsValid(scan->rs_cbuf))
608595
ReleaseBuffer(scan->rs_cbuf);
@@ -613,14 +600,13 @@ heapgettup_pagemode(HeapScanDesc scan,
613600
return;
614601
}
615602

616-
page= (dir<0) ? (page-1) : (page+1);
617-
603+
page=backward ? (page-1) : (page+1);
618604
heapgetpage(scan,page);
619605

620606
dp= (Page)BufferGetPage(scan->rs_cbuf);
621607
lines=scan->rs_ntuples;
622608
linesleft=lines;
623-
if (dir<0)
609+
if (backward)
624610
lineindex=lines-1;
625611
else
626612
lineindex=0;
@@ -1008,15 +994,11 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction)
1008994

1009995
HEAPDEBUG_1;/* heap_getnext( info ) */
1010996

1011-
/*
1012-
* Note: we depend here on the -1/0/1 encoding of ScanDirection.
1013-
*/
1014997
if (scan->rs_pageatatime)
1015-
heapgettup_pagemode(scan,(int)direction,
998+
heapgettup_pagemode(scan,direction,
1016999
scan->rs_nkeys,scan->rs_key);
10171000
else
1018-
heapgettup(scan, (int)direction,
1019-
scan->rs_nkeys,scan->rs_key);
1001+
heapgettup(scan,direction,scan->rs_nkeys,scan->rs_key);
10201002

10211003
if (scan->rs_ctup.t_data==NULL)
10221004
{
@@ -2745,13 +2727,13 @@ heap_restrpos(HeapScanDesc scan)
27452727
{
27462728
scan->rs_cindex=scan->rs_mindex;
27472729
heapgettup_pagemode(scan,
2748-
0,/* "no movement" */
2730+
NoMovementScanDirection,
27492731
0,/* needn't recheck scan keys */
27502732
NULL);
27512733
}
27522734
else
27532735
heapgettup(scan,
2754-
0,/* "no movement" */
2736+
NoMovementScanDirection,
27552737
0,/* needn't recheck scan keys */
27562738
NULL);
27572739
}

‎src/backend/executor/execMain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.266 2006/02/19 00:04:26 neilc Exp $
29+
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.267 2006/02/21 23:01:54 neilc Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -218,7 +218,7 @@ ExecutorRun(QueryDesc *queryDesc,
218218
/*
219219
* run plan
220220
*/
221-
if (direction==NoMovementScanDirection)
221+
if (ScanDirectionIsNoMovement(direction))
222222
result=NULL;
223223
else
224224
result=ExecutePlan(estate,

‎src/backend/tcop/pquery.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.98 2005/11/22 18:17:21 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.99 2006/02/21 23:01:54 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -795,7 +795,7 @@ PortalRunSelect(Portal portal,
795795
nprocessed=queryDesc->estate->es_processed;
796796
}
797797

798-
if (direction!=NoMovementScanDirection)
798+
if (!ScanDirectionIsNoMovement(direction))
799799
{
800800
longoldPos;
801801

@@ -837,7 +837,7 @@ PortalRunSelect(Portal portal,
837837
nprocessed=queryDesc->estate->es_processed;
838838
}
839839

840-
if (direction!=NoMovementScanDirection)
840+
if (!ScanDirectionIsNoMovement(direction))
841841
{
842842
if (nprocessed>0&&portal->atEnd)
843843
{
@@ -890,13 +890,13 @@ RunFromStore(Portal portal, ScanDirection direction, long count,
890890

891891
(*dest->rStartup) (dest,CMD_SELECT,portal->tupDesc);
892892

893-
if (direction==NoMovementScanDirection)
893+
if (ScanDirectionIsNoMovement(direction))
894894
{
895895
/* do nothing except start/stop the destination */
896896
}
897897
else
898898
{
899-
boolforward= (direction==ForwardScanDirection);
899+
boolforward=ScanDirectionIsForward(direction);
900900

901901
for (;;)
902902
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp