Re: Some optimizations for COALESCE expressions during constant folding

Richard Guo <guofenglinux@gmail.com>

From: Richard Guo <guofenglinux@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-12-01T08:11:25Z
Lists: pgsql-hackers

Attachments

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.

- Richard