-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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: Missing sql_editor_id index #27392
fix: Missing sql_editor_id index #27392
Conversation
@justinpark you'll also have to:
Creating a new index to the |
|
||
def upgrade(): | ||
op.create_index( | ||
op.f("ix_query_sql_editor_id"), "query", ["sql_editor_id"], unique=False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this index be on the (user_id
, sql_editor_id
) tuple instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@john-bodley We have agreed to use a single key index rather than these composite keys. Could you please confirm the agreement here?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #27392 +/- ##
==========================================
+ Coverage 67.34% 69.71% +2.37%
==========================================
Files 1909 1909
Lines 74592 74616 +24
Branches 8320 8320
==========================================
+ Hits 50235 52022 +1787
+ Misses 22305 20542 -1763
Partials 2052 2052
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
From experience that table can get massive and depending on your SQL engine, and creating an index can be a locking operation, which can cascade into deadlock territory on this particular table (I think there's still a pretty crazy amount of polling happening in SQL Lab to look at query state). If you're using MySQL I'd treat this migration very very sensitively. I think there are ways to create index in a non-locking way in MySQL, but have to go out of your way to do it Maybe not a bad time to archive the query table table in your environment ... For most shops I think 90 days worth of query history is enough to go by, not a bad thing to schedule something that deletes 90+ day old queries daily... Note that |
@@ -86,7 +86,7 @@ class Query( | |||
user_id = Column(Integer, ForeignKey("ab_user.id"), nullable=True) | |||
status = Column(String(16), default=QueryStatus.PENDING) | |||
tab_name = Column(String(256)) | |||
sql_editor_id = Column(String(256)) | |||
sql_editor_id = Column(String(256), index=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that it's now a index on two columns you'll have to use the Index
function.
About my earlier comment, the issue may be significant enough that you'd want to write a custom migration for MySQL for your own sake at Airbnb, you can probably go direct DDL |
e249bed
to
fcf7a84
Compare
|
||
|
||
def upgrade(): | ||
op.create_index( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we skip the upgrade if the index already exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a commit to check for index existence.
a6ab95f
to
f91ce6d
Compare
5a38b9a
to
8a2c84e
Compare
8a2c84e
to
0dfc810
Compare
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
0dfc810
to
1d19118
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #27392 +/- ##
==========================================
+ Coverage 60.48% 69.98% +9.49%
==========================================
Files 1931 1933 +2
Lines 76236 76498 +262
Branches 8568 8566 -2
==========================================
+ Hits 46114 53539 +7425
+ Misses 28017 20855 -7162
+ Partials 2105 2104 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com> Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com> Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com> Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com> Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
SUMMARY
As titled, it adds the index for
sql_editor_id
in query table which seems to have caused a slowdown in the sqllab_bootstrap query.TESTING INSTRUCTIONS
locally test
superset db upgrade
ADDITIONAL INFORMATION