Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gRcwK-0005at-UF for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Nov 2018 12:58:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gRcwJ-0000Nf-IZ for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Nov 2018 12:58:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gRctx-0004w1-To for pgsql-hackers@lists.postgresql.org; Tue, 27 Nov 2018 12:55:42 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gRctu-0004Cm-1B for pgsql-hackers@postgresql.org; Tue, 27 Nov 2018 12:55:40 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id wARCtaio018867 for ; Tue, 27 Nov 2018 21:55:36 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 28700EA85A8 for ; Tue, 27 Nov 2018 21:55:36 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 1DD20EA85A2 for ; Tue, 27 Nov 2018 21:55:36 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 16A8C400682 for ; Tue, 27 Nov 2018 21:55:36 +0900 (JST) Message-ID: <5BFD3EAD.2060301@lab.ntt.co.jp> Date: Tue, 27 Nov 2018 21:55:09 +0900 From: Etsuro Fujita User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Subject: postgres_fdw: oddity in costing aggregate pushdown paths Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-CC-Mail-RelayStamp: 1 To: Pg Hackers X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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