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 1gv8c0-0008JU-8q for pgsql-performance@arkaria.postgresql.org; Sat, 16 Feb 2019 22:39:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gv8az-0001CZ-CQ for pgsql-performance@arkaria.postgresql.org; Sat, 16 Feb 2019 22:38:05 +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 1gv8ay-00015Q-QH for pgsql-performance@lists.postgresql.org; Sat, 16 Feb 2019 22:38:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gv8aq-0005i3-MO for pgsql-performance@postgresql.org; Sat, 16 Feb 2019 22:38:02 +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 x1GMbnEx027506; Sat, 16 Feb 2019 17:37:49 -0500 From: Tom Lane To: Andres Freund cc: "Jung, Jinho" , Jeff Janes , "pgsql-performance@postgresql.org" Subject: Re: Performance regressions found using sqlfuzz In-reply-to: <20190215164434.twk54vfogbpxqujm@alap3.anarazel.de> References: <20190215164434.twk54vfogbpxqujm@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Fri, 15 Feb 2019 08:44:34 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27504.1550356669.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 16 Feb 2019 17:37:49 -0500 Message-ID: <27505.1550356669@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > On 2019-02-14 17:27:40 +0000, Jung, Jinho wrote: >> - Our analysis: We believe that this regression has to do with two fact= ors: 1) conditional expression (e.g., LEAST or NULLIF) are not reduced to = constants unlike string functions (e.g., CHAR_LENGTH) 2) change in the co= st estimation function for bitmap scan. Execution time grows by 3 orders o= f magnitude. We note that this regression is only observed on large datab= ases (e.g., scale factor of 50). > Hm. The primary problem here is that the estimation both before and > after are really bad. So I don't think the commit you point out here is > really to blame. I'm not that bothered by the query not being great, > given the weird construction with LEAST(), but we probably could fix > that pretty easily. We already did: Author: Tom Lane Branch: master [6f19a8c41] 2018-12-30 13:42:04 -0500 Teach eval_const_expressions to constant-fold LEAST/GREATEST expressio= ns. = Doing this requires an assumption that the invoked btree comparison function is immutable. We could check that explicitly, but in other places such as contain_mutable_functions we just assume that it's true= , so we may as well do likewise here. (If the comparison function's behavior isn't immutable, the sort order in indexes built with it woul= d be unstable, so it seems certainly wrong for it not to be so.) = Vik Fearing = Discussion: https://postgr.es/m/c6e8504c-4c43-35fa-6c8f-3c0b80a912cc@2= ndquadrant.com BTW, const-folding NULLIF would not be a similarly tiny fix, because it would need to check for immutability of the underlying operator (since it is possibly a cross-type comparison, we can't get away with just assuming it's immutable). I'm not convinced that case is worth carrying extra code for. regards, tom lane