Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plan: fix a panic bug. #1914

Merged
merged 3 commits into from
Nov 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here.

}
newProp.sortKeyLen = len(newProp.props)
for i, col := range gbyCols {
Expand Down