Skip to content

Commit

Permalink
Merge pull request #33 from CloverHealth/index-foreign-keys-0.3.x
Browse files Browse the repository at this point in the history
Add indices on history table foreign keys (0.3.x backport)
  • Loading branch information
pauljz authored Aug 10, 2017
2 parents 426b303 + 02c7709 commit 53630ff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions temporal_sqlalchemy/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ def _exclusion_in(type_, name) -> typing.Tuple:


@_exclusion_in.register(sap.UUID)
def _(type_, name):
def _exclusion_in_uuid(type_, name):
"""
Cast UUIDs to text for our exclusion index because postgres doesn't
currently allow GiST indices on UUIDs.
"""
return sa.cast(sa.text(name), sap.TEXT), '='


Expand All @@ -287,7 +291,9 @@ def build_history_table(
table_name = truncate_identifier(
_generate_history_table_name(local_table, columns)
)
entity_foreign_keys = list(util.foreign_key_to(local_table))
# Build the foreign key(s), specifically adding an index since we may use
# a casted foreign key in our constraints. See _exclusion_in_uuid
entity_foreign_keys = list(util.foreign_key_to(local_table, index=True))
entity_constraints = [
_exclusion_in(fk.type, fk.key)
for fk in entity_foreign_keys
Expand Down

0 comments on commit 53630ff

Please sign in to comment.