@@ -141,7 +141,8 @@ bool optimize_bounded_sort = true;
141
141
* which is a separate palloc chunk --- we assume it is just one chunk and
142
142
* can be freed by a simple pfree() (except during merge, when we use a
143
143
* simple slab allocator). SortTuples also contain the tuple's first key
144
- * column in Datum/nullflag format, and an index integer.
144
+ * column in Datum/nullflag format, and a source/input tape number that
145
+ * tracks which tape each heap element/slot belongs to during merging.
145
146
*
146
147
* Storing the first key column lets us save heap_getattr or index_getattr
147
148
* calls during tuple comparisons. We could extract and save all the key
@@ -162,16 +163,13 @@ bool optimize_bounded_sort = true;
162
163
* either the same pointer as "tuple", or is an abbreviated key value as
163
164
* described above. Accordingly, "tuple" is always used in preference to
164
165
* datum1 as the authoritative value for pass-by-reference cases.
165
- *
166
- * tupindex holds the input tape number that each tuple in the heap was read
167
- * from during merge passes.
168
166
*/
169
167
typedef struct
170
168
{
171
169
void * tuple ; /* the tuple itself */
172
170
Datum datum1 ; /* value of first key column */
173
171
bool isnull1 ; /* is first key column NULL? */
174
- int tupindex ; /* see notes above */
172
+ int srctape ; /* source tape number */
175
173
} SortTuple ;
176
174
177
175
/*
@@ -2093,7 +2091,7 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward,
2093
2091
*/
2094
2092
if (state -> memtupcount > 0 )
2095
2093
{
2096
- int srcTape = state -> memtuples [0 ].tupindex ;
2094
+ int srcTape = state -> memtuples [0 ].srctape ;
2097
2095
SortTuple newtup ;
2098
2096
2099
2097
* stup = state -> memtuples [0 ];
@@ -2124,7 +2122,7 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward,
2124
2122
LogicalTapeRewindForWrite (state -> tapeset , srcTape );
2125
2123
return true;
2126
2124
}
2127
- newtup .tupindex = srcTape ;
2125
+ newtup .srctape = srcTape ;
2128
2126
tuplesort_heap_replace_top (state , & newtup );
2129
2127
return true;
2130
2128
}
@@ -2808,7 +2806,7 @@ mergeonerun(Tuplesortstate *state)
2808
2806
SortTuple stup ;
2809
2807
2810
2808
/* write the tuple to destTape */
2811
- srcTape = state -> memtuples [0 ].tupindex ;
2809
+ srcTape = state -> memtuples [0 ].srctape ;
2812
2810
WRITETUP (state , destTape , & state -> memtuples [0 ]);
2813
2811
2814
2812
/* recycle the slot of the tuple we just wrote out, for the next read */
@@ -2821,7 +2819,7 @@ mergeonerun(Tuplesortstate *state)
2821
2819
*/
2822
2820
if (mergereadnext (state , srcTape , & stup ))
2823
2821
{
2824
- stup .tupindex = srcTape ;
2822
+ stup .srctape = srcTape ;
2825
2823
tuplesort_heap_replace_top (state , & stup );
2826
2824
}
2827
2825
else
@@ -2886,7 +2884,7 @@ beginmerge(Tuplesortstate *state)
2886
2884
2887
2885
if (mergereadnext (state , srcTape , & tup ))
2888
2886
{
2889
- tup .tupindex = srcTape ;
2887
+ tup .srctape = srcTape ;
2890
2888
tuplesort_heap_insert (state , & tup );
2891
2889
}
2892
2890
}
0 commit comments