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

expression: fix incorrect result of logical operators when isTrue/ isFalse function is pushed down #15926

Closed
wants to merge 15 commits into from

Conversation

Reminiscent
Copy link
Contributor

@Reminiscent Reminiscent commented Mar 31, 2020

What problem does this PR solve?

Close: #15718 #15987
Related PR: #12173
Need to review TiPB176 first
Related to #13962

What is changed and how it works?

See an example of this comment
Before this PR:

MySQL [test]> select a and b as c, a, b from tt order by c limit 4;
+---+------+------+
| c | a    | b    |
+---+------+------+
| NULL |    7 | NULL |
| NULL | NULL | 2    |
| 0 |    0 | 2    |
| 0 | NULL | w    |
+---+------+------+
4 rows in set, 4 warnings (0.00 sec)

MySQL [test]> select a and b as c, a, b from tt order by c;
+---+------+------+
| c | a    | b    |
+---+------+------+
| NULL | NULL | NULL |
| NULL |    7 | NULL |
| NULL | NULL | 2    |
| NULL | NULL | 2    |
| 0 | NULL | w    |
| 0 |    0 | 2    |
| 0 |    7 | f    |
| 1 |    7 | 3    |
+---+------+------+
8 rows in set, 2 warnings (0.01 sec)

After this PR:

mysql> create table tt(a decimal(10, 0), b varchar(1));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into tt values(0, '2'), (7, null), (7, '3'), (NULL, 'w'), (NULL, '2'), (NULL, '2'), (NULL, NULL), (7, 'f');
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> select a and b as c, a, b from tt order by c limit 4;
+---+------+------+
| c | a    | b    |
+---+------+------+
| NULL | NULL | NULL |
| NULL | NULL | 2    |
| NULL | NULL | 2    |
| NULL |    7 | NULL |
+---+------+------+
4 rows in set, 2 warnings (0.01 sec)

mysql> select a and b as c, a, b from tt order by c;
+---+------+------+
| c | a    | b    |
+---+------+------+
| NULL | NULL | NULL |
| NULL |    7 | NULL |
| NULL | NULL | 2    |
| NULL | NULL | 2    |
| 0 | NULL | w    |
| 0 |    0 | 2    |
| 0 |    7 | f    |
| 1 |    7 | 3    |
+---+------+------+
8 rows in set, 2 warnings (0.00 sec)

The cause of this problem is that when the order by expression in the topN executor is logicalAnd or logicalOr, keepNull should be set to true when the topN executor is pushed down.

Check List

Tests

  • Unit test
  • Integration test

@Reminiscent Reminiscent requested a review from a team as a code owner March 31, 2020 13:11
@ghost ghost removed their request for review March 31, 2020 13:11
@github-actions github-actions bot added the sig/execution SIG execution label Mar 31, 2020
@codecov
Copy link

codecov bot commented Mar 31, 2020

Codecov Report

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

@@             Coverage Diff             @@
##             master     #15926   +/-   ##
===========================================
  Coverage   80.3437%   80.3437%           
===========================================
  Files           506        506           
  Lines        136618     136618           
===========================================
  Hits         109764     109764           
  Misses        18276      18276           
  Partials       8578       8578           

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 previously approved these changes Apr 1, 2020
Copy link
Contributor

@wshwsh12 wshwsh12 left a comment

Choose a reason for hiding this comment

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

LGTM

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Apr 1, 2020

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 1, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Apr 1, 2020

Your auto merge job has been accepted, waiting for 15907, 15845, 15758, 15956, 15776, 15889

@XuHuaiyu XuHuaiyu added the status/LGT2 Indicates that a PR has LGTM 2. label Apr 1, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Apr 1, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Apr 1, 2020

@Reminiscent merge failed.

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Apr 1, 2020

@Reminiscent CI failed, please check it.

@XuHuaiyu
Copy link
Contributor

Is this expectant?

[2020-04-16T06:33:09.000Z] FAIL: const_test.go:180: testMySQLConstSuite.TestHighNotPrecedenceMode

[2020-04-16T06:33:09.000Z] 

[2020-04-16T06:33:09.000Z] const_test.go:191:

