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 1gxBVI-0001Ef-F9 for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Feb 2019 14:08:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gxBVH-0004la-71 for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Feb 2019 14:08:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gxBVG-0004lT-Vh for pgsql-hackers@lists.postgresql.org; Fri, 22 Feb 2019 14:08:39 +0000 Received: from mx1.mailbox.org ([2001:67c:2050:104:0:1:25:1]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gxBVA-0003Lh-DI for pgsql-hackers@postgresql.org; Fri, 22 Feb 2019 14:08:38 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id C29DC4C788; Fri, 22 Feb 2019 15:08:30 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=MBO0001; t=1550844508; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XDty2OYR2tOR6P5R0hZZRD+YwCzfJEUyZcD+YRv0SQs=; b=oPLQINB84lWqo+tG/kJX8DPPQ3ldQ+oad0P9CZ7l02v0BOlhPo28XiKjVYd2I8hVA75IM/ jH5VMUQg1jp8PYG4VV+b4sDlxGdAY/5FTu3Pbu9QWPAdsu+G0vqTqjb4aqpQwQQFkaa47c FRW+areM7IDAASyd7QrozuqJKSBUEdWUGbxfxyy/thd4TYLZa8Mz5kheya65hQWJ+TsqiP JRYPeyW2vjl8w88hSlcR7Qooe1niHYdoXFJ+IFcvgxJj4cvS38g0Qp3I7y3mjf/9zlKU6B XPxhfqTk0gDZm9Ha3+3+Q/0YMs5u6yOlNU0h4WftTT5RuO1KM8ix5KbQyLbqPQ== Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id zR9astSS7Jwe; Fri, 22 Feb 2019 15:08:22 +0100 (CET) From: Antonin Houska To: Etsuro Fujita cc: Pg Hackers Subject: Re: postgres_fdw: another oddity in costing aggregate pushdown paths In-reply-to: <5C66A056.60007@lab.ntt.co.jp> References: <5C66A056.60007@lab.ntt.co.jp> Comments: In-reply-to Etsuro Fujita message dated "Fri, 15 Feb 2019 20:19:50 +0900." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29502.1550844622.1@localhost> Date: Fri, 22 Feb 2019 15:10:22 +0100 Message-ID: <29503.1550844622@localhost> Authentication-Results: default_out X-Rspamd-Queue-Id: E5C5816AC List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Etsuro Fujita wrote: > As mentioned in the near thread, I think there is another oversight in > the cost estimation for aggregate pushdown paths in postgres_fdw, IIUC. > When costing an aggregate pushdown path using local statistics, we > re-use the estimated costs of implementing the underlying scan/join > relation, cached in the relation's PgFdwRelationInfo (ie, > rel_startup_cost and rel_total_cost). Since these costs wouldn't yet > contain the costs of evaluating the final scan/join target, as tlist > replacement by apply_scanjoin_target_to_paths() is performed afterwards. > So I think we need to adjust these costs so that the tlist eval costs > are included, but ISTM that estimate_path_cost_size() forgot to do so. > Attached is a patch for fixing this issue. I think the following comment in apply_scanjoin_target_to_paths() should mention that FDWs rely on the new value of reltarget. /* * Update the reltarget. This may not be strictly necessary in all cases, * but it is at least necessary when create_append_path() gets called * below directly or indirectly, since that function uses the reltarget as * the pathtarget for the resulting path. It seems like a good idea to do * it unconditionally. */ rel->reltarget = llast_node(PathTarget, scanjoin_targets); -- Antonin Houska https://www.cybertec-postgresql.com