mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 18:43:18 +08:00
Add hypertable cache lookup on ID/pkey
Hypertables can now be looked up through the cache on ID/pkey in addition to OID.
This commit is contained in:
parent
f38a578578
commit
c4a46ac8a1
@ -32,6 +32,47 @@ hypertable_from_tuple(HeapTuple tuple)
|
||||
return h;
|
||||
}
|
||||
|
||||
static bool
|
||||
hypertable_tuple_get_relid(TupleInfo *ti, void *data)
|
||||
{
|
||||
FormData_hypertable *form = (FormData_hypertable *) GETSTRUCT(ti->tuple);
|
||||
Oid *relid = data;
|
||||
Oid schema_oid = get_namespace_oid(NameStr(form->schema_name), true);
|
||||
|
||||
if (OidIsValid(schema_oid))
|
||||
*relid = get_relname_relid(NameStr(form->table_name), schema_oid);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Oid
|
||||
hypertable_id_to_relid(int32 hypertable_id)
|
||||
{
|
||||
Catalog *catalog = catalog_get();
|
||||
Oid relid = InvalidOid;
|
||||
ScanKeyData scankey[1];
|
||||
ScannerCtx scanctx = {
|
||||
.table = catalog->tables[HYPERTABLE].id,
|
||||
.index = catalog->tables[HYPERTABLE].index_ids[HYPERTABLE_ID_INDEX],
|
||||
.scantype = ScannerTypeIndex,
|
||||
.nkeys = 1,
|
||||
.scankey = scankey,
|
||||
.tuple_found = hypertable_tuple_get_relid,
|
||||
.data = &relid,
|
||||
.lockmode = AccessShareLock,
|
||||
.scandirection = ForwardScanDirection,
|
||||
};
|
||||
|
||||
/* Perform an index scan on the hypertable pkey. */
|
||||
ScanKeyInit(&scankey[0], Anum_hypertable_pkey_idx_id,
|
||||
BTEqualStrategyNumber, F_INT4EQ,
|
||||
Int32GetDatum(hypertable_id));
|
||||
|
||||
scanner_scan(&scanctx);
|
||||
|
||||
return relid;
|
||||
}
|
||||
|
||||
typedef struct ChunkCacheEntry
|
||||
{
|
||||
MemoryContext mcxt;
|
||||
|
@ -22,6 +22,7 @@ typedef struct Hypertable
|
||||
extern Hypertable *hypertable_from_tuple(HeapTuple tuple);
|
||||
extern int hypertable_set_name(Hypertable *ht, const char *newname);
|
||||
extern int hypertable_set_schema(Hypertable *ht, const char *newname);
|
||||
extern Oid hypertable_id_to_relid(int32 hypertable_id);
|
||||
extern Chunk *hypertable_get_chunk(Hypertable *h, Point *point);
|
||||
extern Oid hypertable_relid(RangeVar *rv);
|
||||
extern bool is_hypertable(Oid relid);
|
||||
|
@ -65,7 +65,6 @@ hypertable_cache_create()
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
||||
static Cache *hypertable_cache_current = NULL;
|
||||
|
||||
static bool
|
||||
@ -83,7 +82,6 @@ hypertable_cache_create_entry(Cache *cache, CacheQuery *query)
|
||||
HypertableCacheQuery *hq = (HypertableCacheQuery *) query;
|
||||
Catalog *catalog = catalog_get();
|
||||
HypertableNameCacheEntry *cache_entry = query->result;
|
||||
Hypertable *ht;
|
||||
int number_found;
|
||||
ScanKeyData scankey[2];
|
||||
ScannerCtx scanCtx = {
|
||||
@ -123,8 +121,6 @@ hypertable_cache_create_entry(Cache *cache, CacheQuery *query)
|
||||
case 1:
|
||||
Assert(strncmp(cache_entry->hypertable->fd.schema_name.data, hq->schema, NAMEDATALEN) == 0);
|
||||
Assert(strncmp(cache_entry->hypertable->fd.table_name.data, hq->table, NAMEDATALEN) == 0);
|
||||
ht = cache_entry->hypertable;
|
||||
ht->space = dimension_scan(ht->fd.id, ht->main_table_relid, ht->fd.num_dimensions);
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "Got an unexpected number of records: %d", number_found);
|
||||
@ -158,6 +154,12 @@ hypertable_cache_get_entry_rv(Cache *cache, RangeVar *rv)
|
||||
return hypertable_cache_get_entry(cache, RangeVarGetRelid(rv, NoLock, true));
|
||||
}
|
||||
|
||||
Hypertable *
|
||||
hypertable_cache_get_entry_by_id(Cache *cache, int32 hypertable_id)
|
||||
{
|
||||
return hypertable_cache_get_entry(cache, hypertable_id_to_relid(hypertable_id));
|
||||
}
|
||||
|
||||
Hypertable *
|
||||
hypertable_cache_get_entry_with_table(Cache *cache, Oid relid, const char *schema, const char *table)
|
||||
{
|
||||
|
@ -8,6 +8,7 @@
|
||||
extern Hypertable *hypertable_cache_get_entry(Cache *cache, Oid relid);
|
||||
extern Hypertable *hypertable_cache_get_entry_rv(Cache *cache, RangeVar *rv);
|
||||
extern Hypertable *hypertable_cache_get_entry_with_table(Cache *cache, Oid relid, const char *schema, const char *table);
|
||||
extern Hypertable *hypertable_cache_get_entry_by_id(Cache *cache, int32 hypertable_id);
|
||||
|
||||
extern void hypertable_cache_invalidate_callback(void);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user