pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Etsuro Fujita <efujita@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: postgres_fdw: Fix costing of pre-sorted foreign paths with local
Date: Fri, 14 Jun 2019 11:53:54 +0000
Message-ID: <E1hbkmI-0001Fh-Mv@gemulon.postgresql.org> (raw)

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/08d2d58a2a1c8ef8d39e8132d39ee14a1d029500

Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c | 95 ++++++++++++++++++++++---------------
contrib/postgres_fdw/postgres_fdw.h |  9 +++-
2 files changed, 63 insertions(+), 41 deletions(-)



Message-ID: <E1hbkmI-0001Fh-Mv@gemulon.postgresql.org>
Permalink:  ../E1hbkmI-0001Fh-Mv@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hbkmI-0001Fh-Mv@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: efujita@postgresql.org
  Subject: Re: pgsql: postgres_fdw: Fix costing of pre-sorted foreign paths with local
  In-Reply-To: <E1hbkmI-0001Fh-Mv@gemulon.postgresql.org>
  References: <E1hbkmI-0001Fh-Mv@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox