Skip to content

Commit

Permalink
executor, plan: eliminate projection if the schema len is 0 (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu committed Apr 23, 2018
1 parent 4f9b51b commit 498c481
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,13 @@ func (s *testSuite) TestUnion(c *C) {
tk.MustExec("insert into t value ('2017-01-01'), ('2017-01-02')")
r = tk.MustQuery("(select a from t where a < 0) union (select a from t where a > 0) order by a")
r.Check(testkit.Rows("2017-01-01", "2017-01-02"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
tk.MustExec("insert into t value(0),(0)")
tk.MustQuery("select 1 from (select a from t union all select a from t) tmp").Check(testkit.Rows("1", "1", "1", "1"))
tk.MustQuery("select 1 from (select a from t limit 1 union all select a from t limit 1) tmp").Check(testkit.Rows("1", "1"))
tk.MustQuery("select count(1) from (select a from t union all select a from t) tmp").Check(testkit.Rows("4"))
}

func (s *testSuite) TestIn(c *C) {
Expand Down
3 changes: 3 additions & 0 deletions plan/eliminate_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func canProjectionBeEliminatedLoose(p *LogicalProjection) bool {
// canProjectionBeEliminatedStrict checks whether a projection can be eliminated, returns true if
// the projection just copy its child's output.
func canProjectionBeEliminatedStrict(p *PhysicalProjection) bool {
if p.Schema().Len() == 0 {
return true
}
child := p.Children()[0]
if p.Schema().Len() != child.Schema().Len() {
return false
Expand Down

0 comments on commit 498c481

Please sign in to comment.