Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MXS-2759: Optimize user loading query
The SQL for the second recursive CTE table can be optimized by adding a
where condition on the recursive part that rules out users that are not
roles. The functionality remains the same as only roles can be granted to
users.
  • Loading branch information
markus456 committed Nov 29, 2019
1 parent d41975d commit 374d5b2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/modules/authenticator/MySQLAuth/dbusers.cc
Expand Up @@ -77,14 +77,15 @@ const char* mariadb_102_users_query =
"), users AS ("
// Select the root row, the actual user
" SELECT t.user, t.host, t.db, t.select_priv, t.password, t.default_role AS role FROM t"
" WHERE t.is_role <> 'Y'"
" WHERE t.is_role = 'N'"
" UNION"
// Recursively select all roles for the users
" SELECT u.user, u.host, t.db, t.select_priv, u.password, r.role FROM t"
" JOIN users AS u"
" ON (t.user = u.role)"
" LEFT JOIN mysql.roles_mapping AS r"
" ON (t.user = r.user)"
" WHERE t.is_role = 'Y'"
")"
"SELECT DISTINCT t.user, t.host, t.db, t.select_priv, t.password FROM users AS t %s";

Expand Down

0 comments on commit 374d5b2

Please sign in to comment.