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

P1-[4.0 Bug Hunting]-[Window Function]-over function is weird #93

Open
zhangysh1995 opened this issue May 22, 2020 · 2 comments
Open

P1-[4.0 Bug Hunting]-[Window Function]-over function is weird #93

zhangysh1995 opened this issue May 22, 2020 · 2 comments

Comments

@zhangysh1995
Copy link

zhangysh1995 commented May 22, 2020

Bug Report

1. What did you do?

mysql> create table t(a int, b int);                                                                                                                                               Query OK, 0 rows affected (0.00 sec)   

mysql> insert into t values(1,2);
Query OK, 1 row affected (0.00 sec)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
mysql> insert into t values(4,5);
Query OK, 1 row affected (0.00 sec)
                                                                                                                                                                                                                                                    
mysql> select (select sum(a) over ())  from t ;
+-------------------------+
| (select sum(a) over ()) |
+-------------------------+
|                       1 |
|                    NULL |
+-------------------------+
2 rows in set (0.00 sec)

mysql> select sum(a) over ()  from t ;
+----------------+
| sum(a) over () |
+----------------+
|              5 |
|              5 |
+----------------+
2 rows in set (0.00 sec)

2. What did you expect to see?

mysql> select (select sum(a) over ())  from t ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '())  from t' at line 1

mysql> select sum(a) over ()  from t ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '()  from t' at line 1

3. What did you see instead?

The results don't make any sense.

4. What version of TiDB are you using? (tidb-server -V or run select tidb_version(); on TiDB)

Reproducible on master branch:

commit 38298c2e3e8ae6438b2b9caa696586087ea58a4d (HEAD -> master, origin/master, origin/HEAD)
Author: Zhuomin(Charming) Liu <[email protected]>
Date:   Fri May 22 17:40:10 2020 +0800
mysql> select tidb_version();                                                                                                                                                      
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------$--------------------------------------------------------+
| tidb_version()
                                                        |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------$--------------------------------------------------------+
| Release Version: None
Edition: None
Git Commit Hash: None
Git Branch: None
UTC Build Time: None
GoVersion: go1.13.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@zhangysh1995 zhangysh1995 changed the title [P0]-[4.0 Bug Hunting]-[Window Function]-over function is weird P1-[4.0 Bug Hunting]-[Window Function]-over function is weird May 22, 2020
@shuke987
Copy link

shuke987 commented Jun 2, 2020

/bug P1

@wwar
Copy link

wwar commented Jun 5, 2020

Window functions are a MySQL 8.0 feature. Both these queries actually work in MySQL 8, but the result of the first query is different, which I believe is a bug:

drop table if exists t;
create table t(a int, b int); 
insert into t values(1,2),(4,5);
select (select sum(a) over ())  from t ;
select sum(a) over ()  from t ;

..

mysql [localhost:8020] {msandbox} (test) > select (select sum(a) over ())  from t ;
+-------------------------+
| (select sum(a) over ()) |
+-------------------------+
|                       1 |
|                       4 |
+-------------------------+
2 rows in set (0.00 sec)

mysql [localhost:8020] {msandbox} (test) > select sum(a) over ()  from t ;
+----------------+
| sum(a) over () |
+----------------+
|              5 |
|              5 |
+----------------+
2 rows in set (0.00 sec)

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

No branches or pull requests

4 participants