Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9g0P-00072x-AN for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Oct 2017 23:31:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e9g0O-0004Wv-Bn for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Oct 2017 23:31:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e9g0M-0004UI-8q for pgsql-hackers@postgresql.org; Tue, 31 Oct 2017 23:31:34 +0000 Received: from www1.webmail.pair.com ([209.68.6.94]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e9g0J-0008VC-AQ for pgsql-hackers@postgresql.org; Tue, 31 Oct 2017 23:31:32 +0000 Received: by www1.webmail.pair.com (Postfix, from userid 65534) id 3DFB47A23D4; Tue, 31 Oct 2017 19:31:29 -0400 (EDT) Received: from 89.0.114.1 ([89.0.114.1]) (SquirrelMail authenticated user te_123@bloodgate.com) by sm.webmail.pair.com with HTTP; Tue, 31 Oct 2017 19:31:29 -0400 Message-ID: <0410ddd44e3823059cf7d39f9b3e82c4.squirrel@sm.webmail.pair.com> In-Reply-To: <20968.1509486337@sss.pgh.pa.us> References: <20968.1509486337@sss.pgh.pa.us> Date: Tue, 31 Oct 2017 19:31:29 -0400 Subject: Re: Account for cost and selectivity of HAVING quals From: "Tels" To: "Tom Lane" Cc: pgsql-hackers@postgresql.org User-Agent: SquirrelMail/1.4.23 [SVN] MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Moin, On Tue, October 31, 2017 5:45 pm, Tom Lane wrote: > Pursuant to the discussion at > https://www.postgresql.org/message-id/20171029112420.8920B5FB05@mx.zeyos.com > here's a patch to fix the planner so that eval costs and selectivity of > HAVING quals are factored into the appropriate plan node numbers. > Perhaps unsurprisingly, this doesn't change the results of any > existing regression tests. > > It's slightly annoying that this approach will result in calculating > the eval costs and selectivity several times, once for each aggregation > plan type we consider. I thought about inserting RestrictInfo nodes > into the havingQual so that those numbers could be cached, but that turned > out to break various code that doesn't expect to see such nodes there. > I'm not sure it's worth going to the trouble of fixing that; in the big > scheme of things, the redundant calculations likely don't cost much, since > we aren't going to have relevant statistics. > > Comments? If anyone wants to do a real review of this, I'm happy to stick > it into the upcoming CF; but without an expression of interest, I'll just > push it. I don't think there's anything terribly controversial here. Not a review, but the patch has this: + total_cost += qual_cost.startup + output_tuples * qual_cost.per_tuple; + + output_tuples = clamp_row_est(output_tuples * ... That looks odd to me, it first uses output_tuples in a formula, then overwrites the value with a new value. Should these lines be swapped? Best regards, Tels -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers