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

ANY_VALUE function does not suppress group by errors #8161

Closed
morgo opened this issue Nov 3, 2018 · 3 comments
Closed

ANY_VALUE function does not suppress group by errors #8161

morgo opened this issue Nov 3, 2018 · 3 comments
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@morgo
Copy link
Contributor

morgo commented Nov 3, 2018

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?

Make sure sql_mode='ONLY_FULL_GROUP_BY' to start. Then:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL);
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
SELECT COUNT(*) AS c, b FROM t1 GROUP BY a;
SELECT COUNT(*) AS c, ANY_VALUE(b) FROM t1 GROUP BY a;
  1. What did you expect to see?
mysql57> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.06 sec)

mysql57> CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL);
Query OK, 0 rows affected (0.16 sec)

mysql57> INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql57> SELECT COUNT(*) AS c, b FROM t1 GROUP BY a;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t1.b' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
mysql57> SELECT COUNT(*) AS c, ANY_VALUE(b) FROM t1 GROUP BY a;
+---+--------------+
| c | ANY_VALUE(b) |
+---+--------------+
| 1 |            1 |
| 1 |            2 |
| 1 |            3 |
+---+--------------+
3 rows in set (0.00 sec)
  1. What did you see instead?
tidb> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.81 sec)

tidb> CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL);
Query OK, 0 rows affected (0.48 sec)

tidb> INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
Query OK, 3 rows affected (0.16 sec)

tidb> SELECT COUNT(*) AS c, b FROM t1 GROUP BY a;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'b' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
tidb> SELECT COUNT(*) AS c, ANY_VALUE(b) FROM t1 GROUP BY a;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ANY_VALUE(b)' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
tidb> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v2.1.0-rc.3-140-g47ac8aef1-dirty
Git Commit Hash: 47ac8aef1971b84b317b3179c1d2e4ce06468eb8
Git Branch: only-full-group-by
UTC Build Time: 2018-11-03 10:06:03
GoVersion: go version go1.11 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false
1 row in set (0.01 sec)
@morgo morgo added the type/bug The issue is confirmed as a bug. label Nov 3, 2018
@zz-jason zz-jason added sig/execution SIG execution help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Nov 3, 2018
@spongedu
Copy link
Contributor

spongedu commented Feb 6, 2019

@morgo I've fixed this issue in #9255 . PTAL.
I've try to open some test settings modified in #8163, but not complete. I think we should look back and take a look after #9255 is merged.

@morgo
Copy link
Contributor Author

morgo commented Feb 7, 2019

Sounds good to me. Thank you for working on this!

@morgo
Copy link
Contributor Author

morgo commented Feb 13, 2019

Verified that the test case works as expected:

tidb> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.00 sec)

tidb> CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL);
Query OK, 0 rows affected (0.01 sec)

tidb> INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

tidb> SELECT COUNT(*) AS c, b FROM t1 GROUP BY a;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'b' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
tidb> SELECT COUNT(*) AS c, ANY_VALUE(b) FROM t1 GROUP BY a;
+------+--------------+
| c    | ANY_VALUE(b) |
+------+--------------+
|    1 |            2 |
|    1 |            3 |
|    1 |            1 |
+------+--------------+
3 rows in set (0.00 sec)

@morgo morgo closed this as completed Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants