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

wrong result and panic when joining dual table #12065

Closed
jingyugao opened this issue Sep 6, 2019 · 6 comments
Closed

wrong result and panic when joining dual table #12065

jingyugao opened this issue Sep 6, 2019 · 6 comments
Assignees
Labels
challenge-program duplicate Issues or pull requests already exists. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@jingyugao
Copy link
Contributor

jingyugao commented Sep 6, 2019

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
select null in (select 1 );
select a in (select 0) xx from (select null as a) x;
  1. What did you expect to see?
mysql [localhost:5731] {msandbox} (test) > select null in (select 1 );
+---------------------+
| null in (select 1 ) |
+---------------------+
|                NULL |
+---------------------+
1 row in set (0.00 sec)

mysql [localhost:5731] {msandbox} (test) > select a in (select 0) xx from (select null as a) x;
+------+
| xx   |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
  1. What did you see instead?
mysql> select null in (select 1 );
+---------------------+
| null in (select 1 ) |
+---------------------+
|                   0 |
+---------------------+
1 row in set (0.00 sec)

mysql> select a in (select 0) xx from (select null as a) x;
+------+
| xx   |
+------+
| NULL |
+------+
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)?
    5.7.25-TiDB-v4.0.0-alpha-201-g702854f02

SIG slack channel

#sig-exec

Score

  • 300

Mentor

@jingyugao jingyugao added the type/bug The issue is confirmed as a bug. label Sep 6, 2019
@jingyugao
Copy link
Contributor Author

select a in (select 0)xx from (select null as a)x

This sql will cause panic

@jingyugao jingyugao changed the title wrong reuslt of select null in (select 1) wrong reuslt and panic when joining dual table Sep 7, 2019
@shenli
Copy link
Member

shenli commented Sep 7, 2019

@jingyugao Nice catch! Would you like to fix it?

@jingyugao
Copy link
Contributor Author

@jingyugao Nice catch! Would you like to fix it?

I will have a try.

@fzhedu
Copy link
Contributor

fzhedu commented Nov 13, 2019

The running internals in MySQL is listed below:

mysql> explain select null in ( 1 )\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: NULL
   partitions: NULL
         type: NULL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: NULL
     filtered: NULL
        Extra: No tables used
1 row in set, 1 warning (0.00 sec)

mysql> show warnings\G
*************************** 1. row ***************************
  Level: Note
   Code: 1003
Message: /* select#1 */ select (NULL = 1) AS `null in ( 1 )`
1 row in set (0.00 sec)

mysql> explain select null in (select 1 )\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: NULL
   partitions: NULL
         type: NULL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: NULL
     filtered: NULL
        Extra: No tables used
1 row in set, 2 warnings (0.00 sec)

mysql> show warnings\G
*************************** 1. row ***************************
  Level: Note
   Code: 1249
Message: Select 2 was reduced during optimization
*************************** 2. row ***************************
  Level: Note
   Code: 1003
Message: /* select#1 */ select (NULL = 1) AS `null in (select 1 )`
2 rows in set (0.00 sec)

We can conclude that select 1 is converted to 1.
TiDB runs select null in (1) correctly, so it is necessary to rewrite select 1 to 1.

@zz-jason zz-jason added the sig/execution SIG execution label Mar 17, 2020
@SunRunAway SunRunAway added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Jun 1, 2020
@ghost
Copy link

ghost commented Aug 6, 2020

I believe this is a duplicate of #3773

@ghost ghost added the correctness label Aug 6, 2020
@ghost ghost changed the title wrong reuslt and panic when joining dual table wrong result and panic when joining dual table Aug 6, 2020
@shuke987
Copy link

duplicate with #3773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
challenge-program duplicate Issues or pull requests already exists. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

9 participants