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

left join cause result duplicate #8499

Closed
allenliu88 opened this issue Nov 28, 2018 · 3 comments · Fixed by #8505
Closed

left join cause result duplicate #8499

allenliu88 opened this issue Nov 28, 2018 · 3 comments · Fixed by #8505
Assignees
Labels
sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@allenliu88
Copy link

allenliu88 commented Nov 28, 2018

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.
-- test data
drop table test_a;
create table test_a(user_config_id bigint(20) primary key, user_id bigint(20), tenant_id bigint(20), default_company_id bigint(20));
insert into test_a(user_config_id, user_id, tenant_id, default_company_id) values (120003, 1, 0, 0);
insert into test_a(user_config_id, user_id, tenant_id, default_company_id) values (120008, 1, 1, null);

select * from test_a;

drop table test_b;
create table test_b (company_id bigint(20) primary key, company_num varchar(30), tenant_id bigint(20));
insert into test_b(company_id, company_num, tenant_id) values (0, 'HZERO', 0);
select * from test_b;


-- test SQL
select huc.*, hc.company_id from test_a huc left join test_b hc on ((hc.company_id = huc.default_company_id or (hc.company_id is null and huc.default_company_id is null)) and hc.tenant_id = huc.tenant_id) where user_id = 1; -- No.1 result correct count 2

select huc.*, hc.company_id from test_a huc left join test_b hc on (hc.company_id = huc.default_company_id and hc.tenant_id = huc.tenant_id) where user_id = 1; -- No.2 result not correct 3
  1. What did you expect to see?
    expect No.2 query result size 2 not 3, because data of table test_a has only 2 row, and left join should not be duplicate.

  2. What did you see instead?
    No.2 query result size 3, has duplicate
    image

  3. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
    Release Version: None
    Git Commit Hash: 508f5dd
    Git Branch: master
    UTC Build Time: 2018-10-27 09:59:28
    GoVersion: go version go1.11 linux/amd64
    Race Enabled: false
    TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
    Check Table Before Drop: false

@XuHuaiyu
Copy link
Contributor

@AllenLiuGit Thanks for your feedback.
We'll investigate this.

@lastzero
Copy link

Great that you fixed this so fast! Still it surprises me that a bug like that was hiding in a stable database engine used by the financial services industry. Did I miss something here?

@shenli
Copy link
Member

shenli commented Dec 1, 2018

@lastzero Thanks for your comment!

We consider wrong results bugs to be high priority and action them immediately. In this case, the bug was caused by an incorrect optimization being applied (not all the user scenarios will meet this issue). The patch addresses the optimization so that it is handled correctly.

For the important users and critical scenario, we always work together with our customers to evaluate and test their application on TiDB. For the banks, we even help them to review their SQLs. They all use a more stable (but with less functionality) version (for now, it is 2.0.x). The strict test and cautious upgrading strategy are the two key factors to keep the banks' application safe. For the community users, some of them will use the latest version like 2.1.x or the latest master.

Building a distributed RDMS is a hard work. We benefit from the open source community. They help us to improve at an incredible speed. We encourage the community to try TiDB and report Bug/FeatureRequest through Github issue in a public way. And we also publish most of our development work through Github project/pr/issue. The community has the right to known what's going on in this database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants