From 0b8aa8cde55a40da64bbe70665b6d19f025425a9 Mon Sep 17 00:00:00 2001 From: vastdata-xyzr Date: Thu, 9 Mar 2023 22:04:47 -0500 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5PG=E8=A1=A5=E4=B8=81=2045be99?= =?UTF-8?q?f8=20=E8=AE=A1=E7=AE=97=E5=B9=B6=E8=A1=8CSeqScan=E4=BB=A3?= =?UTF-8?q?=E4=BB=B7=E6=96=B0=E5=85=AC=E5=BC=8F=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=8E=A7=E5=88=B6=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=8D=E5=BC=80=E5=90=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 磁盘代价作为整体计入Seqscan代价,不再按照线程数平均。 --- src/bin/gs_guc/cluster_guc.conf | 1 + src/common/backend/utils/misc/guc/guc_sql.cpp | 11 ++++ src/gausskernel/optimizer/path/costsize.cpp | 5 +- .../knl/knl_guc/knl_session_attr_sql.h | 1 + .../regress/expected/force_vector_engine.out | 13 ++++ src/test/regress/expected/upsert_subquery.out | 60 +++++++++++++++++++ .../regress/output/recovery_2pc_tools.source | 1 + src/test/regress/sql/force_vector_engine.sql | 3 + src/test/regress/sql/upsert_subquery.sql | 8 +++ 9 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index 86d904f1e..a5d3b623c 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -224,6 +224,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 420529c78..cb43a5175 100755 --- a/src/common/backend/utils/misc/guc/guc_sql.cpp +++ b/src/common/backend/utils/misc/guc/guc_sql.cpp @@ -647,6 +647,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 e9d4ae167..ca50e9812 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 f4b3af22d..8fa225421 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 9a40c0474..2288fb381 100644 --- a/src/test/regress/output/recovery_2pc_tools.source +++ b/src/test/regress/output/recovery_2pc_tools.source @@ -307,6 +307,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;