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 1iJKju-0000Iv-Fx for pgsql-performance@arkaria.postgresql.org; Sat, 12 Oct 2019 16:59:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iJKit-0002NA-NT for pgsql-performance@arkaria.postgresql.org; Sat, 12 Oct 2019 16:58:31 +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 1iJKit-0002Mp-DI for pgsql-performance@lists.postgresql.org; Sat, 12 Oct 2019 16:58:31 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJKip-0003U7-Qw for pgsql-performance@postgresql.org; Sat, 12 Oct 2019 16:58:31 +0000 Received: from [192.168.127.1] (port=10879 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1iJKik-0009eD-E2; Sat, 12 Oct 2019 16:58:22 +0000 Received: from localhost ([127.0.0.1]:53755 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.92.1 (FreeBSD)) (envelope-from ) id 1iJKik-0009KU-9S; Sat, 12 Oct 2019 16:58:22 +0000 From: Andrew Gierth To: MichaelDBA Cc: Jeff Janes , Justin Pryzby , Ivan Voras , postgres performance list Subject: Re: Optimising a two column OR check In-Reply-To: (MichaelDBA@sqlexec.com's message of "Sat, 12 Oct 2019 11:54:07 -0400") Message-ID: <87imotx5uq.fsf@news-spur.riddles.org.uk> References: <20191012144336.GA4475@telsasoft.com> <87y2xqvv1x.fsf@news-spur.riddles.org.uk> <25d9306a-d0e9-ed82-3128-bff469f09aed@sqlexec.com> <87tv8evuq0.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (berkeley-unix) Date: Sat, 12 Oct 2019 17:58:22 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "MichaelDBA" =3D=3D MichaelDBA writes: MichaelDBA> Yep, you're right, Andrew, adding a couple rows made it do MichaelDBA> the index only scan.=C2=A0 I reckon I got misled by turning off MichaelDBA> sequential scans, thinking that actual rows were not MichaelDBA> important anymore.=C2=A0 Overly simplistic reasonings can get MichaelDBA> one into trouble, lol. We do some odd stuff with the statistics estimates for completely empty tables because (a) it's not common in practice for a table to be always empty (i.e. the emptiness is usually transient) and (b) if you take the emptiness of a table at face value, you end up generating insanely bad plans for certain FK check queries that may not get replanned quickly enough to mitigate the performance impact. --=20 Andrew (irc:RhodiumToad)