Skip to content

Commit

Permalink
fix a bug in projection elimination (pingcap#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu authored Oct 9, 2016
1 parent b2bf4f5 commit 1d06bc6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 2 additions & 5 deletions plan/eliminate_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ func EliminateProjection(p LogicalPlan) LogicalPlan {
RemovePlan(p)
p = EliminateProjection(child)
case *DataSource:
// predicates may be pushed down when build physical plan, and the schema of Selection operator is
// always the same as the child operator, so here we copy the schema of Selection to DataSource.
// predicates may be pushed down when build physical plan,
// so here we copy the schema of Selection to DataSource.
if sel, ok := plan.GetParentByIndex(0).(*Selection); ok {
plan.SetSchema(sel.GetSchema())
for i, cond := range sel.Conditions {
sel.Conditions[i], _ = retrieveColumnsInExpression(cond, plan.GetSchema())
}
}
}
if len(p.GetChildren()) == 1 {
Expand Down
11 changes: 11 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,17 @@ func (s *testSessionSuite) TestIndex(c *C) {
mustExecSQL(c, se, "create table if not exists test_varchar_index (c1 varchar(255), index(c1))")
mustExecSQL(c, se, "insert test_varchar_index values (''), ('a')")
mustExecMatch(c, se, "select * from test_varchar_index where c1 like ''", [][]interface{}{{[]byte("")}})

mustExecSQL(c, se, "drop table if exists t")
mustExecSQL(c, se, "create table t (c1 int, c2 int)")
mustExecSQL(c, se, "insert into t values (1,2), (1,2)")
mustExecSQL(c, se, "create index idx_0 on t(c1)")
mustExecSQL(c, se, "create index idx_1 on t(c2)")
r = mustExecSQL(c, se, "select c1 as c2 from t where c1 >= 2")
rows, err = GetRows(r)
c.Assert(err, IsNil)
matches(c, rows, [][]interface{}{})

err = store.Close()
c.Assert(err, IsNil)
}
Expand Down

0 comments on commit 1d06bc6

Please sign in to comment.