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

bug: UNION NULL value returns incorrect result set #1167

Open
2 of 3 tasks
davidshiz opened this issue Dec 29, 2022 · 7 comments
Open
2 of 3 tasks

bug: UNION NULL value returns incorrect result set #1167

davidshiz opened this issue Dec 29, 2022 · 7 comments
Assignees
Labels
A-bug Something isn't working B-SQL SQL layer prio: high High priority

Comments

@davidshiz
Copy link
Collaborator

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

  • I confirm there is no existing issue for this

Describe the problem

mysql> create table t2 (a int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t2 values (120), (0), (111);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select NULL union select a+0 from t2;
+------+
| NULL |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

Expected behavior

mysql> select NULL union select a+0 from t2;
+------+
| NULL |
+------+
| NULL |
|  120 |
|    0 |
|  111 |
+------+
4 rows in set (0.00 sec)

How To Reproduce

create table t2 (a int);
insert into t2 values (120), (0), (111);
select NULL union select a+0 from t2;

Environment

[root@localhost ~]# /opt/stonedb57/install/bin/mysqld --version
/opt/stonedb57/install/bin/mysqld  Ver 5.7.36-StoneDB for Linux on x86_64 (build-)
build information as follow:
        Repository address: https://github.com/stoneatom/stonedb.git:HEAD
        Branch name: HEAD
        Last commit ID: b44a51ce8
        Last commit time: Date:   Fri Dec 2 16:11:06 2022 +0000
        Build time: Date: Mon Dec  5 06:12:44 UTC 2022
[root@localhost ~]# cat /etc/system-release
CentOS Linux release 7.9.2009 (Core)

Are you interested in submitting a PR to solve the problem?

  • Yes, I will!
@davidshiz davidshiz added the A-bug Something isn't working label Dec 29, 2022
@RingsC RingsC added the prio: high High priority label Jan 6, 2023
@RingsC RingsC added this to the stonedb_5.7_v1.0.3 milestone Jan 6, 2023
@lujiashun
Copy link

ACK

@wisehead wisehead added the B-SQL SQL layer label Jan 9, 2023
@lujiashun
Copy link

In function Engine::Execute, to check the "// 1. all tables are derived and derived tables has no from table,// 2. fields of derived tables has sp", it seems we should use lex->all_selects_list instead of lex->select_lex;

@lujiashun
Copy link

lujiashun commented Jan 14, 2023

Check Engine::Execute, the logic to decide the way to mysql or to tianmu, (condition 1 or condition 2)
condition 1. if all the table is derived and all the tables has not from table;
condition 2. if any table has sp item;

In the two scenario,
scenario 1. table 1 is derived table and has sp, table 2 is not derived
scenario 2. talbe 1 is not derived, table 2 is derived table and has sp;

for scenario 1, the return value is "to mysql" according to the code logic;
for scenario 2, the return values is "to tianmu" according to the code logic;

the table order decides the return values, is the logic correct? @adofsauron

@adofsauron
Copy link
Collaborator

That should be correct. That's what the comment says

  // 1. all tables are derived and derived tables has no from table
  // 2. fields of derived tables has sp

@lujiashun
Copy link

crash in this sql:
select * from (select NULL union select a+0 from t2)t3;

@lujiashun
Copy link

lujiashun commented Jan 17, 2023

mysql> select a +0 from t2 union select NULL from t2 union select null from t2;
+------+
| a +0 |
+------+
|  120 |
|    0 |
|  111 |
| NULL |
+------+
4 rows in set (0.01 sec)

@lujiashun
Copy link

carsh in this SQL:
select "a" from t2 limit 0;

lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Jan 29, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Jan 29, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
Nliver pushed a commit to lujiashun/stonedb that referenced this issue Jan 30, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
@hustjieke hustjieke added B-storage data type, data storage, insert,update,delete, transactions and removed B-storage data type, data storage, insert,update,delete, transactions labels Jan 30, 2023
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 8, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 8, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 9, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 13, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 16, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 16, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Feb 16, 2023
, stoneatom#1168)

1. add system table sys_tianmu.dual which has only and must has one row.
2. in sql parse stage, if the sql is select clause and the related tables's storage is tianmu,
   if the select clause without from clause, rewrite the sql, add from clause "from sys_tianmu.dual"
3. in mysql_test, the system table is initialized in install.db directory,and copy to the mysql_test base_dir,
   if the file is symbol link, the destination file will be regular file, so change the Path.pm to copy symbol
   link file;
@hustjieke hustjieke moved this to In Progress in StoneDB for MySQL 5.7 Apr 18, 2023
@hustjieke hustjieke self-assigned this Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bug Something isn't working B-SQL SQL layer prio: high High priority
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

6 participants