Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9gRd-00009B-3r for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Oct 2017 23:59:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e9gRc-0006bw-Mv for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Oct 2017 23:59:44 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e9gRb-0006ab-BK for pgsql-hackers@postgresql.org; Tue, 31 Oct 2017 23:59:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e9gRU-0002Q0-D3 for pgsql-hackers@postgresql.org; Tue, 31 Oct 2017 23:59:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v9VNxXOh001465; Tue, 31 Oct 2017 19:59:33 -0400 From: Tom Lane To: "David G. Johnston" cc: Tels , "pgsql-hackers@postgresql.org" Subject: Re: Account for cost and selectivity of HAVING quals In-reply-to: References: <20968.1509486337@sss.pgh.pa.us> <0410ddd44e3823059cf7d39f9b3e82c4.squirrel@sm.webmail.pair.com> Comments: In-reply-to "David G. Johnston" message dated "Tue, 31 Oct 2017 16:54:08 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1463.1509494373.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 31 Oct 2017 19:59:33 -0400 Message-ID: <1464.1509494373@sss.pgh.pa.us> 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 "David G. Johnston" writes: > On Tue, Oct 31, 2017 at 4:31 PM, Tels wrote: >> 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? > ​IIUC it is correct: the additional total_cost comes from processing every > output group to check whether it is qualified - since every group is > checked the incoming output_tuples from the prior grouping is used. Right --- we'll expend the effort to compute the HAVING expression once per group row, whether the row passes the qual or not. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers