Description:
When query cache is enabled, queries which contain CURRENT_USER() are cached and thus return wrong results.
How to repeat:
Enable query cache on your server.
Connect under some user (e.g. root) and do:
drop table if exists t1;
create table t1 select 1;
select *, user() from t1;
#+---+----------------+
#| 1 | user() |
#+---+----------------+
#| 1 | root@localhost |
#+---+----------------+
select *, current_user() from t1;
#+---+----------------+
#| 1 | current_user() |
#+---+----------------+
#| 1 | root@localhost |
#+---+----------------+
Now connect under another user (e.g. anonymous) and do:
select *, user() from t1;
#+---+---------------+
#| 1 | user() |
#+---+---------------+
#| 1 | zzz@localhost |
#+---+---------------+
select *, current_user() from t1;
#+---+----------------+
#| 1 | current_user() |
#+---+----------------+
#| 1 | root@localhost |
#+---+----------------+
# This is wrong!
select current_user();
#+----------------+
#| current_user() |
#+----------------+
#| @localhost |
#+----------------+
# And this is right value of current_user()
Suggested fix:
Do not cache queries containing CURRENT_USER() function as we do it for queries with USER() function...