-
Notifications
You must be signed in to change notification settings - Fork 2.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
perf: cache reserved bind variables in queries #7698
Conversation
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
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.
Overall looks good.
I have one question.
Can the reserved Bindvars be exposed as a method on Statement Interface than passing it through all the methods?
@harshit-gangal: that was the first design I attempted: type BindableStatement struct {
Statement
KnownBinds BindVars
} I tried wrapping all the statements that had bindable variables with a |
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.
more conflicts to resolve
Description
This week we're starting our performance mission earlier with a long-standing TODO from @sougou in the SQL parser:
GetBindvars
is not as cheap as it could be. It is, in fact, quite expensive! Walking the AST is hard! If we look at a profile for aNormalize
benchmark, we find a surprising result:GetBindvars
accounts for almost 50% the time spent when normalizing a query! And we're doing it twice in the normal flow of a request: once when normalizing the incoming query, and again in the planbuilder when rewriting the query into its final plan. @sougou is quite right that "ideally, this should be done only once"... But we can do even better: ideally this shouldn't be done at all!This PR removes all the usages of
GetBindvars
from the codebase -- instead, it updates our SQL grammar so it keeps track of the bind variables as it finds them while parsing. Then, we propagate these reserved variable names everywhere they are needed. A bit verbose, but it makes normalization twice as fast (as one would expect from looking at the flame graph):Obviously, this is in a synthetic benchmark -- in a production environment, the speedup will be even more significant because we're no longer calling
GetBindvars
redundantly from the query planner.Related Issue(s)
Checklist
Deployment Notes
Impacted Areas in Vitess
Components that this PR will affect: