@@ -259,6 +259,53 @@ add_query_text(int qhash, const char *query_string)
259259 return true;
260260}
261261
262+
263+ static ArrayType *
264+ form_oids_vector (List * relids )
265+ {
266+ Datum * oids ;
267+ ArrayType * array ;
268+ ListCell * lc ;
269+ int i = 0 ;
270+
271+ if (relids == NIL )
272+ return NULL ;
273+
274+ oids = (Datum * ) palloc (list_length (relids ) * sizeof (Datum ));
275+
276+ foreach (lc , relids )
277+ {
278+ Oid relid = lfirst_oid (lc );
279+
280+ oids [i ++ ] = ObjectIdGetDatum (relid );
281+ }
282+
283+ Assert (i == list_length (relids ));
284+ array = construct_array (oids , i , OIDOID , sizeof (Oid ), true, TYPALIGN_INT );
285+ pfree (oids );
286+ return array ;
287+ }
288+
289+ static List *
290+ deform_oids_vector (Datum datum )
291+ {
292+ ArrayType * array = DatumGetArrayTypePCopy (PG_DETOAST_DATUM (datum ));
293+ Datum * values ;
294+ int i ;
295+ int nelems = 0 ;
296+ List * relids = NIL ;
297+
298+ deconstruct_array (array ,
299+ OIDOID , sizeof (Oid ), true, TYPALIGN_INT ,
300+ & values , NULL , & nelems );
301+ for (i = 0 ; i < nelems ; ++ i )
302+ relids = lappend_oid (relids , DatumGetObjectId (values [i ]));
303+
304+ pfree (values );
305+ pfree (array );
306+ return relids ;
307+ }
308+
262309/*
263310 * Loads feature subspace (fss) from table aqo_data into memory.
264311 * The last column of the returned matrix is for target values of objects.
@@ -275,7 +322,8 @@ add_query_text(int qhash, const char *query_string)
275322 */
276323bool
277324load_fss (int fhash , int fss_hash ,
278- int ncols , double * * matrix , double * targets , int * rows )
325+ int ncols , double * * matrix , double * targets , int * rows ,
326+ List * * relids )
279327{
280328 RangeVar * rv ;
281329 Relation hrel ;
@@ -287,8 +335,8 @@ load_fss(int fhash, int fss_hash,
287335 Oid reloid ;
288336 IndexScanDesc scan ;
289337 ScanKeyData key [2 ];
290- Datum values [5 ];
291- bool isnull [5 ];
338+ Datum values [6 ];
339+ bool isnull [6 ];
292340 bool success = true;
293341
294342 reloid = RelnameGetRelid ("aqo_fss_access_idx" );
@@ -330,6 +378,9 @@ load_fss(int fhash, int fss_hash,
330378 <
684D
span class=pl-en>deform_matrix(values [3 ], matrix );
331379
332380 deform_vector (values [4 ], targets , rows );
381+
382+ if (relids != NULL )
383+ * relids = deform_oids_vector (values [5 ]);
333384 }
334385 else
335386 elog (ERROR , "unexpected number of features for hash (%d, %d):\
@@ -361,7 +412,7 @@ load_fss(int fhash, int fss_hash,
361412 */
362413bool
363414update_fss (int fhash , int fsshash , int nrows , int ncols ,
364- double * * matrix , double * targets )
415+ double * * matrix , double * targets , List * relids )
365416{
366417 RangeVar * rv ;
367418 Relation hrel ;
@@ -371,9 +422,9 @@ update_fss(int fhash, int fsshash, int nrows, int ncols,
371422 TupleDesc tupDesc ;
372423 HeapTuple tuple ,
373424 nw_tuple ;
374- Datum values [5 ];
375- bool isnull [5 ] = { false, false, false, false, false };
376- bool replace [5 ] = { false, false, false, true, true };
425+ Datum values [6 ];
426+ bool isnull [6 ] = { false, false, false, false, false, false };
427+ bool replace [6 ] = { false, false, false, true, true, false };
377428 bool shouldFree ;
378429 bool find_ok = false;
379430 bool update_indexes ;
@@ -421,6 +472,11 @@ update_fss(int fhash, int fsshash, int nrows, int ncols,
421472 isnull [3 ] = true;
422473
423474 values [4 ] = PointerGetDatum (form_vector (targets , nrows ));
475+
476+ /* Form array of relids. Only once. */
477+ values [5 ] = PointerGetDatum (form_oids_vector (relids ));
478+ if ((void * ) values [5 ] == NULL )
479+ isnull [5 ] = true;
424480 tuple = heap_form_tuple (tupDesc , values , isnull );
425481
426482 /*
0 commit comments