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

Commit3856cf9

Browse files
committed
Remove should_free arguments to tuplesort routines.
Since commite94568e, the answer isalways "false", and we do not need to complicate the API by arrangingto return a constant value.Peter GeogheganDiscussion:http://postgr.es/m/CAM3SWZQWZZ_N=DmmL7tKy_OUjGH_5mN=N=A6h7kHyyDvEhg2DA@mail.gmail.com
1 parent9b3d02c commit3856cf9

File tree

5 files changed

+31
-73
lines changed

5 files changed

+31
-73
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,13 @@ void
104104
_h_indexbuild(HSpool*hspool)
105105
{
106106
IndexTupleitup;
107-
boolshould_free;
108107
#ifdefUSE_ASSERT_CHECKING
109108
uint32hashkey=0;
110109
#endif
111110

112111
tuplesort_performsort(hspool->sortstate);
113112

114-
while ((itup=tuplesort_getindextuple(hspool->sortstate,
115-
true,&should_free))!=NULL)
113+
while ((itup=tuplesort_getindextuple(hspool->sortstate, true))!=NULL)
116114
{
117115
/*
118116
* Technically, it isn't critical that hash keys be found in sorted
@@ -129,7 +127,5 @@ _h_indexbuild(HSpool *hspool)
129127
#endif
130128

131129
_hash_doinsert(hspool->index,itup);
132-
if (should_free)
133-
pfree(itup);
134130
}
135131
}

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
680680
boolmerge= (btspool2!=NULL);
681681
IndexTupleitup,
682682
itup2=NULL;
683-
boolshould_free,
684-
should_free2,
685-
load1;
683+
boolload1;
686684
TupleDesctupdes=RelationGetDescr(wstate->index);
687685
inti,
688686
keysz=RelationGetNumberOfAttributes(wstate->index);
@@ -697,10 +695,8 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
697695
*/
698696

699697
/* the preparation of merge */
700-
itup=tuplesort_getindextuple(btspool->sortstate,
701-
true,&should_free);
702-
itup2=tuplesort_getindextuple(btspool2->sortstate,
703-
true,&should_free2);
698+
itup=tuplesort_getindextuple(btspool->sortstate, true);
699+
itup2=tuplesort_getindextuple(btspool2->sortstate, true);
704700
indexScanKey=_bt_mkscankey_nodata(wstate->index);
705701

706702
/* Prepare SortSupport data for each column */
@@ -775,18 +771,12 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
775771
if (load1)
776772
{
777773
_bt_buildadd(wstate,state,itup);
778-
if (should_free)
779-
pfree(itup);
780-
itup=tuplesort_getindextuple(btspool->sortstate,
781-
true,&should_free);
774+
itup=tuplesort_getindextuple(btspool->sortstate, true);
782775
}
783776
else
784777
{
785778
_bt_buildadd(wstate,state,itup2);
786-
if (should_free2)
787-
pfree(itup2);
788-
itup2=tuplesort_getindextuple(btspool2->sortstate,
789-
true,&should_free2);
779+
itup2=tuplesort_getindextuple(btspool2->sortstate, true);
790780
}
791781
}
792782
pfree(sortKeys);
@@ -795,15 +785,13 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
795785
{
796786
/* merge is unnecessary */
797787
while ((itup=tuplesort_getindextuple(btspool->sortstate,
798-
true,&should_free))!=NULL)
788+
true))!=NULL)
799789
{
800790
/* When we see first tuple, create first index page */
801791
if (state==NULL)
802792
state=_bt_pagestate(wstate,0);
803793

804794
_bt_buildadd(wstate,state,itup);
805-
if (should_free)
806-
pfree(itup);
807795
}
808796
}
809797

‎src/backend/commands/cluster.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,21 +1057,17 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
10571057
for (;;)
10581058
{
10591059
HeapTupletuple;
1060-
boolshouldfree;
10611060

10621061
CHECK_FOR_INTERRUPTS();
10631062

1064-
tuple=tuplesort_getheaptuple(tuplesort, true,&shouldfree);
1063+
tuple=tuplesort_getheaptuple(tuplesort, true);
10651064
if (tuple==NULL)
10661065
break;
10671066

10681067
reform_and_rewrite_tuple(tuple,
10691068
oldTupDesc,newTupDesc,
10701069
values,isnull,
10711070
NewHeap->rd_rel->relhasoids,rwstate);
1072-
1073-
if (shouldfree)
1074-
heap_freetuple(tuple);
10751071
}
10761072

10771073
tuplesort_end(tuplesort);

