Skip to content

Commit

Permalink
Cache table AM in Chunk struct
Browse files Browse the repository at this point in the history
A chunk can use different table access methods so to support this more
easily, cache the AM oid in the chunk struct. This allows identifying
the access method quickly at, e.g., planning time.
  • Loading branch information
erimatnor committed Sep 19, 2024
1 parent 616080e commit 8f47bc2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,7 @@ chunk_tuple_found(TupleInfo *ti, void *arg)
chunk->hypertable_relid = ts_hypertable_id_to_relid(chunk->fd.hypertable_id, false);

chunk->relkind = get_rel_relkind(chunk->table_id);
chunk->amoid = ts_get_rel_am(chunk->table_id);

Ensure(chunk->relkind > 0,
"relkind for chunk \"%s\".\"%s\" is invalid",
Expand Down
1 change: 1 addition & 0 deletions src/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef struct Chunk
char relkind;
Oid table_id;
Oid hypertable_relid;
Oid amoid; /* Table access method used by chunk */

/*
* The hypercube defines the chunks position in the N-dimensional space.
Expand Down
22 changes: 22 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1748,3 +1748,25 @@ ts_update_placeholder(PG_FUNCTION_ARGS)
elog(ERROR, "this stub function is used only as placeholder during extension updates");
PG_RETURN_NULL();
}

/*
* Get the table access method Oid for a relation.
*/
Oid
ts_get_rel_am(Oid relid)
{
HeapTuple tuple;
Form_pg_class cform;
Oid amoid;

tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));

if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for relation %u", relid);

cform = (Form_pg_class) GETSTRUCT(tuple);
amoid = cform->relam;
ReleaseSysCache(tuple);

return amoid;
}
2 changes: 2 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,5 @@ ts_datum_set_objectid(const AttrNumber attno, NullableDatum *datums, const Oid v
else
datums[AttrNumberGetAttrOffset(attno)].isnull = true;
}

extern Oid ts_get_rel_am(Oid relid);

0 comments on commit 8f47bc2

Please sign in to comment.