Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache table AM in Chunk struct #7284

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some observations on this:

  1. I think you should add this to ts_chunk_scan_by_chunk_ids as well. Probably a good idea to do a catalog lookup once, because the relkind and amoid are in the same pg_class catalog. Maybe you can make a function and use it here and there as well.

  2. It's not failing, so this means it's dead code now. Let's add some assertion that this is not null to improve test coverage.


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