diff --git a/executor/builder.go b/executor/builder.go index 1893bab0ebf5f..7a245ca3ebd9d 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -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 } diff --git a/executor/window.go b/executor/window.go index 7c0ddeb8309b1..de615f84a9f30 100644 --- a/executor/window.go +++ b/executor/window.go @@ -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" ) @@ -36,7 +35,6 @@ type WindowExec struct { windowFunc windowfuncs.WindowFunc partialResult windowfuncs.PartialResult executed bool - childCols []*expression.Column meetNewGroup bool } @@ -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) } } diff --git a/executor/window_test.go b/executor/window_test.go index b5a4ae647243a..0e966664add41 100644 --- a/executor/window_test.go +++ b/executor/window_test.go @@ -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")) } diff --git a/planner/core/physical_plans.go b/planner/core/physical_plans.go index bb9f6188c2c33..12d829cf3f9d6 100644 --- a/planner/core/physical_plans.go +++ b/planner/core/physical_plans.go @@ -383,5 +383,4 @@ type PhysicalWindow struct { WindowFuncDesc *aggregation.WindowFuncDesc PartitionBy []property.Item OrderBy []property.Item - ChildCols []*expression.Column } diff --git a/planner/core/resolve_indices.go b/planner/core/resolve_indices.go index 23c0a3e07bb9f..3145c45f26cdb 100644 --- a/planner/core/resolve_indices.go +++ b/planner/core/resolve_indices.go @@ -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())