Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jmNhV-0004vN-In for pgsql-performance@arkaria.postgresql.org; Fri, 19 Jun 2020 20:33:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jmNhT-0001qs-Ib for pgsql-performance@arkaria.postgresql.org; Fri, 19 Jun 2020 20:33:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jmNhT-0001ql-B3 for pgsql-performance@lists.postgresql.org; Fri, 19 Jun 2020 20:33:23 +0000 Received: from mx.zeyos.com ([88.99.153.70]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jmNhM-0008Q4-VB for pgsql-performance@postgresql.org; Fri, 19 Jun 2020 20:33:22 +0000 Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id 68FB05FB27 for ; Fri, 19 Jun 2020 22:33:16 +0200 (CEST) Authentication-Results: mx.zeyos.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=zeyos.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zeyos.com; h= content-transfer-encoding:content-type:content-type:mime-version :to:from:from:subject:subject:date:date; s=dkim; t=1592598796; x=1593462797; bh=yBgvNo+mPkmRLJe10hOYFDO4h8hNIp3Imi50JYs0JRk=; b= SWyhmqPYGIk4pfhperf/CxHISfqGpH9FNYlCSEo8k/XOqAPZaVu9rPXwv60T0AaY s9kY2ZKNSSbgLunmUo7j4JaLYRyh848VbYdbb5glO8WLcXGW+ivVpB7tkCpZr25X A8BzjyjwMm17CtKkJRrIW0qgNxTflmvfbMp/fw3By/c= X-Virus-Scanned: Debian amavisd-new at mx.zeyos.com Received: from mx.zeyos.com ([127.0.0.1]) by mx.zeyos.com (mx.zeyos.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id vHB_TTM-87E6 for ; Fri, 19 Jun 2020 22:33:16 +0200 (CEST) Received: from cloud.zeyos.com (unknown [81.171.8.203]) by mx.zeyos.com (Postfix) with ESMTPSA id 975775FB22; Fri, 19 Jun 2020 22:33:15 +0200 (CEST) Date: Fri, 19 Jun 2020 22:33:15 +0200 Subject: Re: Unclamped row estimates whith OR-ed subplans From: "Benjamin Coutu" To: "Tom Lane" Cc: pgsql-performance@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20200619203316.68FB05FB27@mx.zeyos.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > While you're waiting, you might think about recasting the query to > avoid the OR. Perhaps you could do a UNION of two scans of the > transactions table?=0A=0AThanks for the hint, I am well aware of the work= around for OR via UNION. I am not trying to improve this query per se as it= is the small root of a very complex generated query and it's unfeasible to= rewrite it to a UNION in this case.=0A=0AThe point of my message to the li= st was to highlight the misestimation, which I couldn't wrap my head around= . Maybe this discussion can give some food for thought to someone who might= tackle this in the future. It would surely be great to have selectivity es= timate smarts for the generic case of OR-ed SubPlans someday.=0A >=20 > > Btw, I don't quite understand why the nested loop on contract only is e= xpected to yield 31662 rows, when the null_frac of field transactions.contr= act is 1. Shouldn't that indicate zero rows or some kind of default minimum= estimate for that query? >=20 > That I don't understand. I get a minimal rowcount estimate for an > all-nulls outer table, as long as I'm using just one IN rather than=0A=0A= Yeah, that might be worth digging into. Is there any other info apart from = those stats that I could provide?