Correction of RowMark Removal During Sel-Join Elimination

Andrei Lepikhov <lepihov@gmail.com>

From: Andrei Lepikhov <lepihov@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Alexander Korotkov <aekorotkov@gmail.com>
Date: 2025-08-01T12:32:51Z
Lists: pgsql-hackers

Attachments

Hi,

I've noticed that the code for sel-join elimination incorrectly removes 
RowMarks. Currently, this doesn't lead to any issues because the 
optimiser retains pointers to the simple_rte_array. A RowMark refers to 
an RTE entry that is the same for both the relations being kept and 
those being removed.

I believe it would be beneficial to address this issue now to prevent 
potential problems in the future. See the patch attached.

-- 
regards, Andrei Lepikhov

Commits

  1. Improve RowMark handling during Self-Join Elimination

  2. Refactor variable names in remove_self_joins_one_group()

  3. Reduce "Var IS [NOT] NULL" quals during constant folding

  4. Reimplement parsing and storage of default expressions and constraint