Summary
get_foreign_keys() is missing the @reflection.cache decorator, causing a fresh DESCRIBE TABLE EXTENDED query to be issued to the SQL warehouse for every table on every reflection call.
Expected behaviour
Like get_pk_constraint(), has_table(), and get_table_comment(), get_foreign_keys() should be cached per-table per-connection so that DESCRIBE TABLE EXTENDED is only executed once per table during a reflection pass.
Actual behaviour
Every call to get_foreign_keys() unconditionally executes:
DESCRIBE TABLE EXTENDED `catalog`.`schema`.`table`
When reflecting schemas with many tables (or when reflection is triggered repeatedly, e.g. on each request in a web application), this produces a large number of redundant warehouse queries.
Root cause
base.py — get_foreign_keys() at line 256 lacks @reflection.cache. Compare with get_pk_constraint() (line 211) which uses the same _describe_table_extended() helper but is correctly decorated.
Fix
Add @reflection.cache to get_foreign_keys().
Summary
get_foreign_keys()is missing the@reflection.cachedecorator, causing a freshDESCRIBE TABLE EXTENDEDquery to be issued to the SQL warehouse for every table on every reflection call.Expected behaviour
Like
get_pk_constraint(),has_table(), andget_table_comment(),get_foreign_keys()should be cached per-table per-connection so thatDESCRIBE TABLE EXTENDEDis only executed once per table during a reflection pass.Actual behaviour
Every call to
get_foreign_keys()unconditionally executes:When reflecting schemas with many tables (or when reflection is triggered repeatedly, e.g. on each request in a web application), this produces a large number of redundant warehouse queries.
Root cause
base.py—get_foreign_keys()at line 256 lacks@reflection.cache. Compare withget_pk_constraint()(line 211) which uses the same_describe_table_extended()helper but is correctly decorated.Fix
Add
@reflection.cachetoget_foreign_keys().