pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>
To: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: postgres_fdw: oddity in costing aggregate pushdown paths
Date: Tue, 27 Nov 2018 21:55:09 +0900
Message-ID: <5BFD3EAD.2060301@lab.ntt.co.jp> (raw)

Hi,

While working on [1], I noticed that since we don't set the selectivity
and cost of the local_conds (i.e., fpinfo->local_conds_sel and
fpinfo->local_conds_cost) properly in add_foreign_grouping_paths and
foreign_grouping_ok, estimate_path_cost_size produces considerably
underestimated results when use_remote_estimate.  I think this would
cause problems in later planning steps.  So, why not add something like
this to add_foreign_grouping_paths, as done in other functions such as
postgresGetForeignJopinPaths?

--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -5496,6 +5496,19 @@ add_foreign_grouping_paths(PlannerInfo *root,
RelOptInfo\
 *input_rel,
    if (!foreign_grouping_ok(root, grouped_rel, extra->havingQual))
        return;

+   /*
+    * Compute the selectivity and cost of the local_conds, so we don't have
+    * to do it over again for each path.  The best we can do for these
+    * conditions is to estimate selectivity on the basis of local
statistics.
+    */
+   fpinfo->local_conds_sel = clauselist_selectivity(root,
+                                                    fpinfo->local_conds,
+                                                    0,
+                                                    JOIN_INNER,
+                                                    NULL);
+
+   cost_qual_eval(&fpinfo->local_conds_cost, fpinfo->local_conds, root);
+
    /* Estimate the cost of push down */
    estimate_path_cost_size(root, grouped_rel, NIL, NIL, &rows,
                            &width, &startup_cost, &total_cost);

Best regards,
Etsuro Fujita

[1] https://www.postgresql.org/message-id/5BBC4140.50403%40lab.ntt.co.jp




view thread (9+ messages)  latest in thread

Message-ID: <5BFD3EAD.2060301@lab.ntt.co.jp>
Permalink:  ../5BFD3EAD.2060301@lab.ntt.co.jp/
Also on:    postgresql.org/message-id/5BFD3EAD.2060301@lab.ntt.co.jp

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: fujita.etsuro@lab.ntt.co.jp
  Subject: Re: postgres_fdw: oddity in costing aggregate pushdown paths
  In-Reply-To: <5BFD3EAD.2060301@lab.ntt.co.jp>

* 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