Skip to content

get_foreign_keys() missing @reflection.cache causes excessive DESCRIBE TABLE EXTENDED queries #72

Description

@gdubya

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.pyget_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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions