diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index 2e25e066f..be1da63f4 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -6291,7 +6291,15 @@ static FunctionScan* make_functionscan(List* qptlist, List* qpqual, Index scanre * if functionscan is disallowed to smp, and cursorPlan has stream node, * rebuild non-smp plan. For example, subplan is not support smp. */ + + /* we must restore is_stream/is_stream_support cause they would be change during pgxc_planner */ + bool outer_is_stream = u_sess->opt_cxt.is_stream; + bool outer_is_stream_support = u_sess->opt_cxt.is_stream_support; + ce->plan = (Node*)ReBuildNonSmpPlanForCursorExpr(pstrdup(ce->raw_query_str)); + + u_sess->opt_cxt.is_stream = outer_is_stream; + u_sess->opt_cxt.is_stream_support = outer_is_stream_support; } return node; diff --git a/src/gausskernel/optimizer/plan/subselect.cpp b/src/gausskernel/optimizer/plan/subselect.cpp index 6fa6ecc99..1ccba2b19 100644 --- a/src/gausskernel/optimizer/plan/subselect.cpp +++ b/src/gausskernel/optimizer/plan/subselect.cpp @@ -711,8 +711,7 @@ static Node* make_subplan( /* Reset u_sess->opt_cxt.query_dop. */ u_sess->opt_cxt.query_dop = outerDop; - /* Reset is_stream/is_stream_support because cursorExpr in subquery would change them */ - set_default_stream(); + /* Isolate the params needed by this specific subplan */ plan_params = root->plan_params; root->plan_params = NIL; diff --git a/src/test/regress/expected/smp.out b/src/test/regress/expected/smp.out index 6a2e7aa45..2f608772f 100644 --- a/src/test/regress/expected/smp.out +++ b/src/test/regress/expected/smp.out @@ -1461,6 +1461,34 @@ where no_o_id not in ( with tmp as (select w_id from bmsql_warehouse where bmsql 0 (1 row) +set query_dop = 1002; +create table store_sales(ss_quantity integer, ss_list_price decimal(7,2)); +create table item(i_brand_id integer); +create table catalog_sales(cs_quantity integer, cs_list_price decimal(7,2)); +with avg_sales as + (select avg(quantity*list_price) average_sales + from (select ss_quantity quantity + ,ss_list_price list_price + from store_sales) x) +select 'store' channel + from store_sales + ,item + group by i_brand_id + having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) +union all + select 'catalog' channel + from catalog_sales + ,item + group by i_brand_id + having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) + ; + channel +--------- +(0 rows) + +drop table store_sales; +drop table item; +drop table catalog_sales; --clean set search_path=public; drop schema test_smp cascade; diff --git a/src/test/regress/sql/smp.sql b/src/test/regress/sql/smp.sql index 132d28c92..96f738a5a 100644 --- a/src/test/regress/sql/smp.sql +++ b/src/test/regress/sql/smp.sql @@ -234,6 +234,35 @@ where no_o_id not in ( with tmp as (select w_id from bmsql_warehouse where bmsql ( select count(*) from bmsql_item group by i_im_id,i_im_id having i_im_id like f1('0') ) tb2; +set query_dop = 1002; +create table store_sales(ss_quantity integer, ss_list_price decimal(7,2)); +create table item(i_brand_id integer); + +create table catalog_sales(cs_quantity integer, cs_list_price decimal(7,2)); + +with avg_sales as + (select avg(quantity*list_price) average_sales + from (select ss_quantity quantity + ,ss_list_price list_price + from store_sales) x) + +select 'store' channel + from store_sales + ,item + group by i_brand_id + having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) +union all + select 'catalog' channel + from catalog_sales + ,item + group by i_brand_id + having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) + ; + +drop table store_sales; +drop table item; +drop table catalog_sales; + --clean set search_path=public; drop schema test_smp cascade;