diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index e64ac7bd5..7cc4b88ef 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -225,6 +225,7 @@ enable_resource_record|bool|0,0|NULL|NULL| enable_roach_standby_cluster|bool|0,0|NULL|NULL| enable_save_datachanged_timestamp|bool|0,0|NULL|NULL| enable_seqscan|bool|0,0|NULL|NULL| +enable_seqscan_dopcost|bool|0,0|NULL|NULL| enable_show_any_tuples|bool|0,0|NULL|NULL| enable_sort|bool|0,0|NULL|NULL| enable_incremental_catchup|bool|0,0|NULL|NULL| diff --git a/src/common/backend/utils/misc/guc/guc_sql.cpp b/src/common/backend/utils/misc/guc/guc_sql.cpp index 8aff4a3b1..7eff448d6 100755 --- a/src/common/backend/utils/misc/guc/guc_sql.cpp +++ b/src/common/backend/utils/misc/guc/guc_sql.cpp @@ -648,6 +648,17 @@ static void InitSqlConfigureNamesBool() NULL, NULL, NULL}, + {{"enable_seqscan_dopcost", + PGC_USERSET, + NODE_ALL, + QUERY_TUNING_METHOD, + gettext_noop("Enables DOP cost calculating for sequential-scan."), + NULL}, + &u_sess->attr.attr_sql.enable_seqscan_dopcost, + true, + NULL, + NULL, + NULL}, {{"enable_indexscan", PGC_USERSET, NODE_ALL, diff --git a/src/gausskernel/optimizer/path/costsize.cpp b/src/gausskernel/optimizer/path/costsize.cpp index 5a7e7ba12..f9312beeb 100755 --- a/src/gausskernel/optimizer/path/costsize.cpp +++ b/src/gausskernel/optimizer/path/costsize.cpp @@ -668,7 +668,10 @@ void cost_seqscan(Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathI * wiil be equal division to all parallelism thread. */ run_cost += u_sess->opt_cxt.smp_thread_cost * (dop - 1); - run_cost += spc_seq_page_cost * baserel->pages / dop; + if (u_sess->attr.attr_sql.enable_seqscan_dopcost) + run_cost += spc_seq_page_cost * baserel->pages / dop; + else + run_cost += spc_seq_page_cost * baserel->pages; cpu_per_tuple = u_sess->attr.attr_sql.cpu_tuple_cost + qpqual_cost.per_tuple; run_cost += cpu_per_tuple * RELOPTINFO_LOCAL_FIELD(root, baserel, tuples) / dop; double cpu_run_cost = 0; diff --git a/src/include/knl/knl_guc/knl_session_attr_sql.h b/src/include/knl/knl_guc/knl_session_attr_sql.h index 6a5d043f3..c5cf08952 100644 --- a/src/include/knl/knl_guc/knl_session_attr_sql.h +++ b/src/include/knl/knl_guc/knl_session_attr_sql.h @@ -58,6 +58,7 @@ typedef struct knl_session_attr_sql { bool enable_csqual_pushdown; bool enable_change_hjcost; bool enable_seqscan; + bool enable_seqscan_dopcost; bool enable_indexscan; bool enable_indexonlyscan; bool enable_bitmapscan; diff --git a/src/test/regress/expected/force_vector_engine.out b/src/test/regress/expected/force_vector_engine.out index 09a2f83c9..b3d3c6285 100644 --- a/src/test/regress/expected/force_vector_engine.out +++ b/src/test/regress/expected/force_vector_engine.out @@ -176,6 +176,19 @@ explain select count(*) from force_vector_test; -> Seq Scan on force_vector_test (cost=0.00..36.25 rows=10000 width=0) (6 rows) +set enable_seqscan_dopcost = off; +explain select count(*) from force_vector_test; + QUERY PLAN +---------------------------------------------------------------------------------------------------- + Row Adapter (cost=95.01..95.01 rows=1 width=8) + -> Vector Aggregate (cost=95.00..95.01 rows=1 width=8) + -> Vector Streaming(type: LOCAL GATHER dop: 1/4) (cost=95.00..95.01 rows=1 width=8) + -> Vector Aggregate (cost=95.00..95.01 rows=1 width=8) + -> Vector Adapter(type: BATCH MODE) (cost=70.00..70.00 rows=10000 width=0) + -> Seq Scan on force_vector_test (cost=0.00..70.00 rows=10000 width=0) +(6 rows) + +set enable_seqscan_dopcost = on; select count(*) from force_vector_test; count ------- diff --git a/src/test/regress/expected/upsert_subquery.out b/src/test/regress/expected/upsert_subquery.out index eca49b731..f1734de89 100644 --- a/src/test/regress/expected/upsert_subquery.out +++ b/src/test/regress/expected/upsert_subquery.out @@ -537,6 +537,16 @@ explain (costs off, verbose) select count(*) from hh; Output: h1, h2, h3 (8 rows) +set enable_seqscan_dopcost = off; +explain (costs off, verbose) select count(*) from hh; -- should not be a smp query + QUERY PLAN +--------------------------------- + Aggregate + Output: count(*) + -> Seq Scan on upserttest.hh + Output: h1, h2, h3 +(4 rows) + insert into aa values(3,3,3,3) on duplicate key update a2 = (select count(*) from hh); -- suc explain (costs off, verbose) insert into aa values(3,3,3,3) on duplicate key update a2 = (select count(*) from hh); -- subquery is not execute by smp, but there still is a two-level agg. QUERY PLAN @@ -553,6 +563,16 @@ explain (costs off, verbose) insert into aa values(3,3,3,3) on duplicate key upd Output: 3, 3, 3, 3 (10 rows) +explain (costs off, verbose) select 4,count(*), 4, 4 from hh; -- should not be a smp query + QUERY PLAN +--------------------------------- + Aggregate + Output: 4, count(*), 4, 4 + -> Seq Scan on upserttest.hh + Output: h1, h2, h3 +(4 rows) + +set enable_seqscan_dopcost = on; explain (costs off, verbose) select 4,count(*), 4, 4 from hh; -- should be a smp query QUERY PLAN ---------------------------------------------- @@ -590,8 +610,48 @@ explain (costs off, verbose) insert into aa select 4,count(*), 4, 4 from hh on d Output: upserttest.hh.h1, upserttest.hh.h2, upserttest.hh.h3 (18 rows) +set enable_seqscan_dopcost = off; +explain (costs off, verbose) insert into aa select 4,count(*), 4, 4 from hh on duplicate key update a2 = (select count(*) from hh); -- neither insert-part is a smp plan, nor update-part + QUERY PLAN +------------------------------------------------------------------------------------------------------- + Insert on upserttest.aa + Conflict Resolution: UPDATE + Conflict Arbiter Indexes: aa_pkey, aa_a4_key + InitPlan 1 (returns $0) + -> Aggregate + Output: count(*) + -> Seq Scan on upserttest.hh + Output: upserttest.hh.h1, upserttest.hh.h2, upserttest.hh.h3 + -> Subquery Scan on "*SELECT*" + Output: "*SELECT*"."?column?", "*SELECT*".count, "*SELECT*"."?column?", "*SELECT*"."?column?" + -> Aggregate + Output: 4, count(*), 4, 4 + -> Seq Scan on upserttest.hh + Output: upserttest.hh.h1, upserttest.hh.h2, upserttest.hh.h3 +(14 rows) + prepare sub4 as insert into aa select $1, count(*), 4, 4 from hh on duplicate key update a2 =(select count(*) + $1 from hh); execute sub4(1); -- suc +explain (costs off, verbose) execute sub4(1); -- insert-part is a smp plan, but update-part not + QUERY PLAN +------------------------------------------------------------------------------------------------------- + Insert on upserttest.aa + Conflict Resolution: UPDATE + Conflict Arbiter Indexes: aa_pkey, aa_a4_key + InitPlan 1 (returns $0) + -> Aggregate + Output: (count(*) + 1) + -> Seq Scan on upserttest.hh + Output: upserttest.hh.h1, upserttest.hh.h2, upserttest.hh.h3 + -> Subquery Scan on "*SELECT*" + Output: "*SELECT*"."?column?", "*SELECT*".count, "*SELECT*"."?column?", "*SELECT*"."?column?" + -> Aggregate + Output: 1, count(*), 4, 4 + -> Seq Scan on upserttest.hh + Output: upserttest.hh.h1, upserttest.hh.h2, upserttest.hh.h3 +(14 rows) + +set enable_seqscan_dopcost = on; explain (costs off, verbose) execute sub4(1); -- insert-part is a smp plan, but update-part not QUERY PLAN ------------------------------------------------------------------------------------------------------- diff --git a/src/test/regress/output/recovery_2pc_tools.source b/src/test/regress/output/recovery_2pc_tools.source index 21e1cb114..e97875681 100644 --- a/src/test/regress/output/recovery_2pc_tools.source +++ b/src/test/regress/output/recovery_2pc_tools.source @@ -310,6 +310,7 @@ select name,vartype,unit,min_val,max_val from pg_settings where name <> 'qunit_c enable_segment | bool | | | enableSeparationOfDuty | bool | | | enable_seqscan | bool | | | + enable_seqscan_dopcost | bool | | | enable_seqscan_fusion | bool | | | enable_set_variable_b_format | bool | | | enable_show_any_tuples | bool | | | diff --git a/src/test/regress/sql/force_vector_engine.sql b/src/test/regress/sql/force_vector_engine.sql index 738ac68df..757178f48 100644 --- a/src/test/regress/sql/force_vector_engine.sql +++ b/src/test/regress/sql/force_vector_engine.sql @@ -43,6 +43,9 @@ select * from force_vector_test t1, force_vector_test2 t2 where t1.id=t2.id orde set query_dop=1004; explain select count(*) from force_vector_test; +set enable_seqscan_dopcost = off; +explain select count(*) from force_vector_test; +set enable_seqscan_dopcost = on; select count(*) from force_vector_test; set query_dop=1; diff --git a/src/test/regress/sql/upsert_subquery.sql b/src/test/regress/sql/upsert_subquery.sql index a372b33ff..f7b48bebf 100644 --- a/src/test/regress/sql/upsert_subquery.sql +++ b/src/test/regress/sql/upsert_subquery.sql @@ -118,16 +118,24 @@ insert into aa values(2,2,2,2) on duplicate key update a2 = (select h1 from hh w explain (costs off, verbose) insert into aa values(2,3,3,3) on duplicate key update a2 = (select h1 from hh where h1 = 20); -- upsert not support bypass, so subquery is not a bypass, too. set query_dop = 2; explain (costs off, verbose) select count(*) from hh; -- should be a smp query +set enable_seqscan_dopcost = off; +explain (costs off, verbose) select count(*) from hh; -- should not be a smp query insert into aa values(3,3,3,3) on duplicate key update a2 = (select count(*) from hh); -- suc explain (costs off, verbose) insert into aa values(3,3,3,3) on duplicate key update a2 = (select count(*) from hh); -- subquery is not execute by smp, but there still is a two-level agg. +explain (costs off, verbose) select 4,count(*), 4, 4 from hh; -- should not be a smp query +set enable_seqscan_dopcost = on; explain (costs off, verbose) select 4,count(*), 4, 4 from hh; -- should be a smp query insert into aa select 4,count(*), 4, 4 from hh on duplicate key update a2 = (select count(*) from hh); -- suc explain (costs off, verbose) insert into aa select 4,count(*), 4, 4 from hh on duplicate key update a2 = (select count(*) from hh); -- insert-part is a smp plan, but update-part not +set enable_seqscan_dopcost = off; +explain (costs off, verbose) insert into aa select 4,count(*), 4, 4 from hh on duplicate key update a2 = (select count(*) from hh); -- neither insert-part is a smp plan, nor update-part prepare sub4 as insert into aa select $1, count(*), 4, 4 from hh on duplicate key update a2 =(select count(*) + $1 from hh); execute sub4(1); -- suc explain (costs off, verbose) execute sub4(1); -- insert-part is a smp plan, but update-part not +set enable_seqscan_dopcost = on; +explain (costs off, verbose) execute sub4(1); -- insert-part is a smp plan, but update-part not set query_dop = 1; select * from aa order by a1;