!3282 引入PG补丁 45be99f8 计算并行SeqScan代价新公式

Merge pull request !3282 from xiyanziran/master_dopcost
This commit is contained in:
opengauss-bot
2023-06-01 11:36:14 +00:00
committed by Gitee
9 changed files with 102 additions and 1 deletions

View File

@ -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|

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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
-------

View File

@ -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
-------------------------------------------------------------------------------------------------------

View File

@ -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 | | |

View File

@ -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;

View File

@ -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;