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

chore(data-warehouse): optimize databaseschemaquery #27977

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

EDsCODE
Copy link
Member

@EDsCODE EDsCODE commented Jan 28, 2025

Problem

  • database schema query was an n+3 db query

Changes

  • collapse queries into only 3

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?


# Fetch warehouse tables with related data in a single query
warehouse_tables_with_data = (
DataWarehouseTable.objects.select_related("credential", "external_data_source")
Copy link
Member Author

@EDsCODE EDsCODE Jan 28, 2025

Choose a reason for hiding this comment

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

i'm pretty rusty on exactly what django ORM spits out but this should be ultimately better than n+3 queries

@EDsCODE EDsCODE requested a review from a team January 28, 2025 17:55
Copy link
Contributor

@phixMe phixMe left a comment

Choose a reason for hiding this comment

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

Nice, should be a pretty big pref improvement!

@EDsCODE EDsCODE merged commit d383498 into master Jan 28, 2025
93 checks passed
@EDsCODE EDsCODE deleted the fix-database-schema-query-optimize branch January 28, 2025 18:41
@EDsCODE EDsCODE linked an issue Jan 28, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HogQL "DatabaseSchema" query is slow
3 participants