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 1oaFIj-0007ar-4d for pgsql-general@arkaria.postgresql.org; Mon, 19 Sep 2022 11:51:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oaFIh-0001Nd-G6 for pgsql-general@arkaria.postgresql.org; Mon, 19 Sep 2022 11:50:59 +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 1oaFIh-0001NS-2h for pgsql-general@lists.postgresql.org; Mon, 19 Sep 2022 11:50:59 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oaFIa-0004o4-8c for pgsql-general@lists.postgresql.org; Mon, 19 Sep 2022 11:50:58 +0000 Received: by mail-wr1-x434.google.com with SMTP id t14so47124601wrx.8 for ; Mon, 19 Sep 2022 04:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date; bh=154HmUZu32AW++PlxZ64+K6IdX9eNmDOIJ3QbnWuUsk=; b=JE6WtgOavrG6TQEjZk4F3QoY145RKL8y+rX0KeHA2GrpskBtNW+f5GAVcjlGqXEDDH rhBPbZJiIvSYMaDNVSTyCUon66ruQrUIW5usvbWMpOpBwietNkJYw13rhOh6Uv0MLkwh 8aKkJxmqsv1Xc5PpXIALleH/ey8d4fsvh6la4R1yiFDB0I79clMUqfXk1hIo6blRGuHy wwwuN3e7woDHmu8tQah7z8G+svj3Q3RY9aY6YdCmQUS9iCjdFUDhIY8oNltaPw2NqwYK Z/qMOjHe1blEyDBoFBwjKjo7q3iItHr0P0yv+gtRw8+IuJoEGVFjtbVCfzqEIdsSaYGY 3e5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date; bh=154HmUZu32AW++PlxZ64+K6IdX9eNmDOIJ3QbnWuUsk=; b=RDWqToe6Ublct5RzZgTQTqCAa6zCZI5kHPWzM8jLz8Fo1hWGlfWkIw8qn59ivuN9sA OZcNns6rVtvhpgZxok8ttDtUuanygx4vSzEb9OUQboVDHw+HL/VMVLxlg0RqaHCDBOsE BxVV2kd0fGKsDlN4yOAVUSsTu4raAa6wTsh0EzNBR3TyjSAH94jkUd+8OFEAzD6wlXRN XtM7UzaUlnAc36GV2ebYuS0rN+VoDSZdvxfEQoOpjXNJQtIK26kvIGHpmg3/pDOLb4Wx 9JJNkfx0egA/VJvVbSJZLq5VgXzDut5DFLkCGwprvCE6rf7v6sh25chy7bH41cBgHl1m Ivsw== X-Gm-Message-State: ACrzQf0VLzBLjhuJ6KzMUTJnFFWEJB7+yNofu0pCMtc7GLRGxhcMZOyT K2rG4NfjuCbF5VGeCZIa3fqUPbPSS5RSqQ== X-Google-Smtp-Source: AMsMyM4WIuLCCYq5gkoMbVacabogTlDkKmyY/ftuQyggxA0VV33C+sUVD42jFtaVwgdJB4cSitRdhA== X-Received: by 2002:a5d:6084:0:b0:228:67c1:e160 with SMTP id w4-20020a5d6084000000b0022867c1e160mr10006576wrt.83.1663588249875; Mon, 19 Sep 2022 04:50:49 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:516d:2d07:4cb8:3555:7ebc]) by smtp.gmail.com with ESMTPSA id ay5-20020a5d6f05000000b0022afbd02c69sm4537124wrb.56.2022.09.19.04.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 04:50:49 -0700 (PDT) Message-ID: Subject: Re: Suggest using boolean index with (bflag is true) condition for the query with (bflag = true) clause From: Laurenz Albe To: =?UTF-8?Q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9_?= =?UTF-8?Q?=D0=9F=D0=BB=D0=B8=D1=81=D0=BA=D0=B8=D0=BD?= , pgsql-general@lists.postgresql.org Date: Mon, 19 Sep 2022 13:50:47 +0200 In-Reply-To: <519561082.20220918182435@gmail.com> References: <519561082.20220918182435@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 2022-09-18 at 18:24 +0300, Евгений Плискин wrote: > This is not a bug report but rather a suggestion. > > Suppose database contains an index on a boolean column like this: >       create table1(id int, amount float, best_record boolean); >       create index index1 on table1(best_record) where best_record is true; > > And suppose we issue a query like this: >       select * from table1 where best_record = true; > > The planner does not try to use an index for this query because an index condition (bflag is true) does not literally match the query (bflag = true). > But is that reasonable? > The index does not cover records where "best_record" is FALSE or NULL. > And similarly the query is not interested in any records where "best_record" is FALSE or NULL. > So why not use this index for this query? Because the conditions are different: SELECT NULL = TRUE, NULL IS TRUE; ?column? │ ?column? ══════════╪══════════ │ f (1 row) The first result is NULL. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com