@@ -138,7 +138,7 @@ SampleRows(IvfflatBuildState * buildstate)
138
138
* Add tuple to sort
139
139
*/
140
140
static void
141
- AddTupleToSort (Relation index ,ItemPointer tid ,Datum * values ,bool * isnull , IvfflatBuildState * buildstate )
141
+ AddTupleToSort (Relation index ,ItemPointer tid ,Datum * values ,IvfflatBuildState * buildstate )
142
142
{
143
143
double distance ;
144
144
double minDistance = DBL_MAX ;
@@ -184,11 +184,6 @@ AddTupleToSort(Relation index, ItemPointer tid, Datum *values, bool *isnull, Ivf
184
184
slot -> tts_isnull [1 ]= false;
185
185
slot -> tts_values [2 ]= value ;
186
186
slot -> tts_isnull [2 ]= false;
187
- for (int i = 1 ;i < buildstate -> tupdesc -> natts ;i ++ )
188
- {
189
- slot -> tts_values [2 + i ]= values [i ];
190
- slot -> tts_isnull [2 + i ]= isnull [i ];
191
- }
192
187
ExecStoreVirtualTuple (slot );
193
188
194
189
/*
@@ -220,7 +215,7 @@ BuildCallback(Relation index, ItemPointer tid, Datum *values,
220
215
oldCtx = MemoryContextSwitchTo (buildstate -> tmpCtx );
221
216
222
217
/* Add tuple to sort */
223
- AddTupleToSort (index ,tid ,values ,isnull , buildstate );
218
+ AddTupleToSort (index ,tid ,values ,buildstate );
224
219
225
220
/* Reset memory context */
226
221
MemoryContextSwitchTo (oldCtx );
@@ -231,20 +226,19 @@ BuildCallback(Relation index, ItemPointer tid, Datum *values,
231
226
* Get index tuple from sort state
232
227
*/
233
228
static inline void
234
- GetNextTuple (Tuplesortstate * sortstate ,TupleDesc tupdesc ,TupleTableSlot * slot ,Datum * values , bool * isnull , IndexTuple * itup ,int * list )
229
+ GetNextTuple (Tuplesortstate * sortstate ,TupleDesc tupdesc ,TupleTableSlot * slot ,IndexTuple * itup ,int * list )
235
230
{
236
231
if (tuplesort_gettupleslot (sortstate , true, false,slot ,NULL ))
237
232
{
238
- bool unused ;
233
+ Datum value ;
234
+ bool isnull ;
239
235
240
- * list = DatumGetInt32 (slot_getattr (slot ,1 ,& unused ));
241
-
242
- for (int i = 0 ;i < tupdesc -> natts ;i ++ )
243
- values [i ]= slot_getattr (slot ,3 + i ,& isnull [i ]);
236
+ * list = DatumGetInt32 (slot_getattr (slot ,1 ,& isnull ));
237
+ value = slot_getattr (slot ,3 ,& isnull );
244
238
245
239
/* Form the index tuple */
246
- * itup = index_form_tuple (tupdesc ,values , isnull );
247
- (* itup )-> t_tid = * ((ItemPointer )DatumGetPointer (slot_getattr (slot ,2 ,& unused )));
240
+ * itup = index_form_tuple (tupdesc ,& value , & isnull );
241
+ (* itup )-> t_tid = * ((ItemPointer )DatumGetPointer (slot_getattr (slot ,2 ,& isnull )));
248
242
}
249
243
else
250
244
* list = -1 ;
@@ -262,14 +256,12 @@ InsertTuples(Relation index, IvfflatBuildState * buildstate, ForkNumber forkNum)
262
256
263
257
TupleTableSlot * slot = MakeSingleTupleTableSlot (buildstate -> sortdesc ,& TTSOpsMinimalTuple );
264
258
TupleDesc tupdesc = buildstate -> tupdesc ;
265
- Datum * values = palloc (tupdesc -> natts * sizeof (Datum ));
266
- bool * isnull = palloc (tupdesc -> natts * sizeof (bool ));
267
259
268
260
pgstat_progress_update_param (PROGRESS_CREATEIDX_SUBPHASE ,PROGRESS_IVFFLAT_PHASE_LOAD );
269
261
270
262
pgstat_progress_update_param (PROGRESS_CREATEIDX_TUPLES_TOTAL ,buildstate -> indtuples );
271
263
272
- GetNextTuple (buildstate -> sortstate ,tupdesc ,slot ,values , isnull , & itup ,& list );
264
+ GetNextTuple (buildstate -> sortstate ,tupdesc ,slot ,& itup ,& list );
273
265
274
266
for (int i = 0 ;i < buildstate -> centers -> length ;i ++ )
275
267
{
@@ -305,7 +297,7 @@ InsertTuples(Relation index, IvfflatBuildState * buildstate, ForkNumber forkNum)
305
297
306
298
pgstat_progress_update_param (PROGRESS_CREATEIDX_TUPLES_DONE ,++ inserted );
307
299
308
- GetNextTuple (buildstate -> sortstate ,tupdesc ,slot ,values , isnull , & itup ,& list );
300
+ GetNextTuple (buildstate -> sortstate ,tupdesc ,slot ,& itup ,& list );
309
301
}
310
302
311
303
insertPage = BufferGetBlockNumber (buf );
@@ -315,9 +307,6 @@ InsertTuples(Relation index, IvfflatBuildState * buildstate, ForkNumber forkNum)
315
307
/* Set the start and insert pages */
316
308
IvfflatUpdateList (index ,buildstate -> listInfo [i ],insertPage ,InvalidBlockNumber ,startPage ,forkNum );
317
309
}
318
-
319
- pfree (values );
320
- pfree (isnull );
321
310
}
322
311
323
312
/*
@@ -368,11 +357,10 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In
368
357
errmsg ("dimensions must be greater than one for this opclass" )));
369
358
370
359
/* Create tuple description for sorting */
371
- buildstate -> sortdesc = CreateTemplateTupleDesc (2 + buildstate -> tupdesc -> natts );
360
+ buildstate -> sortdesc = CreateTemplateTupleDesc (3 );
372
361
TupleDescInitEntry (buildstate -> sortdesc , (AttrNumber )1 ,"list" ,INT4OID ,-1 ,0 );
373
362
TupleDescInitEntry (buildstate -> sortdesc , (AttrNumber )2 ,"tid" ,TIDOID ,-1 ,0 );
374
- for (int i = 0 ;i < buildstate -> tupdesc -> natts ;i ++ )
375
- TupleDescInitEntry (buildstate -> sortdesc , (AttrNumber ) (3 + i ),NULL ,buildstate -> tupdesc -> attrs [i ].atttypid ,-1 ,0 );
363
+ TupleDescInitEntry (buildstate -> sortdesc , (AttrNumber )3 ,"vector" ,buildstate -> tupdesc -> attrs [0 ].atttypid ,-1 ,0 );
376
364
377
365
buildstate -> slot = MakeSingleTupleTableSlot (buildstate -> sortdesc ,& TTSOpsVirtual );
378
366