Skip to content

Commit 38285aa

Browse files
committed
Revert "Updated IVFFlat to support multiple attributes (not enabled yet)"
This reverts commit 772ab69.
1 parent a2408e6 commit 38285aa

File tree

2 files changed

+14
-32
lines changed

2 files changed

+14
-32
lines changed

src/ivfbuild.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ SampleRows(IvfflatBuildState * buildstate)
138138
* Add tuple to sort
139139
*/
140140
static void
141-
AddTupleToSort(Relation index, ItemPointer tid, Datum *values, bool *isnull, IvfflatBuildState * buildstate)
141+
AddTupleToSort(Relation index, ItemPointer tid, Datum *values, IvfflatBuildState * buildstate)
142142
{
143143
double distance;
144144
double minDistance = DBL_MAX;
@@ -184,11 +184,6 @@ AddTupleToSort(Relation index, ItemPointer tid, Datum *values, bool *isnull, Ivf
184184
slot->tts_isnull[1] = false;
185185
slot->tts_values[2] = value;
186186
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-
}
192187
ExecStoreVirtualTuple(slot);
193188

194189
/*
@@ -220,7 +215,7 @@ BuildCallback(Relation index, ItemPointer tid, Datum *values,
220215
oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx);
221216

222217
/* Add tuple to sort */
223-
AddTupleToSort(index, tid, values, isnull, buildstate);
218+
AddTupleToSort(index, tid, values, buildstate);
224219

225220
/* Reset memory context */
226221
MemoryContextSwitchTo(oldCtx);
@@ -231,20 +226,19 @@ BuildCallback(Relation index, ItemPointer tid, Datum *values,
231226
* Get index tuple from sort state
232227
*/
233228
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)
235230
{
236231
if (tuplesort_gettupleslot(sortstate, true, false, slot, NULL))
237232
{
238-
bool unused;
233+
Datum value;
234+
bool isnull;
239235

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);
244238

245239
/* 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)));
248242
}
249243
else
250244
*list = -1;
@@ -262,14 +256,12 @@ InsertTuples(Relation index, IvfflatBuildState * buildstate, ForkNumber forkNum)
262256

263257
TupleTableSlot *slot = MakeSingleTupleTableSlot(buildstate->sortdesc, &TTSOpsMinimalTuple);
264258
TupleDesc tupdesc = buildstate->tupdesc;
265-
Datum *values = palloc(tupdesc->natts * sizeof(Datum));
266-
bool *isnull = palloc(tupdesc->natts * sizeof(bool));
267259

268260
pgstat_progress_update_param(PROGRESS_CREATEIDX_SUBPHASE, PROGRESS_IVFFLAT_PHASE_LOAD);
269261

270262
pgstat_progress_update_param(PROGRESS_CREATEIDX_TUPLES_TOTAL, buildstate->indtuples);
271263

272-
GetNextTuple(buildstate->sortstate, tupdesc, slot, values, isnull, &itup, &list);
264+
GetNextTuple(buildstate->sortstate, tupdesc, slot, &itup, &list);
273265

274266
for (int i = 0; i < buildstate->centers->length; i++)
275267
{
@@ -305,7 +297,7 @@ InsertTuples(Relation index, IvfflatBuildState * buildstate, ForkNumber forkNum)
305297

306298
pgstat_progress_update_param(PROGRESS_CREATEIDX_TUPLES_DONE, ++inserted);
307299

308-
GetNextTuple(buildstate->sortstate, tupdesc, slot, values, isnull, &itup, &list);
300+
GetNextTuple(buildstate->sortstate, tupdesc, slot, &itup, &list);
309301
}
310302

311303
insertPage = BufferGetBlockNumber(buf);
@@ -315,9 +307,6 @@ InsertTuples(Relation index, IvfflatBuildState * buildstate, ForkNumber forkNum)
315307
/* Set the start and insert pages */
316308
IvfflatUpdateList(index, buildstate->listInfo[i], insertPage, InvalidBlockNumber, startPage, forkNum);
317309
}
318-
319-
pfree(values);
320-
pfree(isnull);
321310
}
322311

323312
/*
@@ -368,11 +357,10 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In
368357
errmsg("dimensions must be greater than one for this opclass")));
369358

370359
/* Create tuple description for sorting */
371-
buildstate->sortdesc = CreateTemplateTupleDesc(2 + buildstate->tupdesc->natts);
360+
buildstate->sortdesc = CreateTemplateTupleDesc(3);
372361
TupleDescInitEntry(buildstate->sortdesc, (AttrNumber) 1, "list", INT4OID, -1, 0);
373362
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);
376364

377365
buildstate->slot = MakeSingleTupleTableSlot(buildstate->sortdesc, &TTSOpsVirtual);
378366

src/ivfinsert.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, R
7878
BlockNumber insertPage = InvalidBlockNumber;
7979
ListInfo listInfo;
8080
BlockNumber originalInsertPage;
81-
TupleDesc tupdesc = RelationGetDescr(index);
82-
Datum *newValues = palloc(tupdesc->natts * sizeof(Datum));
8381

8482
/* Detoast once for all calls */
8583
value = PointerGetDatum(PG_DETOAST_DATUM(values[0]));
@@ -104,12 +102,8 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, R
104102
Assert(BlockNumberIsValid(insertPage));
105103
originalInsertPage = insertPage;
106104

107-
newValues[0] = value;
108-
for (int i = 1; i < tupdesc->natts; i++)
109-
newValues[i] = values[i];
110-
111105
/* Form tuple */
112-
itup = index_form_tuple(tupdesc, newValues, isnull);
106+
itup = index_form_tuple(RelationGetDescr(index), &value, isnull);
113107
itup->t_tid = *heap_tid;
114108

115109
/* Get tuple size */

0 commit comments

Comments
 (0)