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: v1-0001-Fix-IGNORE-NULLS-nullness-cache-for-volatile-wind.patch
Description: Binary data

Reply via email to