[2020-04-16T06:33:09.000Z]     r = tk.MustQuery(`SELECT * FROM t1 WHERE NOT a BETWEEN 2 AND 3;`)

[2020-04-16T06:33:09.000Z] /home/jenkins/agent/workspace/tidb_ghpr_check_2@2/go/src/github.com/pingcap/tidb/util/testkit/testkit.go:288:

[2020-04-16T06:33:09.000Z]     tk.c.Check(err, check.IsNil, comment)

[2020-04-16T06:33:09.000Z] ... value *errors.fundamental = runtime error: invalid memory address or nil pointer dereference ("runtime error: invalid memory address or nil pointer dereference")

[2020-04-16T06:33:09.000Z] ... sql:SELECT * FROM t1 WHERE NOT a BETWEEN 2 AND 3;, args:[]

@XuHuaiyu
Copy link
Contributor

[2020-04-16T09:05:14.887Z] PANIC: distsql_builtin_test.go:159: testEvalSuite.TestEval

[2020-04-16T09:05:14.887Z] 

[2020-04-16T09:05:14.887Z] ... Panic: interface conversion: proto.Message is nil, not *tipb.InUnionMetadata (PC=0xFAA711)

[2020-04-16T09:05:14.887Z] 

[2020-04-16T09:05:14.887Z] /usr/local/go/src/runtime/panic.go:679

[2020-04-16T09:05:14.887Z]   in gopanic

[2020-04-16T09:05:14.887Z] /usr/local/go/src/runtime/iface.go:255

[2020-04-16T09:05:14.887Z]   in panicdottypeE

[2020-04-16T09:05:14.887Z] /usr/local/go/src/runtime/iface.go:265

[2020-04-16T09:05:14.887Z]   in panicdottypeI

[2020-04-16T09:05:14.887Z] distsql_builtin.go:74

[2020-04-16T09:05:14.887Z]   in getSignatureByPB

[2020-04-16T09:05:14.887Z] distsql_builtin.go:1056

[2020-04-16T09:05:14.887Z]   in newDistSQLFunctionBySig

[2020-04-16T09:05:14.887Z] distsql_builtin.go:1138

[2020-04-16T09:05:14.887Z]   in PBToExpr

[2020-04-16T09:05:14.887Z] distsql_builtin_test.go:856

[2020-04-16T09:05:14.887Z]   in testEvalSuite.TestEval

[2020-04-16T09:05:14.887Z] /usr/local/go/src/reflect/value.go:321

[2020-04-16T09:05:14.887Z]   in Value.Call

[2020-04-16T09:05:14.887Z] /home/jenkins/agent/workspace/tidb_ghpr_check_2@2/go/pkg/mod/github.com/pingcap/check@v0.0.0-20200212061837-5e12011dc712/check.go:850

[2020-04-16T09:05:14.887Z]   in suiteRunner.forkTest.func1

[2020-04-16T09:05:14.887Z] /home/jenkins/agent/workspace/tidb_ghpr_check_2@2/go/pkg/mod/github.com/pingcap/check@v0.0.0-20200212061837-5e12011dc712/check.go:739

[2020-04-16T09:05:14.887Z]   in suiteRunner.forkCall.func1

[2020-04-16T09:05:14.887Z] /usr/local/go/src/runtime/asm_amd64.s:1357

[2020-04-16T09:05:14.887Z]   in goexit

@Reminiscent
Copy link
Contributor Author

@XuHuaiyu @breeswish PTAL. Thanks!

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

@XuHuaiyu
Copy link
Contributor

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 16, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Apr 16, 2020

/run-all-tests

@XuHuaiyu XuHuaiyu added the status/LGT2 Indicates that a PR has LGTM 2. label Apr 16, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Apr 16, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Apr 16, 2020

@Reminiscent merge failed.

@breezewish
Copy link
Member

Do we need to fix at TiKV side as well? Otherwise the results will be different so that copr-test will fail.

@Reminiscent
Copy link
Contributor Author

After an offline discussion, we decided to use another method to solve this problem. We will close this PR and reopen a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression 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.

executor: some unexpected behaviors of TopN
5 participants