Skip to content

Commit

Permalink
resolve schema column index instead
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx committed Jan 9, 2019
1 parent d29cc68 commit cec25b3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,6 @@ func (b *executorBuilder) buildWindow(v *plannercore.PhysicalWindow) *WindowExec
windowFunc: windowFunc,
partialResult: windowFunc.AllocPartialResult(),
groupChecker: newGroupChecker(b.ctx.GetSessionVars().StmtCtx, groupByItems),
childCols: v.ChildCols,
}
return e
}
5 changes: 2 additions & 3 deletions executor/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/executor/windowfuncs"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/util/chunk"
)

Expand All @@ -36,7 +35,6 @@ type WindowExec struct {
windowFunc windowfuncs.WindowFunc
partialResult windowfuncs.PartialResult
executed bool
childCols []*expression.Column
meetNewGroup bool
}

Expand Down Expand Up @@ -155,7 +153,8 @@ func (e *WindowExec) copyChk(chk *chunk.Chunk) {
}
childResult := e.childResults[0]
e.childResults = e.childResults[1:]
for i, col := range e.childCols {
columns := e.Schema().Columns[:len(e.Schema().Columns)-1]
for i, col := range columns {
chk.CopyColumns(childResult, i, col.Index)
}
}
2 changes: 2 additions & 0 deletions executor/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ func (s *testSuite2) TestWindowFunctions(c *C) {
result.Check(testkit.Rows("8 3", "8 3", "8 3"))
result = tk.MustQuery("select sum(t1.a) over() from t t1, t t2")
result.Check(testkit.Rows("21", "21", "21", "21", "21", "21", "21", "21", "21"))
result = tk.MustQuery("select _tidb_rowid, sum(t.a) over() from t")
result.Check(testkit.Rows("1 7", "2 7", "3 7"))
}
1 change: 0 additions & 1 deletion planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,4 @@ type PhysicalWindow struct {
WindowFuncDesc *aggregation.WindowFuncDesc
PartitionBy []property.Item
OrderBy []property.Item
ChildCols []*expression.Column
}
6 changes: 3 additions & 3 deletions planner/core/resolve_indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ func (p *PhysicalSort) ResolveIndices() {
// ResolveIndices implements Plan interface.
func (p *PhysicalWindow) ResolveIndices() {
p.physicalSchemaProducer.ResolveIndices()
p.ChildCols = p.Schema().Columns[:len(p.Schema().Columns)-1]
for i, col := range p.ChildCols {
for i := 0; i < len(p.Schema().Columns)-1; i++ {
col := p.Schema().Columns[i]
newCol := col.ResolveIndices(p.children[0].Schema())
p.ChildCols[i] = newCol.(*expression.Column)
p.Schema().Columns[i] = newCol.(*expression.Column)
}
for i, item := range p.PartitionBy {
newCol := item.Col.ResolveIndices(p.children[0].Schema())
Expand Down

0 comments on commit cec25b3

Please sign in to comment.