Skip to content

SQL query improvements in utils/db.py#32518

Merged
uranusjr merged 1 commit into
apache:mainfrom
astronomer:sql-improve
Jul 11, 2023
Merged

SQL query improvements in utils/db.py#32518
uranusjr merged 1 commit into
apache:mainfrom
astronomer:sql-improve

Conversation

@uranusjr

@uranusjr uranusjr commented Jul 11, 2023

Copy link
Copy Markdown
Member

As mentioned in #32177.

  • Move some imports to type-checking block to avoid runtime cost
  • Use SELECT 1 to avoid loading ORM model objects unnecessarily
  • Use scalars(...) to avoid needing to unpack ORM models
  • Use table.c[key] instead of getattr(table.c, key). They work basically the same, except getattr is worse for this purpose (potential name conflicts)
  • Use generators when the arguments are immediately unpacked into a function call so there's no need to produce an intermediate list

* Move some imports to type-checking block to avoid runtime cost
* Use SELECT 1 to avoid loading ORM model objects unnecessarily
* Use scalars() to avoid needing to unpack ORM models
* Use .c[key] instead of getattr(.c, key). They work basically the same,
  except getattr is worse for this purpose (potential name conflicts)
* Use generators when the arguments are immediately unpacked into a
  function call so there's no need to produce an intermediate list
@uranusjr
uranusjr merged commit 3f6ac2f into apache:main Jul 11, 2023
@uranusjr
uranusjr deleted the sql-improve branch July 11, 2023 10:58
@ephraimbuddy ephraimbuddy added this to the Airflow 2.7.0 milestone Aug 2, 2023
@ephraimbuddy ephraimbuddy added the type:misc/internal Changelog: Misc changes that should appear in change log label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:misc/internal Changelog: Misc changes that should appear in change log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants