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 1tO7w5-004Ig1-E0 for pgsql-general@arkaria.postgresql.org; Thu, 19 Dec 2024 04:14:53 +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 1tO7w4-006cYW-P4 for pgsql-general@arkaria.postgresql.org; Thu, 19 Dec 2024 04:14:52 +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 1tO7w4-006cYO-EP for pgsql-general@lists.postgresql.org; Thu, 19 Dec 2024 04:14:52 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tO7vx-000WQx-Sp for pgsql-general@postgresql.org; Thu, 19 Dec 2024 04:14:51 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-71e3eb8d224so87101a34.2 for ; Wed, 18 Dec 2024 20:14:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734581684; x=1735186484; darn=postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=12foFq0NRpD9iBertby0/dgGscJnPTz/rYBc8glAfz0=; b=X3nQ6SH9ay0ZnYD12HwlpR43YY3UNLosD5l1cDTrfgS2bmyWTkFqKheyStHBwBHxZA oOG6J6LvN2Z4L9DSpF2xsttA8+xWSaXQn9yxE4/47eUcN2DpWZOhoHt8f7GRNKuiWIMn d/1GUwjbbqLQAnQydbndparUu8IHyHM05lNI81yLSsGWxw1kiwRJrgNRR+oAKZ9bMBH3 Aucwl+Cy+IpaiAlJgZHjhyGhau0R6sESGcws9d4AK5luMUj/U3BWF9vV7yhEgvVakiUy ddtMUCBrBqBeqpKzyuDoRlLJLPvv8mQX8DBNvoO+ddeeJE5PogP4OKqlzdxhxrgmM7Ma Z8dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734581684; x=1735186484; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=12foFq0NRpD9iBertby0/dgGscJnPTz/rYBc8glAfz0=; b=dAUkHJ2SUVJlAiMC6i6VHkmYeOL14YdKS5sK/HbNgKV8e0TDxj25CKINyA99Qn2ZLW cNFtl7y3wn4E5u0SsNM1O3URCpL8U6XkFtClu9aGqtNx4iw2IreHM33V9rYP1Pbls9+i f34jBzfwC8T8xfjh172dNDdQV3CyfDQfNpxS70CJoF05qZ2k0piRKJtBkDAewunqL0Dh dcZZ6PuDK485Uzbp1nTfxdmukC0k0OgvR2Rz6ZMjSMinpZT/c1pwe0ku1orLEyThEmo7 bIPWXrhsMBSuFlbFl+Lwrs7MQ2I7aRsQiwXdElvOoPfpfbh/RCn+mJ+HbXg/ZAOJA8rT QW8Q== X-Gm-Message-State: AOJu0YzEzCGFn1bWMMrmqOurcAix311do1cfWbjNKXAyCAaEwR1UyC9i s3lwR5MGUV+689sUiU0EH2mAbmgrMhVGW4U5Bx0sdmtZiGqLQx/N+2alj24+wDAEcmNqhfH+1wu sUcV562WpEhVoTTMnxNnaCi0SkTc= X-Gm-Gg: ASbGncvKFtkTnIPgw3AwZr+vP7lYepz63yB/v2eyoKTEqpE3hIcJIgxJnvsFXm1NfDN 6Y3O/fwrzg67mLUq1Nj/k/cZrsdmfhEGH4eEu9w== X-Google-Smtp-Source: AGHT+IEq6eUxh2+oml8RHLKaWTl4EUvHt/OH8k0KXAPAK5sje6Q/4z3+iu0BrsjKWVJszXMj/+D5gT4WOfWIyn4oAHw= X-Received: by 2002:a05:6808:289a:b0:3ea:65bf:8438 with SMTP id 5614622812f47-3eccc02c39cmr2429413b6e.3.1734581684213; Wed, 18 Dec 2024 20:14:44 -0800 (PST) MIME-Version: 1.0 Received: by 2002:ac9:5d0f:0:b0:577:9519:f64a with HTTP; Wed, 18 Dec 2024 20:14:43 -0800 (PST) In-Reply-To: References: From: "David G. Johnston" Date: Wed, 18 Dec 2024 21:14:43 -0700 Message-ID: Subject: Re: Wrapping a where clause to preserve rows with nulls To: Adrian Garcia Badaracco Cc: "pgsql-general@postgresql.org" Content-Type: multipart/alternative; boundary="0000000000001f1df9062997c5c0" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001f1df9062997c5c0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wednesday, December 18, 2024, Adrian Garcia Badaracco < adrian@adriangb.com> wrote: > > Is there any way to include the rows where the predicate evaluates to nul= l > while still using an index? > That seems quite unlikely. Your definition of equality is incompatible with the system=E2=80=99s standard definition while requiring that the stan= dard equals operator be used in the query. Null values and non-null values are not considered equal, or, put another way, always considered distinct from each other. A btree index, which handles =3D, can=E2=80=99t be told to beh= ave differently and so cannot fulfill your desire to produce rows where the stored value is null; it can only produce those equal to 5000. David J. --0000000000001f1df9062997c5c0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wednesday, December 18, 2024, Adrian Garcia Badaracco <adrian@adriangb.com> wrote:

Is there any way to= include the rows where the predicate evaluates to null while still using a= n index?

That seems quite unlik= ely.=C2=A0 Your definition of equality is incompatible with the system=E2= =80=99s standard definition while requiring that the standard equals operat= or be used in the query.=C2=A0 Null values and non-null values are not cons= idered equal, or, put another way, always considered distinct from each oth= er.=C2=A0 A btree index, which handles =3D, can=E2=80=99t be told to behave= differently and so cannot fulfill your desire to produce rows where the st= ored value is null; it can only produce those equal to 5000.

=
David J.
--0000000000001f1df9062997c5c0--