Skip to content

Commit

Permalink
cherry pick pingcap#25817 to release-5.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
qw4990 authored and ti-srebot committed Jun 29, 2021
1 parent 8acd5c8 commit 1a8778e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ func (p *LogicalJoin) constructIndexJoin(
lhs, ok1 := c.GetArgs()[0].(*expression.Column)
rhs, ok2 := c.GetArgs()[1].(*expression.Column)
if ok1 && ok2 {
if lhs.InOperand || rhs.InOperand {
// if this other-cond is from a `[not] in` sub-query, do not convert it into eq-cond since
// IndexJoin cannot deal with NULL correctly in this case; please see #25799 for more details.
continue
}
outerSchema, innerSchema := p.Children()[outerIdx].Schema(), p.Children()[1-outerIdx].Schema()
if outerSchema.Contains(lhs) && innerSchema.Contains(rhs) {
outerHashKeys = append(outerHashKeys, lhs)
Expand Down
24 changes: 24 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3772,6 +3772,30 @@ func (s *testIntegrationSuite) TestIssue24281(c *C) {
"UNION select 1 as v1, 2 as v2")
}

<<<<<<< HEAD
=======
func (s *testIntegrationSuite) TestIssue25799(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec(`create table t1 (a float default null, b smallint(6) DEFAULT NULL)`)
tk.MustExec(`insert into t1 values (1, 1)`)
tk.MustExec(`create table t2 (a float default null, b tinyint(4) DEFAULT NULL, key b (b))`)
tk.MustExec(`insert into t2 values (null, 1)`)
tk.HasPlan(`select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b)`, `IndexJoin`)
tk.MustQuery(`select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b)`).Check(testkit.Rows())
}

func (s *testIntegrationSuite) TestLimitWindowColPrune(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
tk.MustExec("insert into t values(1)")
tk.MustQuery("select count(a) f1, row_number() over (order by count(a)) as f2 from t limit 1").Check(testkit.Rows("1 1"))
}

>>>>>>> a0b97b0c9... planner: handle other-conditions from subqueries correctly when constructing IndexJoin (#25817)
func (s *testIntegrationSuite) TestIncrementalAnalyzeStatsVer2(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down

0 comments on commit 1a8778e

Please sign in to comment.