Skip to content

Commit

Permalink
plan: fix a panic bug. (pingcap#1914)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfei1991 authored Nov 1, 2016
1 parent 2e79d3f commit 154d7f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func (s *testSuite) TestAggregation(c *C) {
result.Check(testkit.Rows())
result = tk.MustQuery("select count(*) from t a join t b where a.c < 0")
result.Check(testkit.Rows("0"))
result = tk.MustQuery("select sum(b.c), count(b.d), a.c from t a left join t b on a.c = b.d group by b.d order by b.d")
result.Check(testkit.Rows("<nil> 0 4", "8 12 1", "5 2 3"))
// This two cases prove that having always resolve name from field list firstly.
result = tk.MustQuery("select 1-d as d from t having d < 0 order by d desc")
result.Check(testkit.Rows("-1", "-1", "-2", "-2"))
Expand Down
11 changes: 6 additions & 5 deletions plan/physical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,17 +630,18 @@ func (p *Aggregation) convert2PhysicalPlanStream(prop *requiredProperty) (*physi
props: make([]*columnProp, 0, len(gbyCols)),
}
for _, pro := range prop.props {
isMatch := false
var matchedCol *expression.Column
for i, col := range gbyCols {
if col.ColName.L == pro.col.ColName.L {
if !col.Correlated && col.ColName.L == pro.col.ColName.L {
isSortKey[i] = true
isMatch = true
matchedCol = col
}
}
if !isMatch {
if matchedCol == nil {
return info, nil
}
newProp.props = append(newProp.props, pro)
// We should add columns in aggregation in order to keep index right.
newProp.props = append(newProp.props, &columnProp{col: matchedCol, desc: pro.desc})
}
newProp.sortKeyLen = len(newProp.props)
for i, col := range gbyCols {
Expand Down

0 comments on commit 154d7f0

Please sign in to comment.