Skip to content

Commit 135f350

Browse files
winorosdb-storage
authored andcommitted
planner: should clone column in injectProjBelowSort (pingcap#10452)
1 parent f3c48ff commit 135f350

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

executor/executor_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -3782,6 +3782,19 @@ func (s *testSuite) TestSplitIndexRegion(c *C) {
37823782
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.WarnDataTruncated))
37833783
}
37843784

3785+
func (s *testSuite) TestIssue10435(c *C) {
3786+
tk := testkit.NewTestKit(c, s.store)
3787+
tk.MustExec("use test")
3788+
tk.MustExec("create table t1(i int, j int, k int)")
3789+
tk.MustExec("insert into t1 VALUES (1,1,1),(2,2,2),(3,3,3),(4,4,4)")
3790+
tk.MustExec("INSERT INTO t1 SELECT 10*i,j,5*j FROM t1 UNION SELECT 20*i,j,5*j FROM t1 UNION SELECT 30*i,j,5*j FROM t1")
3791+
3792+
tk.MustExec("set @@session.tidb_enable_window_function=1")
3793+
tk.MustQuery("SELECT SUM(i) OVER W FROM t1 WINDOW w AS (PARTITION BY j ORDER BY i) ORDER BY 1+SUM(i) OVER w").Check(
3794+
testkit.Rows("1", "2", "3", "4", "11", "22", "31", "33", "44", "61", "62", "93", "122", "124", "183", "244"),
3795+
)
3796+
}
3797+
37853798
func (s *testSuite) TestUnsignedFeedback(c *C) {
37863799
tk := testkit.NewTestKit(c, s.store)
37873800
oriProbability := statistics.FeedbackProbability.Load()

planner/core/rule_inject_extra_projection.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func injectProjBelowSort(p PhysicalPlan, orderByItems []*ByItems) PhysicalPlan {
157157

158158
topProjExprs := make([]expression.Expression, 0, p.Schema().Len())
159159
for i := range p.Schema().Columns {
160-
col := p.Schema().Columns[i]
160+
col := p.Schema().Columns[i].Clone().(*expression.Column)
161161
col.Index = i
162162
topProjExprs = append(topProjExprs, col)
163163
}
@@ -172,9 +172,10 @@ func injectProjBelowSort(p PhysicalPlan, orderByItems []*ByItems) PhysicalPlan {
172172
bottomProjSchemaCols := make([]*expression.Column, 0, len(childPlan.Schema().Columns)+numOrderByItems)
173173
bottomProjExprs := make([]expression.Expression, 0, len(childPlan.Schema().Columns)+numOrderByItems)
174174
for i, col := range childPlan.Schema().Columns {
175-
col.Index = i
176-
bottomProjSchemaCols = append(bottomProjSchemaCols, col)
177-
bottomProjExprs = append(bottomProjExprs, col)
175+
newCol := col.Clone().(*expression.Column)
176+
newCol.Index = i
177+
bottomProjSchemaCols = append(bottomProjSchemaCols, newCol)
178+
bottomProjExprs = append(bottomProjExprs, newCol)
178179
}
179180

180181
for _, item := range orderByItems {

0 commit comments

Comments
 (0)