Re: BUG #19007: Planner fails to choose partial index with spurious 'not null'

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, bryfox(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19007: Planner fails to choose partial index with spurious 'not null'
Date: 2025-09-26 09:20:45
Message-ID: CAMbWs49mcpD7kX_MaC3zgWs2R-71FQwG-Beo99OJHQQ5rBo7dA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Sep 1, 2025 at 3:00 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> 0001 has been pushed; here is a rebase of 0002.
>
> I think the additional call to eval_const_expressions() is acceptable
> performance-wise, because 1) it only runs when index expressions or
> predicates are present, and 2) it's relatively cheap when run on small
> expression trees, which is typically the case for index expressions
> and predicates. In return, in cases such as the reported, it enables
> the planner to match and use partial indexes, which can be a big win
> in execution.

Here is an updated version of the patch. In the commit message, I've
explained why I think the additional call to eval_const_expressions is
not a performance concern. I've also added a test case to validate
that NullTest quals in index expressions can now be reduced.

One concern I have is that this fix can only be applied to master;
there's no way to backpatch it to v17 or v18. This means that the
issue won't exist in v16 or earlier, nor in v19 and later, but it will
persist in v17 and v18. I have no idea what we should do for v17 and
v18.

- Richard

Attachment Content-Type Size
v4-0001-Fix-const-simplification-for-index-expressions-an.patch application/octet-stream 8.9 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-09-26 09:48:20 BUG #19065: postgresql-18.0/src/bin/pg_combinebackup/reconstruct.c:230: Array sanity check in wrong place ?
Previous Message Magnus Hagander 2025-09-26 09:14:08 Re: Issue with PostgreSQL 18.0 Docker image volume mount (/var/lib/postgresql/data symlink)