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 1jvirn-000827-By for pgsql-general@arkaria.postgresql.org; Wed, 15 Jul 2020 14:58:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jvirl-0005d9-3D for pgsql-general@arkaria.postgresql.org; Wed, 15 Jul 2020 14:58:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jvirk-0005c9-RY for pgsql-general@lists.postgresql.org; Wed, 15 Jul 2020 14:58:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jvird-0003gI-PH for pgsql-general@postgresql.org; Wed, 15 Jul 2020 14:58:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 06FEwRwZ3065644; Wed, 15 Jul 2020 10:58:27 -0400 From: Tom Lane To: Radoslav Nedyalkov cc: Michael Lewis , pgsql-general Subject: Re: single table - fighting a seq scan In-reply-to: References: <2980741.1594764364@sss.pgh.pa.us> Comments: In-reply-to Radoslav Nedyalkov message dated "Wed, 15 Jul 2020 15:22:24 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3065642.1594825107.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 15 Jul 2020 10:58:27 -0400 Message-ID: <3065643.1594825107@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Radoslav Nedyalkov writes: > Shame on me. It's a partial index - *where is not null.* > Put the* is not null *predicate in place and planner always goes for ind= ex. > (tested with thousands of IN entries) > CTE version always goes for index too even *without **is not null , *whi= ch > led to a slight confusion. Ah. That's actually something we fixed in v12 (see [1]). In the CTE version, the planner can prove "x is not null" from "x =3D cte_value" even without knowing what the CTE output value is, just on the basis that "=3D" is strict. In the IN form, it's likewise possible to prove "x is not null" from "x IN (list)", but you need a special test to recognize that. With a short IN list, the planner converts IN to "x =3D this OR x =3D that OR x =3D the-other ..." and can make the proof from that formulation. But we prevent it from trying that on long IN lists, because it'd eat lots of cycles and perhaps not be able to prove the desired partial index qual anyway. regards, tom lane [1] https://git.postgresql.org/gitweb/?p=3Dpostgresql.git&a=3Dcommitdiff&h= =3D65ce07e02