Skip to content

Commit

Permalink
planner: don't push down predicates over table dual (#35669)
Browse files Browse the repository at this point in the history
close #35527
  • Loading branch information
tangenta authored Jun 30, 2022
1 parent 17e2731 commit 86cd94a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions planner/core/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,3 +892,14 @@ func TestIssue34863(t *testing.T) {
tk.MustQuery("select count(*) from c right join o on c.c_id=o.c_id;").Check(testkit.Rows("5"))
tk.MustQuery("select count(o.c_id) from c right join o on c.c_id=o.c_id;").Check(testkit.Rows("5"))
}

// https://github.com/pingcap/tidb/issues/35527.
func TestTableDualAsSubQuery(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("CREATE VIEW v0(c0) AS SELECT NULL;")
tk.MustQuery("SELECT v0.c0 FROM v0 WHERE (v0.c0 IS NULL) LIKE(NULL);").Check(testkit.Rows())
tk.MustQuery("SELECT v0.c0 FROM (SELECT null as c0) v0 WHERE (v0.c0 IS NULL) like (NULL);").Check(testkit.Rows())
}
5 changes: 5 additions & 0 deletions planner/core/rule_predicate_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ func (p *LogicalProjection) PredicatePushDown(predicates []expression.Expression
return predicates, child
}
}
if len(p.children) == 1 {
if _, isDual := p.children[0].(*LogicalTableDual); isDual {
return predicates, p
}
}
for _, cond := range predicates {
newFilter := expression.ColumnSubstitute(cond, p.Schema(), p.Exprs)
if !expression.HasGetSetVarFunc(newFilter) {
Expand Down

0 comments on commit 86cd94a

Please sign in to comment.