From 01f72bf91a13190a9bad062f46c4853c2adb1755 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Tue, 22 Feb 2022 20:33:45 +0800 Subject: [PATCH] executor: fix pipelined window invalid memory address (#30418) (#30460) close pingcap/tidb#30326 --- executor/pipelined_window.go | 2 +- expression/integration_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/executor/pipelined_window.go b/executor/pipelined_window.go index 8e120376402be..7e8f6a0ed5c5e 100644 --- a/executor/pipelined_window.go +++ b/executor/pipelined_window.go @@ -179,7 +179,7 @@ func (e *PipelinedWindowExec) getRowsInPartition(ctx context.Context) (err error var drained, samePartition bool drained, err = e.fetchChild(ctx) if err != nil { - err = errors.Trace(err) + return errors.Trace(err) } // we return immediately to use a combination of true newPartition but 0 in e.rowToConsume to indicate the data source is drained, if drained { diff --git a/expression/integration_test.go b/expression/integration_test.go index 278da84826f52..acfefb2095748 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -10548,3 +10548,15 @@ func (s *testIntegrationSuite) TestIssue29513(c *C) { tk.MustQuery("select '123' union select cast(a as char) from t;").Sort().Check(testkit.Rows("123", "45678")) tk.MustQuery("select '123' union select cast(a as char(2)) from t;").Sort().Check(testkit.Rows("123", "45")) } + +func (s *testIntegrationSuite) TestIssue30326(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t(a int);") + tk.MustExec("insert into t values(1),(1),(2),(2);") + tk.MustExec("set tidb_window_concurrency = 1;") + err := tk.QueryToErr("select (FIRST_VALUE(1) over (partition by v.a)) as c3 from (select a from t where t.a = (select a from t t2 where t.a = t2.a)) as v;") + c.Assert(err, NotNil) + c.Assert(err.Error(), Equals, "[executor:1242]Subquery returns more than 1 row") +}