From b2cac28597742a01f080c7e88df0b238edbd197c Mon Sep 17 00:00:00 2001 From: totaj Date: Thu, 29 Dec 2022 17:16:36 +0800 Subject: [PATCH] Fix rownum with column table. --- src/gausskernel/optimizer/plan/createplan.cpp | 2 +- src/test/regress/expected/xc_rownum.out | 72 +++++++++++++++++++ src/test/regress/sql/xc_rownum.sql | 46 ++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index 6a127a5a0f..fd15642296 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -1411,7 +1411,7 @@ static void adjust_scan_targetlist(ResultPath* best_path, Plan* subplan) sub_targetlist = lappend(sub_targetlist, entry); } subplan->targetlist = sub_targetlist; - if (IsA(subplan, PartIterator)) { + if (IsA(subplan, PartIterator) || IsA(subplan, BaseResult)) { subplan->lefttree->targetlist = subplan->targetlist; } } diff --git a/src/test/regress/expected/xc_rownum.out b/src/test/regress/expected/xc_rownum.out index 9c6a1d53e7..5f371f66fa 100755 --- a/src/test/regress/expected/xc_rownum.out +++ b/src/test/regress/expected/xc_rownum.out @@ -2061,6 +2061,78 @@ select * from (select rownum, max(id) as max_id from student_cstore1 group by ro 10 | 10 (10 rows) +-- test rownum with base result plan +create table tab_1110306_1 (a1 int, b1 int, c1 int, d1 int,e1 text,f1 date) with (orientation=column) ; +insert into tab_1110306_1 values +(1, 1, 1, 1,'A10Z','2000-03-01') +,(1, 1, 1, 2,'A1Z' ,'2000-03-02') +,(1, 1, 2, 1,'A11Z','2000-03-05') +,(1, 1, 2, 2,'A2Z' ,'2000-03-04') +,(1, 2, 1, 1,'A13Z','2000-03-05') +,(1, 2, 1, 2,'A3Z' ,'2000-03-19') +,(1, 2, 2, 1,'A15Z','2000-03-05') +,(1, 2, 2, 2,'A4Z' ,'2000-03-19') +,(1, 3, 3, 3,'A10Z','2000-03-05') +,(2, 5, 5, 5,'A5Z' ,'2000-03-10') +,(2, NULL, 6, 6,null,'2000-04-01') +,(2, 6, NULL, 6,'A15Z','2000-05-01') +,(null, 6, 6, NULL,'A6Z','2000-03-11') +,(2, NULL, NULL, 7,'A5Z','2000-03-02') +,(2, NULL, 7, NULL,'A7Z','2000-03-03') +,(2, 7, NULL, NULL,'A10Z','2000-03-10') +,(3, NULL, NULL, NULL,'A9Z','2000-03-05') +; +explain (verbose, costs off)select 1 +from (select transaction_timestamp() as aa +from tab_1110306_1 +where f1 <=to_date('2010-01-02') +and c1 > 12 +or statement_timestamp() >=current_timestamp +and rownum < 6 +group by c1) t1 +group by t1.aa +having t1.aa <=transaction_timestamp(); + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + HashAggregate + Output: 1, t1.aa + Group By Key: t1.aa + -> Subquery Scan on t1 + Output: t1.aa + -> Group + Output: transaction_timestamp(), tab_1110306_1.c1 + Group By Key: tab_1110306_1.c1 + -> Sort + Output: tab_1110306_1.c1 + Sort Key: tab_1110306_1.c1 + -> Result + Output: tab_1110306_1.c1 + Filter: (((tab_1110306_1.f1 <= to_date('2010-01-02'::text)) AND (tab_1110306_1.c1 > 12)) OR ((statement_timestamp() >= pg_systimestamp()) AND (ROWNUM < 6))) + -> Result + Output: tab_1110306_1.c1, tab_1110306_1.f1 + One-Time Filter: (transaction_timestamp() <= transaction_timestamp()) + -> Row Adapter + Output: tab_1110306_1.c1, tab_1110306_1.f1 + -> CStore Scan on public.tab_1110306_1 + Output: tab_1110306_1.c1, tab_1110306_1.f1 +(21 rows) + +select 1 +from (select transaction_timestamp() as aa +from tab_1110306_1 +where f1 <=to_date('2010-01-02') +and c1 > 12 +or statement_timestamp() >=current_timestamp +and rownum < 6 +group by c1) t1 +group by t1.aa +having t1.aa <=transaction_timestamp(); + ?column? +---------- + 1 +(1 row) + +drop table tab_1110306_1; drop table student_cstore1; drop table student_cstore2; drop table student; diff --git a/src/test/regress/sql/xc_rownum.sql b/src/test/regress/sql/xc_rownum.sql index 71caa8545c..e1f4984996 100644 --- a/src/test/regress/sql/xc_rownum.sql +++ b/src/test/regress/sql/xc_rownum.sql @@ -527,6 +527,52 @@ select rownum, sc1.stuname, sc2.id from student_cstore2 as sc1, student_cstore2 -- test rownum for agg select * from (select rownum, max(id) as max_id from student_cstore1 group by rownum) as t order by max_id; +-- test rownum with base result plan +create table tab_1110306_1 (a1 int, b1 int, c1 int, d1 int,e1 text,f1 date) with (orientation=column) ; + +insert into tab_1110306_1 values +(1, 1, 1, 1,'A10Z','2000-03-01') +,(1, 1, 1, 2,'A1Z' ,'2000-03-02') +,(1, 1, 2, 1,'A11Z','2000-03-05') +,(1, 1, 2, 2,'A2Z' ,'2000-03-04') +,(1, 2, 1, 1,'A13Z','2000-03-05') +,(1, 2, 1, 2,'A3Z' ,'2000-03-19') +,(1, 2, 2, 1,'A15Z','2000-03-05') +,(1, 2, 2, 2,'A4Z' ,'2000-03-19') +,(1, 3, 3, 3,'A10Z','2000-03-05') +,(2, 5, 5, 5,'A5Z' ,'2000-03-10') +,(2, NULL, 6, 6,null,'2000-04-01') +,(2, 6, NULL, 6,'A15Z','2000-05-01') +,(null, 6, 6, NULL,'A6Z','2000-03-11') +,(2, NULL, NULL, 7,'A5Z','2000-03-02') +,(2, NULL, 7, NULL,'A7Z','2000-03-03') +,(2, 7, NULL, NULL,'A10Z','2000-03-10') +,(3, NULL, NULL, NULL,'A9Z','2000-03-05') +; + +explain (verbose, costs off)select 1 +from (select transaction_timestamp() as aa +from tab_1110306_1 +where f1 <=to_date('2010-01-02') +and c1 > 12 +or statement_timestamp() >=current_timestamp +and rownum < 6 +group by c1) t1 +group by t1.aa +having t1.aa <=transaction_timestamp(); + +select 1 +from (select transaction_timestamp() as aa +from tab_1110306_1 +where f1 <=to_date('2010-01-02') +and c1 > 12 +or statement_timestamp() >=current_timestamp +and rownum < 6 +group by c1) t1 +group by t1.aa +having t1.aa <=transaction_timestamp(); + +drop table tab_1110306_1; drop table student_cstore1; drop table student_cstore2; drop table student; -- Gitee