-
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
[sqllab] Cancel database query on stop #7611
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7611 +/- ##
=========================================
- Coverage 73.75% 65.85% -7.9%
=========================================
Files 115 459 +344
Lines 12059 22019 +9960
Branches 0 2415 +2415
=========================================
+ Hits 8894 14501 +5607
- Misses 3165 7397 +4232
- Partials 0 121 +121
Continue to review full report at Codecov.
|
d39d6e8
to
5959314
Compare
rebased on master, fixed an issue for sync mode |
@mistercrunch any opinion how to proceed with this? Should I convert it into SIP? Or is it good as a PR? Maybe some changes are required (for example tests for which I would love some advice because I couldn't find tests for similar functionality) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue |
Superseeded by #8097 (?) |
@mistercrunch no. #8097 stops executing list of queries if one of them was stopped. This PR stops (kills) underlying connection to DB (no matter 1 or more queries are there). If you are interested in the fix, I can re-work it using |
It'd be great to enable the true killing of queries, sorry I missed this back in May... |
Cool. Thank you. I'll re-work this PR in the following days to avoid DB migration and make it more flexible. |
5959314
to
953a36e
Compare
SQL Lab has Stop button but it only updates state of superset without actually stopping the database query. Complex query can run in background for long time and affect database performance. This commits solves the problem as following: 1. Add new key `cancel_payload` into extra attribute of the Query instance. 2. Add `get_cancel_query_payload` method to EngineSpec that returns some payload from the connection which allows to cancel it later. 3. `execute_sql_statements` before executing queries retrieves and saves cancel payload into Query 4. Stop handler calls new `cancel_query` method of EngineSpec Both new methods are implemented only for MySQL for now but it is easy to add support for PostgreSQL, MSSQL and maybe some other DBs. For MySQL I use `KILL CONNECTION` to terminate multiple statements.
953a36e
to
085fff0
Compare
@mistercrunch I updated the code. It's simpler and more flexible now. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue |
CATEGORY
Choose one
SUMMARY
Sorry for submitting PR without creating an issue first. It doesn't look like a big change but I can convert the issue and proposal into SIP if needed.
The issue
SQL Lab has Stop button but it only updates state of superset without actually stopping the database query.
In some cases complex query can run in background for days and affect database performance.
The issue especially affect us as we use Superset with gitbase which speeks MySQL protocol.
This commit solves the problem as following:
cancel_payload
into extra attribute of the Query instance.get_cancel_query_payload
method to EngineSpec that returns somepayload from the connection which allows to cancel it later.
execute_sql_statements
before executing queries retrieves and savescancel payload into Query
cancel_query
method of EngineSpecBoth new methods are implemented only for MySQL for now but it is easy
to add support for PostgreSQL, MSSQL and maybe some other DBs.
For MySQL I use
KILL CONNECTION
to terminate multiple statements.Alternative approach:
Maintain list of open connections and close them on cancel.
This solutions looks cleaner but has some disadvantages:
close()
call.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TEST PLAN
Run complex log-running query with MySQL using SQL lab. Press stop. The query should be killed.
ADDITIONAL INFORMATION
REVIEWERS