diff --git a/executor/window.go b/executor/window.go index d80a413c75bd3..e29c6219ac258 100644 --- a/executor/window.go +++ b/executor/window.go @@ -171,6 +171,6 @@ func (e *WindowExec) copyChk(chk *chunk.Chunk) { e.remainingRowsInChunk = childResult.NumRows() columns := e.Schema().Columns[:len(e.Schema().Columns)-1] for i, col := range columns { - chk.CopyColumns(childResult, i, col.Index) + chk.MakeRefTo(i, childResult, col.Index) } } diff --git a/util/chunk/chunk.go b/util/chunk/chunk.go index dd459d757b1be..c59afc45cebe4 100644 --- a/util/chunk/chunk.go +++ b/util/chunk/chunk.go @@ -138,6 +138,11 @@ func (c *Chunk) MakeRef(srcColIdx, dstColIdx int) { c.columns[dstColIdx] = c.columns[srcColIdx] } +// MakeRefTo copies columns `src.columns[srcColIdx]` to `c.columns[dstColIdx]`. +func (c *Chunk) MakeRefTo(dstColIdx int, src *Chunk, srcColIdx int) { + c.columns[dstColIdx] = src.columns[srcColIdx] +} + // SwapColumn swaps column "c.columns[colIdx]" with column // "other.columns[otherIdx]". If there exists columns refer to the column to be // swapped, we need to re-build the reference. @@ -187,11 +192,6 @@ func (c *Chunk) SwapColumns(other *Chunk) { c.numVirtualRows, other.numVirtualRows = other.numVirtualRows, c.numVirtualRows } -// CopyColumns copies columns `other.columns[from]` to `c.columns[dst]`. -func (c *Chunk) CopyColumns(other *Chunk, dst, from int) { - c.columns[dst] = other.columns[from] -} - // SetNumVirtualRows sets the virtual row number for a Chunk. // It should only be used when there exists no column in the Chunk. func (c *Chunk) SetNumVirtualRows(numVirtualRows int) { diff --git a/util/chunk/chunk_test.go b/util/chunk/chunk_test.go index b78be4ad67f5c..e4f0975a6e763 100644 --- a/util/chunk/chunk_test.go +++ b/util/chunk/chunk_test.go @@ -620,6 +620,23 @@ func (s *testChunkSuite) TestPreAlloc4RowAndInsert(c *check.C) { } } +func (s *testChunkSuite) TestMakeRefTo(c *check.C) { + fieldTypes := make([]*types.FieldType, 0, 2) + fieldTypes = append(fieldTypes, &types.FieldType{Tp: mysql.TypeFloat}) + fieldTypes = append(fieldTypes, &types.FieldType{Tp: mysql.TypeFloat}) + + chk1 := NewChunkWithCapacity(fieldTypes, 1) + chk1.AppendFloat64(0, 1) + chk1.AppendFloat64(1, 3) + + chk2 := NewChunkWithCapacity(fieldTypes, 1) + chk2.MakeRefTo(0, chk1, 1) + chk2.MakeRefTo(1, chk1, 0) + + c.Assert(chk2.columns[0] == chk1.columns[1], check.IsTrue) + c.Assert(chk2.columns[1] == chk1.columns[0], check.IsTrue) +} + func BenchmarkAppendInt(b *testing.B) { b.ReportAllocs() chk := newChunk(8)