Re: Some optimizations for COALESCE expressions during constant folding

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Some optimizations for COALESCE expressions during constant folding
Date: 2025-12-03 06:39:04
Message-ID: CAMbWs4_wq12TXbPwSS+PEhAnkH9SvfKwTLuSyV9XQqTp3_q6Uw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 1, 2025 at 5:11 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> Attached is the patch set rebased on current master. I have split the
> patch into two parts: 0001 teaches eval_const_expressions to simplify
> COALESCE arguments using NOT NULL constraints, and 0002 teaches
> expr_is_nonnullable to handle COALESCE expressions.
>
> In addition, 0003 is a WIP patch that extends expr_is_nonnullable to
> handle more expression types. I suspect there are additional cases
> beyond those covered in this patch that can be proven non-nullable.

Here is an updated patchset. I have reorganized the code changes as:
0001 simplifies COALESCE expressions based on non-nullable arguments.
0002 simplifies NullTest expressions for RowExprs based on
non-nullable component fields. It also replaces the existing use of
var_is_nonnullable() with expr_is_nonnullable() for NullTests. 0003
teaches expr_is_nonnullable() to handle more expression types.

- Richard

Attachment Content-Type Size
v4-0001-Simplify-COALESCE-expressions-using-non-nullable-.patch application/octet-stream 10.0 KB
v4-0002-Optimize-ROW-.-IS-NOT-NULL-using-non-nullable-fie.patch application/octet-stream 3.3 KB
v4-0003-Teach-expr_is_nonnullable-to-handle-more-expressi.patch application/octet-stream 12.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2025-12-03 06:42:33 Re: Cleanup shadows variable warnings, round 1
Previous Message Chao Li 2025-12-03 06:16:54 Re: [Proposal] Adding callback support for custom statistics kinds