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

fix: Address performance regression introduced in #11785 #20893

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jul 27, 2022

SUMMARY

This PR fixes a SQL Lab performance regression introduced in https://github.com/apache/superset/pull/11785—a mere two years ago—which impacts the populating the tables in the SQL Lab LHS.

Specially at Airbnb for the Presto database the following line

dataset_tables = {table.name: table for table in database.tables} 

would take over 5 seconds to execute given we have over 100,000 tables registered with said database in Superset. The fix is to bypass the SQLAlchemy ORM and fetch only the subset of relevant tables using the SQLAlchemy Query API. The resulting refactor reduced the statement execution time down to << 0.01 seconds.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

if not self.schema:
return self.table_name
return "{}.{}".format(self.schema, self.table_name)
return self.schema + "." + self.table_name if self.schema else self.table_name
Copy link
Member Author

Choose a reason for hiding this comment

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

The logic needed to be translated into a function that SQLAlchemy could understand as we're using this hybrid property as a filter.

@john-bodley john-bodley force-pushed the john-bodley--optimize-sqllab-table-metadata branch from 422a29d to 37a19c4 Compare July 27, 2022 23:19
@john-bodley john-bodley marked this pull request as ready for review July 27, 2022 23:52
@john-bodley john-bodley requested review from etr2460 and ktmud July 27, 2022 23:52
@codecov
Copy link

codecov bot commented Jul 28, 2022

Codecov Report

Merging #20893 (e738f8c) into master (383313b) will decrease coverage by 11.47%.
The diff coverage is 78.57%.

❗ Current head e738f8c differs from pull request most recent head a9d2e54. Consider uploading reports for the commit a9d2e54 to get more accurate results

@@             Coverage Diff             @@
##           master   #20893       +/-   ##
===========================================
- Coverage   66.27%   54.80%   -11.48%     
===========================================
  Files        1758     1758               
  Lines       67072    67072               
  Branches     7122     7122               
===========================================
- Hits        44453    36759     -7694     
- Misses      20800    28494     +7694     
  Partials     1819     1819               
Flag Coverage Δ
hive 53.25% <64.28%> (+<0.01%) ⬆️
mysql ?
postgres ?
presto 53.15% <64.28%> (+<0.01%) ⬆️
python 57.84% <78.57%> (-23.72%) ⬇️
sqlite ?
unit 50.25% <78.57%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/dashboards/api.py 51.15% <0.00%> (-41.33%) ⬇️
superset/views/core.py 34.39% <0.00%> (-41.20%) ⬇️
superset/connectors/sqla/models.py 77.85% <100.00%> (-12.49%) ⬇️
superset/models/sql_lab.py 74.16% <100.00%> (-4.59%) ⬇️
superset/utils/core.py 62.88% <100.00%> (-27.35%) ⬇️
superset/utils/dashboard_import_export.py 0.00% <0.00%> (-100.00%) ⬇️
superset/key_value/commands/update.py 0.00% <0.00%> (-88.89%) ⬇️
superset/key_value/commands/delete.py 0.00% <0.00%> (-85.30%) ⬇️
superset/key_value/commands/delete_expired.py 0.00% <0.00%> (-80.77%) ⬇️
superset/dashboards/commands/importers/v0.py 15.62% <0.00%> (-76.25%) ⬇️
... and 283 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@john-bodley john-bodley force-pushed the john-bodley--optimize-sqllab-table-metadata branch 2 times, most recently from 25dbfcd to 64e5572 Compare July 28, 2022 04:28
@pull-request-size pull-request-size bot added size/M and removed size/S labels Jul 28, 2022
@john-bodley john-bodley force-pushed the john-bodley--optimize-sqllab-table-metadata branch from 64e5572 to a9d2e54 Compare July 28, 2022 04:56
Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

thanks for the fix!

@john-bodley john-bodley merged commit 50d2e5a into apache:master Jul 29, 2022
@john-bodley john-bodley deleted the john-bodley--optimize-sqllab-table-metadata branch July 29, 2022 05:56
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants