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

executor: some unexpected behaviors of TopN #15718

Closed
zhongzc opened this issue Mar 26, 2020 · 3 comments · Fixed by #16542 or tikv/tikv#7532
Closed

executor: some unexpected behaviors of TopN #15718

zhongzc opened this issue Mar 26, 2020 · 3 comments · Fixed by #16542 or tikv/tikv#7532
Assignees
Labels
severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@zhongzc
Copy link
Contributor

zhongzc commented Mar 26, 2020

Bug Report

1. What did you do?

Some logical operations in TopN executor are not working well.

  1. Order by first column with 1 column.
mysql root@127.0.0.1:test> SELECT `col_decimal` AND `col_varchar_1` AS field1, `col_decimal`, `col_varchar_1`, 1 FROM `table1000_int_autoinc` ORDER BY
                            field1 LIMIT 10;                                                                                                          
+--------+-------------+---------------+---+
| field1 | col_decimal | col_varchar_1 | 1 |
+--------+-------------+---------------+---+
| 0      | 53131       | 0             | 1 |
| <null> | 7           | <null>        | 1 |
| 0      | 54712       | r             | 1 |
| <null> | <null>      | 2             | 1 |
| 0      | 0           | 2             | 1 |
| 0      | <null>      | w             | 1 |
| 0      | 704905216   | j             | 1 |
| 0      | 0           | o             | 1 |
| 0      | 1514078208  | g             | 1 |
| 0      | 7           | g             | 1 |
+--------+-------------+---------------+---+
10 rows in set
Time: 0.066s
  1. Order by first column w/o 1 column.
mysql root@127.0.0.1:test> SELECT `col_decimal` AND `col_varchar_1` AS field1, `col_decimal`, `col_varchar_1` FROM `table1000_int_autoinc` ORDER BY fi
                           eld1 LIMIT 10;                                                                                                             
+--------+-------------+---------------+
| field1 | col_decimal | col_varchar_1 |
+--------+-------------+---------------+
| 0      | 7           | <null>        |
| 0      | 54712       | r             |
| 0      | <null>      | 2             |
| 0      | 0           | 2             |
| 0      | <null>      | w             |
| 0      | 704905216   | j             |
| 0      | 0           | o             |
| 0      | 1514078208  | g             |
| 0      | 7           | g             |
| 0      | 53131       | 0             |
+--------+-------------+---------------+

2. What did you expect to see?

What MySQL does:

mysql root@127.0.0.1:test> SELECT `col_decimal` AND `col_varchar_1` AS field1, `col_decimal`, `col_varchar_1`, 1 FROM `table1000_int_autoinc` ORDER BY
                            field1 LIMIT 10;                                                                                                          
+--------+-------------+---------------+---+
| field1 | col_decimal | col_varchar_1 | 1 |
+--------+-------------+---------------+---+
| <null> | <null>      | 2             | 1 |
| <null> | -589168640  | <null>        | 1 |
| <null> | <null>      | 2             | 1 |
| <null> | <null>      | 2             | 1 |
| <null> | 7           | <null>        | 1 |
| <null> | <null>      | 1             | 1 |
| <null> | 1616052224  | <null>        | 1 |
| <null> | <null>      | <null>        | 1 |
| <null> | <null>      | 5             | 1 |
| <null> | 7           | <null>        | 1 |
+--------+-------------+---------------+---+
10 rows in set
Time: 0.023s
mysql root@127.0.0.1:test> SELECT `col_decimal` AND `col_varchar_1` AS field1, `col_decimal`, `col_varchar_1` FROM `table1000_int_autoinc` ORDER BY fi
                           eld1 LIMIT 10;                                                                                                             
+--------+-------------+---------------+
| field1 | col_decimal | col_varchar_1 |
+--------+-------------+---------------+
| <null> | <null>      | 2             |
| <null> | -589168640  | <null>        |
| <null> | <null>      | 2             |
| <null> | <null>      | 2             |
| <null> | 7           | <null>        |
| <null> | <null>      | 1             |
| <null> | 1616052224  | <null>        |
| <null> | <null>      | <null>        |
| <null> | <null>      | 5             |
| <null> | 7           | <null>        |
+--------+-------------+---------------+
10 rows in set
Time: 0.024s

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

mysql root@127.0.0.1:test> select tidb_version();                                                                                                     
+-------------------------------------------------------------------+
| tidb_version()                                                    |
+-------------------------------------------------------------------+
| Release Version: v4.0.0-beta.2-89-g5cf0c3e2d                      |
| Git Commit Hash: 5cf0c3e2d4b12610b3be092a4e785488875b90bb         |
| Git Branch: master                                                |
| UTC Build Time: 2020-03-26 06:56:55                               |
| GoVersion: go1.13.8                                               |
| Race Enabled: false                                               |
| TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306 |
| Check Table Before Drop: false                                    |
+-------------------------------------------------------------------+
1 row in set
Time: 0.018s
@zhongzc zhongzc added the type/bug The issue is confirmed as a bug. label Mar 26, 2020
@zz-jason zz-jason added the sig/execution SIG execution label Mar 26, 2020
@XuHuaiyu
Copy link
Contributor

What about the result when using tikv?

@XuHuaiyu XuHuaiyu self-assigned this Mar 26, 2020
@zhongzc
Copy link
Contributor Author

zhongzc commented Mar 26, 2020

@XuHuaiyu

mysql>  SELECT `col_decimal` AND `col_varchar_1` AS field1, `col_decimal`, `col_varchar_1`, 1 FROM `table1000_int_autoinc` ORDER BY field1 LIMIT 10;   
+--------+-------------+---------------+---+
| field1 | col_decimal | col_varchar_1 | 1 |
+--------+-------------+---------------+---+
|   NULL |           7 | NULL          | 1 |
|      0 |       54712 | r             | 1 |
|   NULL |        NULL | 2             | 1 |
|      0 |           0 | 2             | 1 |
|      0 |        NULL | w             | 1 |
|      0 |   704905216 | j             | 1 |
|      0 |           0 | o             | 1 |
|      0 |  1514078208 | g             | 1 |
|      0 |           7 | g             | 1 |
|      0 |       53131 | 0             | 1 |
+--------+-------------+---------------+---+
10 rows in set, 75 warnings (0.06 sec)

mysql> SELECT `col_decimal` AND `col_varchar_1` AS field1, `col_decimal`, `col_varchar_1` FROM `table1000_int_autoinc` ORDER BY field1 LIMIT 10;   
+--------+-------------+---------------+
| field1 | col_decimal | col_varchar_1 |
+--------+-------------+---------------+
|      0 |           7 | NULL          |
|      0 |       54712 | r             |
|      0 |        NULL | 2             |
|      0 |           0 | 2             |
|      0 |        NULL | w             |
|      0 |   704905216 | j             |
|      0 |           0 | o             |
|      0 |  1514078208 | g             |
|      0 |           7 | g             |
|      0 |       53131 | 0             |
+--------+-------------+---------------+
10 rows in set, 76 warnings (0.06 sec)

@Reminiscent
Copy link
Contributor

Reminiscent commented Mar 30, 2020

minor case:

In my TiDB version(after fix the problom from expression evaltion):
With TiKV(the result same with mockTiKV)

MySQL [test]> create table tt(a decimal(10, 0), b varchar(1));
Query OK, 0 rows affected (0.28 sec)

MySQL [test]> insert into tt values(0, '2'), (7, null), (7, '3'), (NULL, 'w'), (NULL, '2'), (NULL, '2'), (NULL, NULL), (7, 'f');
Query OK, 8 rows affected (0.12 sec)
Records: 8  Duplicates: 0  Warnings: 0

MySQL [test]> select a and b as c, a, b from tt order by c limit 4;
+---+------+------+
| c | a    | b    |
+---+------+------+
| NULL |    7 | NULL |
| NULL | NULL | 2    |
| 0 |    0 | 2    |
| 0 | NULL | w    |
+---+------+------+
4 rows in set, 4 warnings (0.00 sec)

MySQL [test]> select a and b as c, a, b from tt order by c;
+---+------+------+
| c | a    | b    |
+---+------+------+
| NULL | NULL | NULL |
| NULL |    7 | NULL |
| NULL | NULL | 2    |
| NULL | NULL | 2    |
| 0 | NULL | w    |
| 0 |    0 | 2    |
| 0 |    7 | f    |
| 1 |    7 | 3    |
+---+------+------+
8 rows in set, 2 warnings (0.01 sec)

In mysql5.7:

mysql> create table tt(a decimal(10, 0), b varchar(1));
Query OK, 0 rows affected (0.03 sec)

mysql> insert into tt values(0, '2'), (7, null), (7, '3'), (NULL, 'w'), (NULL, '2'), (NULL, '2'), (NULL, NULL), (7, 'f'); 

Query OK, 8 rows affected (0.01 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> select a and b as c, a, b from tt order by c limit 4;
+------+------+------+
| c    | a    | b    |
+------+------+------+
| NULL |    7 | NULL |
| NULL | NULL | 2    |
| NULL | NULL | NULL |
| NULL | NULL | 2    |
+------+------+------+
4 rows in set, 2 warnings (0.00 sec)

mysql> select a and b as c, a, b from tt order by c;
+------+------+------+
| c    | a    | b    |
+------+------+------+
| NULL |    7 | NULL |
| NULL | NULL | 2    |
| NULL | NULL | 2    |
| NULL | NULL | NULL |
|    0 |    0 | 2    |
|    0 | NULL | w    |
|    0 |    7 | f    |
|    1 |    7 | 3    |
+------+------+------+
8 rows in set, 4 warnings (0.00 sec)

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