diff --git a/executor/executor_test.go b/executor/executor_test.go index 7bce3ca10e929..018e8dad15394 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -3840,6 +3840,19 @@ func (s *testSuite) TestIssue10448(c *C) { tk.MustQuery("desc select * from t where pk = 9223372036854775808").Check(testkit.Rows("Point_Get_1 1.00 root table:t, handle:9223372036854775808")) } +func (s *testSuite) TestIssue10435(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("create table t1(i int, j int, k int)") + tk.MustExec("insert into t1 VALUES (1,1,1),(2,2,2),(3,3,3),(4,4,4)") + 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") + + tk.MustExec("set @@session.tidb_enable_window_function=1") + 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( + testkit.Rows("1", "2", "3", "4", "11", "22", "31", "33", "44", "61", "62", "93", "122", "124", "183", "244"), + ) +} + func (s *testSuite) TestUnsignedFeedback(c *C) { tk := testkit.NewTestKit(c, s.store) oriProbability := statistics.FeedbackProbability.Load() diff --git a/planner/core/rule_inject_extra_projection.go b/planner/core/rule_inject_extra_projection.go index 69d44294032c6..9b629b894040f 100644 --- a/planner/core/rule_inject_extra_projection.go +++ b/planner/core/rule_inject_extra_projection.go @@ -157,7 +157,7 @@ func injectProjBelowSort(p PhysicalPlan, orderByItems []*ByItems) PhysicalPlan { topProjExprs := make([]expression.Expression, 0, p.Schema().Len()) for i := range p.Schema().Columns { - col := p.Schema().Columns[i] + col := p.Schema().Columns[i].Clone().(*expression.Column) col.Index = i topProjExprs = append(topProjExprs, col) } @@ -172,9 +172,10 @@ func injectProjBelowSort(p PhysicalPlan, orderByItems []*ByItems) PhysicalPlan { bottomProjSchemaCols := make([]*expression.Column, 0, len(childPlan.Schema().Columns)+numOrderByItems) bottomProjExprs := make([]expression.Expression, 0, len(childPlan.Schema().Columns)+numOrderByItems) for i, col := range childPlan.Schema().Columns { - col.Index = i - bottomProjSchemaCols = append(bottomProjSchemaCols, col) - bottomProjExprs = append(bottomProjExprs, col) + newCol := col.Clone().(*expression.Column) + newCol.Index = i + bottomProjSchemaCols = append(bottomProjSchemaCols, newCol) + bottomProjExprs = append(bottomProjExprs, newCol) } for _, item := range orderByItems {