‎src/backend/utils/sort/tuplesort.c

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,12 +1841,12 @@ tuplesort_performsort(Tuplesortstate *state)
18411841
/*
18421842
* Internal routine to fetch the next tuple in either forward or back
18431843
* direction into *stup. Returns FALSE if no more tuples.
1844-
*If *should_free is set, the caller must pfree stup.tuple when done with it.
1845-
*Otherwise, caller should not use tuple following next call here.
1844+
*Returned tuple belongs to tuplesort memory context, and must not be freed
1845+
*by caller. Caller should not use tuple following next call here.
18461846
*/
18471847
staticbool
18481848
tuplesort_gettuple_common(Tuplesortstate*state,boolforward,
1849-
SortTuple*stup,bool*should_free)
1849+
SortTuple*stup)
18501850
{
18511851
unsignedinttuplen;
18521852

@@ -1855,7 +1855,6 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward,
18551855
caseTSS_SORTEDINMEM:
18561856
Assert(forward||state->randomAccess);
18571857
Assert(!state->slabAllocatorUsed);
1858-
*should_free= false;
18591858
if (forward)
18601859
{
18611860
if (state->current<state->memtupcount)
@@ -1927,7 +1926,6 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward,
19271926
*/
19281927
state->lastReturnedTuple=stup->tuple;
19291928

1930-
*should_free= false;
19311929
return true;
19321930
}
19331931
else
@@ -2008,14 +2006,12 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward,
20082006
*/
20092007
state->lastReturnedTuple=stup->tuple;
20102008

2011-
*should_free= false;
20122009
return true;
20132010

20142011
caseTSS_FINALMERGE:
20152012
Assert(forward);
20162013
/* We are managing memory ourselves, with the slab allocator. */
20172014
Assert(state->slabAllocatorUsed);
2018-
*should_free= false;
20192015

20202016
/*
20212017
* The slab slot holding the tuple that we returned in previous
@@ -2097,9 +2093,8 @@ tuplesort_gettupleslot(Tuplesortstate *state, bool forward,
20972093
{
20982094
MemoryContextoldcontext=MemoryContextSwitchTo(state->sortcontext);
20992095
SortTuplestup;
2100-
boolshould_free;
21012096

2102-
if (!tuplesort_gettuple_common(state,forward,&stup,&should_free))
2097+
if (!tuplesort_gettuple_common(state,forward,&stup))
21032098
stup.tuple=NULL;
21042099

21052100
MemoryContextSwitchTo(oldcontext);
@@ -2110,12 +2105,8 @@ tuplesort_gettupleslot(Tuplesortstate *state, bool forward,
21102105
if (state->sortKeys->abbrev_converter&&abbrev)
21112106
*abbrev=stup.datum1;
21122107

2113-
if (!should_free)
2114-
{
2115-
stup.tuple=heap_copy_minimal_tuple((MinimalTuple)stup.tuple);
2116-
should_free= true;
2117-
}
2118-
ExecStoreMinimalTuple((MinimalTuple)stup.tuple,slot,should_free);
2108+
stup.tuple=heap_copy_minimal_tuple((MinimalTuple)stup.tuple);
2109+
ExecStoreMinimalTuple((MinimalTuple)stup.tuple,slot, true);
21192110
return true;
21202111
}
21212112
else
@@ -2127,18 +2118,17 @@ tuplesort_gettupleslot(Tuplesortstate *state, bool forward,
21272118

21282119
/*
21292120
* Fetch the next tuple in either forward or back direction.
2130-
* Returns NULL if no more tuples. If *should_free is set, the
2131-
* caller must pfree the returned tuple when done with it.
2132-
* If it is not set, caller should not use tuple following next
2133-
* call here.
2121+
* Returns NULL if no more tuples. Returned tuple belongs to tuplesort memory
2122+
* context, and must not be freed by caller. Caller should not use tuple
2123+
* following next call here.
21342124
*/
21352125
HeapTuple
2136-
tuplesort_getheaptuple(Tuplesortstate*state,boolforward,bool*should_free)
2126+
tuplesort_getheaptuple(Tuplesortstate*state,boolforward)
21372127
{
21382128
MemoryContextoldcontext=MemoryContextSwitchTo(state->sortcontext);
21392129
SortTuplestup;
21402130

2141-
if (!tuplesort_gettuple_common(state,forward,&stup,should_free))
2131+
if (!tuplesort_gettuple_common(state,forward,&stup))
21422132
stup.tuple=NULL;
21432133

21442134
MemoryContextSwitchTo(oldcontext);
@@ -2148,19 +2138,17 @@ tuplesort_getheaptuple(Tuplesortstate *state, bool forward, bool *should_free)
21482138

21492139
/*
21502140
* Fetch the next index tuple in either forward or back direction.
2151-
* Returns NULL if no more tuples. If *should_free is set, the
2152-
* caller must pfree the returned tuple when done with it.
2153-
* If it is not set, caller should not use tuple following next
2154-
* call here.
2141+
* Returns NULL if no more tuples. Returned tuple belongs to tuplesort memory
2142+
* context, and must not be freed by caller. Caller should not use tuple
2143+
* following next call here.
21552144
*/
21562145
IndexTuple
2157-
tuplesort_getindextuple(Tuplesortstate*state,boolforward,
2158-
bool*should_free)
2146+
tuplesort_getindextuple(Tuplesortstate*state,boolforward)
21592147
{
21602148
MemoryContextoldcontext=MemoryContextSwitchTo(state->sortcontext);
21612149
SortTuplestup;
21622150

2163-
if (!tuplesort_gettuple_common(state,forward,&stup,should_free))
2151+
if (!tuplesort_gettuple_common(state,forward,&stup))
21642152
stup.tuple=NULL;
21652153

21662154
MemoryContextSwitchTo(oldcontext);
@@ -2173,7 +2161,8 @@ tuplesort_getindextuple(Tuplesortstate *state, bool forward,
21732161
* Returns FALSE if no more datums.
21742162
*
21752163
* If the Datum is pass-by-ref type, the returned value is freshly palloc'd
2176-
* and is now owned by the caller.
2164+
* and is now owned by the caller (this differs from similar routines for
2165+
* other types of tuplesorts).
21772166
*
21782167
* Caller may optionally be passed back abbreviated value (on TRUE return
21792168
* value) when abbreviation was used, which can be used to cheaply avoid
@@ -2188,9 +2177,8 @@ tuplesort_getdatum(Tuplesortstate *state, bool forward,
21882177
{
21892178
MemoryContextoldcontext=MemoryContextSwitchTo(state->sortcontext);
21902179
SortTuplestup;
2191-
boolshould_free;
21922180

2193-
if (!tuplesort_gettuple_common(state,forward,&stup,&should_free))
2181+
if (!tuplesort_gettuple_common(state,forward,&stup))
21942182
{
21952183
MemoryContextSwitchTo(oldcontext);
21962184
return false;
@@ -2208,11 +2196,7 @@ tuplesort_getdatum(Tuplesortstate *state, bool forward,
22082196
else
22092197
{
22102198
/* use stup.tuple because stup.datum1 may be an abbreviation */
2211-
2212-
if (should_free)
2213-
*val=PointerGetDatum(stup.tuple);
2214-
else
2215-
*val=datumCopy(PointerGetDatum(stup.tuple), false,state->datumTypeLen);
2199+
*val=datumCopy(PointerGetDatum(stup.tuple), false,state->datumTypeLen);
22162200
*isNull= false;
22172201
}
22182202

@@ -2270,16 +2254,12 @@ tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward)
22702254
while (ntuples-->0)
22712255
{
22722256
SortTuplestup;
2273-
boolshould_free;
22742257

2275-
if (!tuplesort_gettuple_common(state,forward,
2276-
&stup,&should_free))
2258+
if (!tuplesort_gettuple_common(state,forward,&stup))
22772259
{
22782260
MemoryContextSwitchTo(oldcontext);
22792261
return false;
22802262
}
2281-
if (should_free&&stup.tuple)
2282-
pfree(stup.tuple);
22832263
CHECK_FOR_INTERRUPTS();
22842264
}
22852265
MemoryContextSwitchTo(oldcontext);

‎src/include/utils/tuplesort.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ extern void tuplesort_performsort(Tuplesortstate *state);
9494

9595
externbooltuplesort_gettupleslot(Tuplesortstate*state,boolforward,
9696
TupleTableSlot*slot,Datum*abbrev);
97-
externHeapTupletuplesort_getheaptuple(Tuplesortstate*state,boolforward,
98-
bool*should_free);
99-
externIndexTupletuplesort_getindextuple(Tuplesortstate*state,boolforward,
100-
bool*should_free);
97+
externHeapTupletuplesort_getheaptuple(Tuplesortstate*state,boolforward);
98+
externIndexTupletuplesort_getindextuple(Tuplesortstate*state,boolforward);
10199
externbooltuplesort_getdatum(Tuplesortstate*state,boolforward,
102100
Datum*val,bool*isNull,Datum*abbrev);
103101

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp