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

executor: fix the projection upon the indexLookUp in indexLookUpJoin can't get result. #12889

Merged
merged 4 commits into from
Oct 24, 2019

Conversation

wshwsh12
Copy link
Contributor

@wshwsh12 wshwsh12 commented Oct 23, 2019

What problem does this PR solve?

Fixes #12785

In buildProjectionForIndexJoin function, it calls ProjectionExec.Open() and recursive calls IndexLookUpExecutor.Open(). In this function, IndexLookUp will re-calculate kvRanges using e.ranges.
In this case, e.ranges is not initiated and will build a empty range.

What is changed and how it works?

Only init ProjectExec and don't recursive init childExec.
The childExec will be initiated in other buildxxxForIndexJoin function.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test
  1. Change the cost model to choose IndexMergeJoin.
  2. Run the following SQL in master and this pr.
use test;
drop table if exists t1, t2;
create table t1(a int, b date, c float, primary key(a, b));
create table t2(a int primary key);
insert into t1 values(1, '2017-11-29', 2.2);
insert into t2 values(1);
select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a=t2.a;

2.1 In master,

tidb> select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a=t2.a;
Empty set (0.00 sec)

tidb> desc analyze select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a=t2.a;
+--------------------------+-------+-----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------+-----------+
| id                       | count | task      | operator info                                                                                   | execution info                                       | memory    |
+--------------------------+-------+-----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------+-----------+
| IndexMergeJoin_25        | 1.00  | root      | inner join, inner:Projection_23, outer key:Column#5, inner key:Column#1                         | time:546.102µs, loops:2, rows:0                      | 745 Bytes |
| ├─Projection_23          | 1.00  | root      | Column#1, Column#2, Column#3                                                                    | time:73.202µs, loops:1, rows:0                       | N/A       |
| │ └─IndexLookUp_22       | 1.00  | root      |                                                                                                 | time:72.229µs, loops:1, rows:0                       | 0 Bytes   |
| │   ├─IndexScan_20       | 1.00  | cop[tikv] | table:t1, index:a, b, range: decided by [eq(Column#1, Column#5)], keep order:true, stats:pseudo | time:0s, loops:0, rows:0                             | N/A       |
| │   └─TableScan_21       | 1.00  | cop[tikv] | table:t1, keep order:false, stats:pseudo                                                        | time:0s, loops:0, rows:0                             | N/A       |
| └─TableReader_29         | 1.00  | root      | data:TableScan_28                                                                               | time:108.032µs, loops:2, rows:1, rpc time:136.84µs   | 127 Bytes |
|   └─TableScan_28         | 1.00  | cop[tikv] | table:t2, range:[-inf,+inf], keep order:false, stats:pseudo                                     | time:73.076µs, loops:2, rows:1                       | N/A       |
+--------------------------+-------+-----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------+-----------+
7 rows in set (0.00 sec)

2.2 In this pr,

tidb> select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a=t2.a;
+---+------------+------+---+
| a | b          | c    | a |
+---+------------+------+---+
| 1 | 2017-11-29 |  2.2 | 1 |
+---+------------+------+---+
1 row in set (0.01 sec)

tidb> desc analyze select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a=t2.a;
+--------------------------+-------+-----------+-------------------------------------------------------------------------------------------------+-------------------------------------------------------+---------------+
| id                       | count | task      | operator info                                                                                   | execution info                                        | memory        |
+--------------------------+-------+-----------+-------------------------------------------------------------------------------------------------+-------------------------------------------------------+---------------+
| IndexMergeJoin_25        | 1.00  | root      | inner join, inner:Projection_23, outer key:Column#5, inner key:Column#1                         | time:2.865241ms, loops:4, rows:2                      | 745 Bytes     |
| ├─Projection_23          | 1.00  | root      | Column#1, Column#2, Column#3                                                                    | time:502.299µs, loops:2, rows:1                       | N/A           |
| │ └─IndexLookUp_22       | 1.00  | root      |                                                                                                 | time:497.121µs, loops:2, rows:1, rpc time:123.668µs   | 9.73046875 KB |
| │   ├─IndexScan_20       | 1.00  | cop[tikv] | table:t1, index:a, b, range: decided by [eq(Column#1, Column#5)], keep order:true, stats:pseudo | time:49.991µs, loops:2, rows:1                        | N/A           |
| │   └─TableScan_21       | 1.00  | cop[tikv] | table:t1, keep order:false, stats:pseudo                                                        | time:35.144µs, loops:2, rows:1                        | N/A           |
| └─TableReader_29         | 1.00  | root      | data:TableScan_28                                                                               | time:454.372µs, loops:2, rows:1, rpc time:1.558265ms  | 127 Bytes     |
|   └─TableScan_28         | 1.00  | cop[tikv] | table:t2, range:[-inf,+inf], keep order:false, stats:pseudo                                     | time:216.994µs, loops:2, rows:1                       | N/A           |
+--------------------------+-------+-----------+-------------------------------------------------------------------------------------------------+-------------------------------------------------------+---------------+
7 rows in set (0.00 sec)

Code changes

Side effects

  • Increased code complexity

Related changes

Release note

Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lzmhhh123 lzmhhh123 added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 23, 2019
@wshwsh12 wshwsh12 added type/bugfix This PR fixes a bug. sig/execution SIG execution labels Oct 23, 2019
@codecov
Copy link

codecov bot commented Oct 23, 2019

Codecov Report

Merging #12889 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master   #12889   +/-   ##
=======================================
  Coverage   79.98%   79.98%           
=======================================
  Files         465      465           
  Lines      107188   107188           
=======================================
  Hits        85729    85729           
  Misses      14994    14994           
  Partials     6465     6465

@wshwsh12
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check whether this bug fix should cherry-pick to release-3.1 and release-3.0

}

func (e *ProjectionExec) open(ctx context.Context) error {
// We have to initialize execution resources in here instead of in function "Open",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is unnecessary.

@@ -2230,7 +2230,7 @@ func (builder *dataReaderBuilder) buildProjectionForIndexJoin(ctx context.Contex
if int64(v.StatsCount()) < int64(builder.ctx.GetSessionVars().MaxChunkSize) {
e.numWorkers = 0
}
err = e.Open(ctx)
err = e.open(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try to refine the test case in the issue, and ensure IndexMergeJoin can be chosen?

@wshwsh12
Copy link
Contributor Author

/rebuild

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wshwsh12 wshwsh12 added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 24, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Oct 24, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Oct 24, 2019

/run-all-tests

@sre-bot sre-bot merged commit bb1c5c8 into pingcap:master Oct 24, 2019
lfkdsk added a commit to JustProject/tidb that referenced this pull request Oct 26, 2019
…ect/tidb into feature-add-udf-support

* 'feature-add-udf-support' of https://github.com/JustProject/tidb: (26 commits)
  *: fix bug that the kill command doesn't work when the killed session is waiting for the pessimistic lock (pingcap#12852)
  executor: fix the projection upon the indexLookUp in indexLookUpJoin can't get result. (pingcap#12889)
  planner, executor: support create view on union (pingcap#12595)
  planner/cascades: introduce TransformationID in cascades planner (pingcap#12879)
  executor: fix data race in test (pingcap#12910)
  executor: reuse chunk row for insert on duplicate update (pingcap#12847)
  ddl: speed up tests (pingcap#12888)
  executor: speed up test (pingcap#12896)
  expression: implement vectorized evaluation for `builtinSecondSig` (pingcap#12886)
  expression: implement vectorized evaluation for `builtinJSONObjectSig` (pingcap#12663)
  expression: speed up builtinRepeatSig by using MergeNulls (pingcap#12674)
  expression: speed up unit tests under the expression package (pingcap#12887)
  store,kv: snapshot doesn't cache the non-exists kv entries lead to poor 'insert ignore' performance (pingcap#12872)
  executor: fix data race in `GetDirtyTable()` (pingcap#12767)
  domain: increase TTL to reduce the occurrence of reporting min startTS errors (pingcap#12578)
  executor: split test for speed up (pingcap#12881)
  executor: fix inconsistent of grants privileges with MySQL when executing `grant all on ...` (pingcap#12330)
  expression: implement vectorized evaluation for `builtinJSONUnquoteSig` (pingcap#12841)
  tune grpc connection count between tidb and tikv (pingcap#12884)
  Makefile: change test parallel to 8 (pingcap#12885)
  ...
XiaTianliang pushed a commit to XiaTianliang/tidb that referenced this pull request Dec 21, 2019
@wshwsh12 wshwsh12 deleted the imj_proj_wrong branch April 21, 2020 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong result for index merge join when using projection upon the indexlookup
4 participants