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:If the field you used in the join condition is primary key, using "NOT EXISTS" will return wrong result. #944

Closed
3 tasks done
haitaoguan opened this issue Nov 16, 2022 · 1 comment
Assignees
Labels
A-bug Something isn't working

Comments

@haitaoguan
Copy link
Collaborator

haitaoguan commented Nov 16, 2022

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

create table tt1(id int primary key,name varchar(5),copy_id int) engine=tianmu;
insert into tt1 values(1,'AAA',1),(2,'AAA',2),(3,'BBB',3),(4,'BBB',4),(5,'CCC',5);
create table tt2(id int primary key,name varchar(5),copy_id int) engine=tianmu;
insert into tt2 values(1,'BBB',1),(2,'BBB',2),(3,'CCC',3),(4,'CCC',4),(5,'DDD',5);
mysql> select *
    ->   from tt1
    ->  where not exists (select 1
    ->           from tt2
    ->          where tt1.id = tt2.id and name='BBB');
Empty set (0.00 sec)

If we set the parameter “tianmu_index_search=off", will return right result.

mysql> set global tianmu_index_search=off;
Query OK, 0 rows affected (0.00 sec)

mysql> select *
    ->   from tt1
    ->  where not exists (select 1
    ->           from tt2
    ->          where tt1.copy_id = tt2.copy_id and name='BBB');
+----+------+---------+
| id | name | copy_id |
+----+------+---------+
|  3 | BBB  |       3 |
|  4 | BBB  |       4 |
|  5 | CCC  |       5 |
+----+------+---------+
3 rows in set (0.00 sec)

If the field you used in the join condition is not an index column, using "NOT EXISTS" will return right result.Independent of parameters.

mysql> select *
    ->   from tt1
    ->  where not exists (select 1
    ->           from tt2
    ->          where tt1.copy_id = tt2.copy_id and name='BBB');
+----+------+---------+
| id | name | copy_id |
+----+------+---------+
|  3 | BBB  |       3 |
|  4 | BBB  |       4 |
|  5 | CCC  |       5 |
+----+------+---------+
3 rows in set (0.01 sec)

Expected behavior

mysql> select *
    ->   from tt1
    ->  where not exists (select 1
    ->           from tt2
    ->          where tt1.id = tt2.id and name='BBB');
+----+------+---------+
| id | name | copy_id |
+----+------+---------+
|  3 | BBB  |       3 |
|  4 | BBB  |       4 |
|  5 | CCC  |       5 |
+----+------+---------+
3 rows in set (0.00 sec)

How To Reproduce

No response

Environment

./mysqld Ver 5.7.36-StoneDB for Linux on x86_64 (build-)
build information as follow:
Repository address: https://github.com/stoneatom/stonedb.git:stonedb-5.7-dev
Branch name: stonedb-5.7-dev
Last commit ID: c91a29e
Last commit time: Date: Mon Oct 24 03:25:06 2022 +0000
Build time: Date: Mon 24 Oct 2022 11:09:00 AM UTC

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

  • Yes, I will!
@haitaoguan haitaoguan added the A-bug Something isn't working label Nov 16, 2022
@haitaoguan haitaoguan changed the title If the field you used in the join condition is indexed, using "NOT EXISTS" will return wrong result. If the field you used in the join condition is an index column, using "NOT EXISTS" will return wrong result. Nov 18, 2022
@haitaoguan haitaoguan changed the title If the field you used in the join condition is an index column, using "NOT EXISTS" will return wrong result. bug:If the field you used in the join condition is an index column, using "NOT EXISTS" will return wrong result. Nov 21, 2022
@haitaoguan haitaoguan changed the title bug:If the field you used in the join condition is an index column, using "NOT EXISTS" will return wrong result. bug:If the field you used in the join condition is primary key, using "NOT EXISTS" will return wrong result. Nov 29, 2022
@RingsC RingsC assigned adofsauron and RingsC and unassigned duanfuxiang0 Nov 29, 2022
@adofsauron
Copy link
Collaborator

the same as #971

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
Projects
None yet
Development

No branches or pull requests

4 participants