-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: allow EXPLAIN on multi-statement SQL beginning with SET #20106
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
431c4d2
to
4dabdf0
Compare
4dabdf0
to
77d7577
Compare
SQL strings containing multiple statements cause problems with the ex- isting explain logic. This change adds a regex to strip an arbitrary number of `SET` commands from the head of all incoming SQL, such that the eventual `EXPLAIN` will be performed on just the trailing SQL. This doesn't fully address all multi-statement SQL strings: in part- icular clients might send e.g. both a SELECT and an UPDATE in the same string. As before, this would be passed as-is to the EXPLAIN machinery. Refs: DBMON-2626
77d7577
to
f37b43b
Compare
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.
Trim leading SET
statement would make it pass _can_explain_statement
. Can you add an integration test to make sure explain will work with multi statements?
If it's not feasible to do it with integration test and you tested it manually, can you add a screenshot instead?
@@ -748,6 +748,8 @@ def _run_and_track_explain(self, dbname, statement, obfuscated_statement, query_ | |||
|
|||
@tracked_method(agent_check_getter=agent_check_getter) | |||
def _run_explain_safe(self, dbname, statement, obfuscated_statement, query_signature): | |||
obfuscated_statement = trim_leading_set_stmts(obfuscated_statement) |
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.
Can we consider only run trim_leading_set_stmts
if the obfuscated_statement
starts with SET
?
What does this PR do?
SQL strings containing multiple statements cause problems with the existing explain logic. This change adds a regex to strip an arbitrary number of
SET
commands from the head of all incoming SQL, such that the eventualEXPLAIN
will be performed on just the trailing SQL.This doesn't fully address all multi-statement SQL strings: in particular, clients might send e.g. both a SELECT and an UPDATE in the same string. As before, this would be passed as-is to the EXPLAIN machinery.
Motivation
DBMON-2626
Review checklist (to be filled by reviewers)
qa/skip-qa
label if the PR doesn't need to be tested during QA.backport/<branch-name>
label to the PR and it will automatically open a backport PR once this one is merged