29
29
#include <utils/snapmgr.h>
30
30
#include <utils/tuplestore.h>
31
31
32
+ #include "cache.h"
32
33
#include "continuous_aggs/invalidation_multi.h"
33
34
#include "continuous_aggs/invalidation_threshold.h"
34
35
#include "continuous_aggs/materialize.h"
@@ -1241,6 +1242,17 @@ continuous_agg_process_hypertable_invalidations_single(Oid hypertable_relid)
1241
1242
invalidation_process_hypertable_log (hypertable_id , dimtype );
1242
1243
}
1243
1244
1245
+ static void
1246
+ append_string_info_relid (StringInfo info , ListCell * lc )
1247
+ {
1248
+ Oid relid = lfirst_oid (lc );
1249
+ const char * name = get_rel_name (relid );
1250
+ if (name )
1251
+ appendStringInfo (info , "\"%s\"" , name );
1252
+ else
1253
+ appendStringInfo (info , "%d" , relid );
1254
+ }
1255
+
1244
1256
/*
1245
1257
* PostgreSQL function to move hypertable invalidations to materialization
1246
1258
* invalidation log.
@@ -1250,21 +1262,59 @@ continuous_agg_process_hypertable_invalidations_multi(ArrayType *hypertable_arra
1250
1262
{
1251
1263
ArrayIterator array_iterator = array_create_iterator (hypertable_array , 0 , NULL );
1252
1264
List * hypertables = NIL ;
1265
+ List * bad_objects = NIL ;
1253
1266
1254
1267
Datum value ;
1255
1268
bool isnull ;
1256
1269
while (array_iterate (array_iterator , & value , & isnull ))
1257
1270
{
1271
+ /* Function signature only allow OIDs, so we will always have an OID. */
1258
1272
Oid hypertable_relid = DatumGetObjectId (value );
1259
- int32 hypertable_id = ts_hypertable_relid_to_id (hypertable_relid );
1260
- TS_DEBUG_LOG ("add relation \"%s\" to list: hypertable_id=%d" ,
1261
- get_rel_name (hypertable_relid ),
1262
- hypertable_id );
1263
- ts_hypertable_permissions_check (hypertable_relid , GetUserId ());
1264
- hypertables = lappend_int (hypertables , hypertable_id );
1273
+ Cache * hcache ;
1274
+ Hypertable * ht = ts_hypertable_cache_get_cache_and_entry (hypertable_relid ,
1275
+ CACHE_FLAG_MISSING_OK ,
1276
+ & hcache );
1277
+ if (ht )
1278
+ {
1279
+ int32 hypertable_id = ht -> fd .id ;
1280
+ TS_DEBUG_LOG ("add relation \"%s\" to list: hypertable_id=%d" ,
1281
+ get_rel_name (hypertable_relid ),
1282
+ hypertable_id );
1283
+ ts_hypertable_permissions_check (hypertable_relid , GetUserId ());
1284
+ hypertables = lappend_int (hypertables , hypertable_id );
1285
+ }
1286
+ else
1287
+ {
1288
+ TS_DEBUG_LOG ("relation \"%s\" is not a hypertable" , get_rel_name (hypertable_relid ));
1289
+ bad_objects = lappend_oid (bad_objects , hypertable_relid );
1290
+ }
1291
+ ts_cache_release (& hcache );
1265
1292
}
1266
1293
1267
1294
array_free_iterator (array_iterator );
1268
1295
1296
+ const int bad_count = list_length (bad_objects );
1297
+ if (bad_count == 1 )
1298
+ {
1299
+ const Oid relid = linitial_oid (bad_objects );
1300
+ const char * name = get_rel_name (relid );
1301
+ if (name )
1302
+ ereport (ERROR ,
1303
+ errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1304
+ errmsg ("table \"%s\" is not a hypertable" , name ));
1305
+ else
1306
+ ereport (ERROR ,
1307
+ errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1308
+ errmsg ("OID %d is not a hypertable" , relid ));
1309
+ }
1310
+ else if (bad_count > 1 )
1311
+ {
1312
+ ereport (ERROR ,
1313
+ errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1314
+ errmsg ("%d objects in list are not hypertables" , bad_count ),
1315
+ errdetail ("Bad objects are %s." ,
1316
+ ts_list_to_string (bad_objects , append_string_info_relid )));
1317
+ }
1318
+
1269
1319
multi_invalidation_process_hypertable_log (hypertables );
1270
1320
}
0 commit comments