Should IGNORE NULLS cache nullness for volatile arguments?

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Cc: Tatsuo Ishii <ishii(at)postgresql(dot)org>, ojford(at)gmail(dot)com
Subject: Should IGNORE NULLS cache nullness for volatile arguments?
Date: 2026-05-14 04:14:54
Message-ID: 42B42506-6972-4266-8422-FB73E61D9DA7@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I tested the new IGNORE NULLS support for window functions and noticed one behavior that looks strange to me.

To avoid repeated evaluation, the current code caches whether an argument value is NULL or NOT NULL. That is fine for stable expressions, but it looks unsafe for volatile arguments. For example, an argument may be evaluated as NOT NULL when its nullness is first checked, but when the value is needed later and the argument is evaluated again, the result may become NULL. That can lead to surprising results for volatile functions.

I do not have full confidence to call this a bug yet, but I think it is at least worth discussing. If the value of a NOT NULL argument were also cached, then I guess this behavior might be acceptable. But with the current implementation, the argument can be re-evaluated later and produce the opposite nullness result, which seems wrong to me.

The attached patch makes a small change in that direction. It only uses the IGNORE NULLS nullness cache when the argument is safe to reuse. For non-cacheable arguments, the nullness is treated as unknown and the argument is evaluated again.

See the attached patch for details.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v1-0001-Fix-IGNORE-NULLS-nullness-cache-for-volatile-wind.patch application/octet-stream 9.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message SungJun Jang 2026-05-14 04:23:55 Re: Remove invalid SS2/SS3 handling from EUC-KR routines
Previous Message wenhui qiu 2026-05-14 03:59:47 Re: Experimental patch for terminating VACUUM freeze blockers