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

current_user() function returns incorrect results #7613

Closed
morgo opened this issue Sep 5, 2018 · 4 comments · Fixed by #7801
Closed

current_user() function returns incorrect results #7613

morgo opened this issue Sep 5, 2018 · 4 comments · Fixed by #7801

Comments

@morgo
Copy link
Contributor

morgo commented Sep 5, 2018

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?

In TiDB, the current_user() function appears to just be an alias of the user() function. In MySQL these have differing behaviors.

  1. What did you expect to see?
mysql [localhost] {root} ((none)) > CREATE USER 'testuser';
Query OK, 0 rows affected (0.00 sec)

..

mysql [localhost] {testuser} ((none)) > SELECT USER(), CURRENT_USER();
+--------------------+----------------+
| USER()             | CURRENT_USER() |
+--------------------+----------------+
| testuser@localhost | testuser@%     |
+--------------------+----------------+
1 row in set (0.00 sec)

Note that current_user() shows the same user you would see in SHOW GRANTS. This is useful for corner cases where multiple users could apply (the MySQL privilege system is weird).

  1. What did you see instead?
MySQL [(none)]> SELECT USER(), CURRENT_USER();
+--------------------+--------------------+
| USER()             | CURRENT_USER()     |
+--------------------+--------------------+
| testuser@127.0.0.1 | testuser@127.0.0.1 |
+--------------------+--------------------+
1 row in set (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
Release Version: v2.1.0-rc.1-13-g1255973
Git Commit Hash: 1255973764f72575d71920b95fc0861d1677c6c5
Git Branch: master
UTC Build Time: 2018-08-28 07:35:57
GoVersion: go version go1.10.2 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false
@crazycs520
Copy link
Contributor

Thanks for your feedback.

@crazycs520
Copy link
Contributor

@tiancaiamao PTAL

@morgo
Copy link
Contributor Author

morgo commented Sep 5, 2018

Relates to #7614

@morgo
Copy link
Contributor Author

morgo commented Sep 9, 2018

There is a TODO on expression/builtin_info.go:151 from 2015-09-23 11:02:45 +0800 that shows this is a known issue:

// TODO: The value of CURRENT_USER() can differ from the value of USER(). We will finish this after we support grant tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants