Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qRZha-002EKZ-0E for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Aug 2023 14:53:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qRZhX-00EIQ0-KG for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Aug 2023 14:53:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qRZhX-00EIPs-7p for pgsql-bugs@lists.postgresql.org; Thu, 03 Aug 2023 14:53:19 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qRZhU-000MIW-Dp for pgsql-bugs@lists.postgresql.org; Thu, 03 Aug 2023 14:53:18 +0000 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-99c10ba30afso472068066b.1 for ; Thu, 03 Aug 2023 07:53:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20221208.gappssmtp.com; s=20221208; t=1691074395; x=1691679195; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=m68YEIbOYS++YyhxSIMgXocrp15Jr7QJMVXWeSZjWx8=; b=mhdjnUI6qT8LLnXN2FVXs3T/x+DX/AbgY2UCbRADFychHKjWyNj/i+rfIQru2tjMG8 OV2ZBxQxaSPUM4nQ4B4PlKkOHR10jEJEgGpko6DLb25imU/VWGdrfui4cuWZ5p24Jjgq H2fxMabkmLcwBE2L7/I0JWjOreRvwqxbEwzImGsS6oArdlLmHWdT0tdlIcj/MeZ3gOxS EI8aD09I4osKY2gvUSlsSvDOlGA/D0ftge2fqq98uJrHlBM2fR5SwHU4b8A3eCrcDwIP Q+YgS92nrLu7y09qUr+2LX2rWbYsn3wTObHeSci6XozcN+0W0IAkWbBp/lJyZjUNRTvv YKlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691074395; x=1691679195; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=m68YEIbOYS++YyhxSIMgXocrp15Jr7QJMVXWeSZjWx8=; b=I990XzsuX7Jqt07FTObIT8KgHvpfCU9y9lAInJttEINjHwdVzlv49JfG9HtuodbSYa YAhIT5O9sZ9jfrUJOfQIU5v/ZcX4JJ0/VS3wcsvm8bCC42dsYHVlIZ9atZKK7Lucwhg2 CB/6KNxdyYCnYXQgS6U2aHPMOc4MuTMjW2HdG5yFpi05qGzqg2+IKuszficDtNJIVgCC 8L4xAz0uG+ZxWU8NVg44fMt/oEjMzfcP7K2KwlETQm7slcIBt5/sstU+bVXqfBHk3xlj NvxHFBSJWb65aHEYFyE7Nj1s4pdmeYxFkRcAcrEXraquauJOw5x+zp6vClCwfdjgQ4wz Bq3w== X-Gm-Message-State: ABy/qLZkUZGZPAEsIeQG/7rmftUe5zpYbXnntwEM7gav4p/S+PjJmGLl DcYCChnA3nBWXWpiIB4YKL+6dqwh3lIZtFqULNs= X-Google-Smtp-Source: APBJJlH0Bn8qGYTpDUwVgHvaQ7Ak0hhzuAngsCSdVOd50xTGwTEeotj90ApVjygDidm1u+Jh2jMkgw== X-Received: by 2002:a17:907:3f1f:b0:98d:abd4:4000 with SMTP id hq31-20020a1709073f1f00b0098dabd44000mr9080826ejc.35.1691074395032; Thu, 03 Aug 2023 07:53:15 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:6acd:7737:df67:614a:2637]) by smtp.gmail.com with ESMTPSA id x23-20020a170906149700b0099329b3ab67sm10615330ejc.71.2023.08.03.07.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:53:14 -0700 (PDT) Message-ID: <3753bdabfae96325e8f5a8ba27afd1bf96912dd1.camel@cybertec.at> Subject: Re: WHERE column = X AND column = Y will always be zero matching rows From: Laurenz Albe To: "[Quipsy] Markus Karg" , "pgsql-bugs@lists.postgresql.org" Date: Thu, 03 Aug 2023 16:53:13 +0200 In-Reply-To: <1e15568107854a75ae8dd35a5a75daa7@quipsy.de> References: <1e15568107854a75ae8dd35a5a75daa7@quipsy.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2023-08-03 at 14:20 +0000, [Quipsy] Markus Karg wrote: > I am using PostgreSQL 15.3 (Debian 15.3-1.pgdg120+1) on aarch64-unknown-l= inux-gnu, > compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit. > =C2=A0 > (In the following X and Y are literals; X <> Y) > =C2=A0 > I noticed is that=E2=80=A6 > =C2=A0 > EXPLAIN SELECT column FROM Table WHERE column =3D X AND column =3D Y > =C2=A0 > =E2=80=A6says that PostgreSQL actually wants to perform a Scan! This is not a bug. > I wonder why squandering any resources into a Scan here, as it is pretty = obvious that the > result is guaranteed to be always, under any conditions, and will always = be: zero matching > rows =E2=80=93 at least in a universe where a single value cannot be X AN= D Y at the same time. Such an optimization, while certainly possible, would not be free, and each query with more than one WHERE condition would have to pay the price. On the other hand, only ill-written queries would benefit. Since PostgreSQL only caches execution plans in special cases, anything tha= t slows down the optimizer should improve enough statements that it is a net = win. I don't see that here (but that is of course a matter of opinion). Yours, Laurenz Albe