Skip to content
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: avoid role existence check in DROP ROLE when it's not necessary #134979

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions pkg/sql/drop_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ func (n *DropRoleNode) startExec(params runParams) error {

// Non-admin users cannot drop admins.
if !hasAdmin {
roleExists, err := RoleExists(params.ctx, params.p.InternalSQLTxn(), name)
if err != nil {
return err
}
if !roleExists {
// If the role does not exist, we can skip the check for targetIsAdmin.
continue
if n.ifExists {
// If `IF EXISTS` was specified, then a non-existing role should be
// skipped without causing any error.
roleExists, err := RoleExists(params.ctx, params.p.InternalSQLTxn(), name)
if err != nil {
return err
}
if !roleExists {
// If the role does not exist, we can skip the check for targetIsAdmin.
continue
}
}

targetIsAdmin, err := params.p.UserHasAdminRole(params.ctx, name)
Expand Down
Loading