Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfd1afdb

Browse files
author
Etsuro Fujita
committed
postgres_fdw: Account for tlist eval costs in estimate_path_cost_size().
Previously, estimate_path_cost_size() didn't account for tlist evalcosts, except when costing a foreign-grouping path using localstatistics, but such costs should be accounted for when costing that pathusing remote estimates, because some of the tlist expressions might beevaluated locally. Also, such costs should be accounted for in the caseof a foreign-scan or foreign-join path, because the tlist might containPlaceHolderVars, which postgres_fdw currently evaluates locally.This also fixes an oversight in my commitf8f6e44.Like that commit, apply this to HEAD only to avoid destabilizing existingplan choices.Author: Etsuro FujitaDiscussion:https://postgr.es/m/5BFD3EAD.2060301%40lab.ntt.co.jp
1 parent2cf91cc commitfd1afdb

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,9 @@ estimate_path_cost_size(PlannerInfo *root,
24992499
Costtotal_cost;
25002500
Costcpu_per_tuple;
25012501

2502+
/* Make sure the core code has set up the relation's reltarget */
2503+
Assert(foreignrel->reltarget);
2504+
25022505
/*
25032506
* If the table or the server is configured to use remote estimates,
25042507
* connect to the foreign server and execute EXPLAIN to estimate the
@@ -2576,6 +2579,24 @@ estimate_path_cost_size(PlannerInfo *root,
25762579
cost_qual_eval(&local_cost,local_param_join_conds,root);
25772580
startup_cost+=local_cost.startup;
25782581
total_cost+=local_cost.per_tuple*retrieved_rows;
2582+
2583+
/*
2584+
* Add in tlist eval cost for each output row. In case of an
2585+
* aggregate, some of the tlist expressions such as grouping
2586+
* expressions will be evaluated remotely, so adjust the costs.
2587+
*/
2588+
startup_cost+=foreignrel->reltarget->cost.startup;
2589+
total_cost+=foreignrel->reltarget->cost.startup;
2590+
total_cost+=foreignrel->reltarget->cost.per_tuple*rows;
2591+
if (IS_UPPER_REL(foreignrel))
2592+
{
2593+
QualCosttlist_cost;
2594+
2595+
cost_qual_eval(&tlist_cost,fdw_scan_tlist,root);
2596+
startup_cost-=tlist_cost.startup;
2597+
total_cost-=tlist_cost.startup;
2598+
total_cost-=tlist_cost.per_tuple*rows;
2599+
}
25792600
}
25802601
else
25812602
{
@@ -2674,19 +2695,19 @@ estimate_path_cost_size(PlannerInfo *root,
26742695
nrows=clamp_row_est(nrows*fpinfo->joinclause_sel);
26752696
run_cost+=nrows*remote_conds_cost.per_tuple;
26762697
run_cost+=fpinfo->local_conds_cost.per_tuple*retrieved_rows;
2698+
2699+
/* Add in tlist eval cost for each output row */
2700+
startup_cost+=foreignrel->reltarget->cost.startup;
2701+
run_cost+=foreignrel->reltarget->cost.per_tuple*rows;
26772702
}
26782703
elseif (IS_UPPER_REL(foreignrel))
26792704
{
26802705
PgFdwRelationInfo*ofpinfo;
2681-
PathTarget*ptarget=foreignrel->reltarget;
26822706
AggClauseCostsaggcosts;
26832707
doubleinput_rows;
26842708
intnumGroupCols;
26852709
doublenumGroups=1;
26862710

2687-
/* Make sure the core code set the pathtarget. */
2688-
Assert(ptarget!=NULL);
2689-
26902711
/*
26912712
* This cost model is mixture of costing done for sorted and
26922713
* hashed aggregates in cost_agg(). We are not sure which
@@ -2750,26 +2771,22 @@ estimate_path_cost_size(PlannerInfo *root,
27502771
* Startup cost includes:
27512772
* 1. Startup cost for underneath input relation
27522773
* 2. Cost of performing aggregation, per cost_agg()
2753-
* 3. Startup cost for PathTarget eval
27542774
*-----
27552775
*/
27562776
startup_cost=ofpinfo->rel_startup_cost;
27572777
startup_cost+=aggcosts.transCost.startup;
27582778
startup_cost+=aggcosts.transCost.per_tuple*input_rows;
27592779
startup_cost+= (cpu_operator_cost*numGroupCols)*input_rows;
2760-
startup_cost+=ptarget->cost.startup;
27612780

27622781
/*-----
27632782
* Run time cost includes:
27642783
* 1. Run time cost of underneath input relation
27652784
* 2. Run time cost of performing aggregation, per cost_agg()
2766-
* 3. PathTarget eval cost for each output row
27672785
*-----
27682786
*/
27692787
run_cost=ofpinfo->rel_total_cost-ofpinfo->rel_startup_cost;
27702788
run_cost+=aggcosts.finalCost*numGroups;
27712789
run_cost+=cpu_tuple_cost*numGroups;
2772-
run_cost+=ptarget->cost.per_tuple*numGroups;
27732790

27742791
/* Account for the eval cost of HAVING quals, if any */
27752792
if (root->parse->havingQual)
@@ -2784,6 +2801,10 @@ estimate_path_cost_size(PlannerInfo *root,
27842801
startup_cost+=fpinfo->local_conds_cost.startup;
27852802
run_cost+=fpinfo->local_conds_cost.per_tuple*retrieved_rows;
27862803
}
2804+
2805+
/* Add in tlist eval cost for each output row */
2806+
startup_cost+=foreignrel->reltarget->cost.startup;
2807+
run_cost+=foreignrel->reltarget->cost.per_tuple*rows;
27872808
}
27882809
else
27892810
{
@@ -2802,6 +2823,10 @@ estimate_path_cost_size(PlannerInfo *root,
28022823
startup_cost+=foreignrel->baserestrictcost.startup;
28032824
cpu_per_tuple=cpu_tuple_cost+foreignrel->baserestrictcost.per_tuple;
28042825
run_cost+=cpu_per_tuple*foreignrel->tuples;
2826+
2827+
/* Add in tlist eval cost for each output row */
2828+
startup_cost+=foreignrel->reltarget->cost.startup;
2829+
run_cost+=foreignrel->reltarget->cost.per_tuple*rows;
28052830
}
28062831

28072832
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp