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: do not build range for NullOuterVal in IndexLookUpJoin #8505

Merged
merged 5 commits into from Nov 29, 2018

Conversation

Projects
None yet
4 participants
@XuHuaiyu
Contributor

XuHuaiyu commented Nov 29, 2018

What problem does this PR solve?

fix #8499

Before this PR, the result of the following query is wrong.

CREATE TABLE `t1` (
  `a` int(11) NOT NULL,
  `b` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`)
);
insert into t1 values(1, 0), (2, null);
CREATE TABLE `t2` (
  `a` int(11) NOT NULL,
  PRIMARY KEY (`a`)
);
insert into t2 values(0);
tidb> select /*+ TIDB_INLJ(t2)*/ * from t1 left join t2 on t1.b = t2.a;
+---+------+------+
| a | b    | a    |
+---+------+------+
| 1 |    0 |    0 |
| 1 |    0 |    0 |
| 2 | NULL | NULL |
+---+------+------+
3 rows in set (0.00 sec)

What is changed and how it works?

When the innerPlan is a TableReader, the range of PKHanle will be built in buildTableReaderForIndexJoin,
and NilDatum.GetInt64() will return 0. Thus we read the row with PkHandle=0 twice, and get a duplicate result line.

When the innerPlan is a IndexReader or IndexLookUpReader, we'll encode the NilDatum, thus no error happens.

Check List

Tests

  • Integration test

Code changes

  • Has exported function/method change

Side effects
none

Related changes

  • Need to cherry-pick to the release branch

This change is Reviewable

@XuHuaiyu XuHuaiyu changed the title from executor: add check for Null-Handle when buildTableReaderForIndexJoin to executor: add check for NilDatum when buildTableReaderForIndexJoin Nov 29, 2018

@XuHuaiyu

This comment has been minimized.

Contributor

XuHuaiyu commented Nov 29, 2018

/run-all-tests

@XuHuaiyu

This comment has been minimized.

Contributor

XuHuaiyu commented Nov 29, 2018

Show resolved Hide resolved executor/builder.go Outdated
@zz-jason

@XuHuaiyu we should cherry pick this change to release-2.1 and release-2.0

@eurekaka eurekaka added status/LGT2 and removed status/LGT1 labels Nov 29, 2018

@zz-jason

LGTM

@zz-jason

This comment has been minimized.

Member

zz-jason commented Nov 29, 2018

/run-all-tests

@XuHuaiyu XuHuaiyu changed the title from executor: add check for NilDatum when buildTableReaderForIndexJoin to executor: do not build range for NullOuterVal in IndexLookUpJoin Nov 29, 2018

@XuHuaiyu

This comment has been minimized.

Contributor

XuHuaiyu commented Nov 29, 2018

/run-integration-ddl-test

@zz-jason zz-jason merged commit 4bcdb6d into pingcap:master Nov 29, 2018

4 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci-tidb/build Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details

@XuHuaiyu XuHuaiyu deleted the XuHuaiyu:fix_inlj_range_from_handle branch Dec 4, 2018

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