-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: cache role existence checks to fix perf regression #111934
Conversation
In 12ec26f, we started to check for the existence of a role whenever a privilege for the public role was checked. This can hapen multiple times during some pg_catalog queries, so it introduced a performance regression. Now, the role existence is cached so we avoid the penalty. The existence of a role is cached for the duration of the entire transaction, and also gets inherited by any internal executor used to implement a command run by the user's transaction. No release note since this is new in 23.2. Release note: None
7178d4b
to
cf61b37
Compare
func (p *planner) RoleExists(ctx context.Context, role username.SQLUsername) (bool, error) { | ||
return RoleExists(ctx, p.InternalSQLTxn(), role) | ||
cache := p.EvalContext().RoleExistsCache | ||
if cache != nil { |
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.
What causes the cache to be nil here?
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.
it shouldn't be nil, it was just a defensive check
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.
IMO defensive checks like this make the code harder to maintain because it is hard to tell the difference between something that is expected to be nil and a bug, but I'll leave it up to you if you want to keep it.
tftr bors r+ |
Build succeeded: |
In 12ec26f, we started to check for the existence of a role whenever a privilege for the public role was checked. This can hapen multiple times during some pg_catalog queries, so it introduced a performance regression.
Now, the role existence is cached so we avoid the penalty. The existence of a role is cached for the duration of the entire transaction, and also gets inherited by any internal executor used to implement a command run by the user's transaction.
No release note since this is new in 23.2.
informs #20718
fixes #112102
Release note: None