aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/postgres_fdw.h
diff options
context:
space:
mode:
authorEtsuro Fujita <efujita@postgresql.org>2019-06-14 20:49:59 +0900
committerEtsuro Fujita <efujita@postgresql.org>2019-06-14 20:49:59 +0900
commit08d2d58a2a1c8ef8d39e8132d39ee14a1d029500 (patch)
tree80553b50aa49d18f1bb69fe508f3c0d6c7d68d53 /contrib/postgres_fdw/postgres_fdw.h
parentbe2e024bd6527b050da4ad02c921869fed84bb5d (diff)
downloadpostgresql-08d2d58a2a1c8ef8d39e8132d39ee14a1d029500.tar.gz
postgresql-08d2d58a2a1c8ef8d39e8132d39ee14a1d029500.zip
postgres_fdw: Fix costing of pre-sorted foreign paths with local stats.
Commit aa09cd242 modified estimate_path_cost_size() so that it reuses cached costs of a basic foreign path for a given foreign-base/join relation when costing pre-sorted foreign paths for that relation, but it incorrectly re-computed retrieved_rows, an estimated number of rows fetched from the remote side, which is needed for costing both the basic and pre-sorted foreign paths. To fix, handle retrieved_rows the same way as the cached costs: store in that relation's fpinfo the retrieved_rows estimate computed for costing the basic foreign path, and reuse it when costing the pre-sorted foreign paths. Also, reuse the rows/width estimates stored in that relation's fpinfo when costing the pre-sorted foreign paths, to make the code consistent. In commit ffab494a4, to extend the costing mentioned above to the foreign-grouping case, I made a change to add_foreign_grouping_paths() to store in a given foreign-grouped relation's RelOptInfo the rows estimate for that relation for reuse, but this patch makes that change unnecessary since we already store the row estimate in that relation's fpinfo, which this patch reuses when costing a foreign path for that relation with the sortClause ordering; remove that change. In passing, fix thinko in commit 7012b132d: in estimate_path_cost_size(), the width estimate for a given foreign-grouped relation to be stored in that relation's fpinfo was reset incorrectly when costing a basic foreign path for that relation with local stats. Apply the patch to HEAD only to avoid destabilizing existing plan choices. Author: Etsuro Fujita Discussion: https://postgr.es/m/CAPmGK17jaJLPDEkgnP2VmkOg=5wT8YQ1CqssU8JRpZ_NSE+dqQ@mail.gmail.com
Diffstat (limited to 'contrib/postgres_fdw/postgres_fdw.h')
-rw-r--r--contrib/postgres_fdw/postgres_fdw.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/contrib/postgres_fdw/postgres_fdw.h b/contrib/postgres_fdw/postgres_fdw.h
index 30b6502bc05..35545e1831d 100644
--- a/contrib/postgres_fdw/postgres_fdw.h
+++ b/contrib/postgres_fdw/postgres_fdw.h
@@ -59,12 +59,17 @@ typedef struct PgFdwRelationInfo
/* Selectivity of join conditions */
Selectivity joinclause_sel;
- /* Estimated size and cost for a scan or join. */
+ /* Estimated size and cost for a scan, join, or grouping/aggregation. */
double rows;
int width;
Cost startup_cost;
Cost total_cost;
- /* Costs excluding costs for transferring data from the foreign server */
+ /*
+ * Estimated number of rows fetched from the foreign server, and costs
+ * excluding costs for transferring those rows from the foreign server.
+ * These are only used by estimate_path_cost_size().
+ */
+ double retrieved_rows;
Cost rel_startup_cost;
Cost rel_total_cost;