nodeWindowAgg.c IGNORE NULLS abs overflow
Hi.
SELECT v,
lead(v, -2147483648) OVER w AS respect_nulls,
lead(v, -2147483648) IGNORE NULLS OVER w AS ignore_nulls
FROM (VALUES (1), (2)) AS t(v)
WINDOW w AS (ORDER BY v);
should return all NULL values for column ignore_nulls.
The fix is to replace the abs function in nodeWindowAgg.c with pg_abs_s32.
Hi Jian,
Hi.
SELECT v,
lead(v, -2147483648) OVER w AS respect_nulls,
lead(v, -2147483648) IGNORE NULLS OVER w AS ignore_nulls
FROM (VALUES (1), (2)) AS t(v)
WINDOW w AS (ORDER BY v);should return all NULL values for column ignore_nulls.
The fix is to replace the abs function in nodeWindowAgg.c with pg_abs_s32.
Thank you for the report and the fix. Unfortunately I have no time to
take care this for now (till November 3rd). I will work on this after
November 4th unless someone beats me.
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
Hi Jian,
SELECT v,
lead(v, -2147483648) OVER w AS respect_nulls,
lead(v, -2147483648) IGNORE NULLS OVER w AS ignore_nulls
FROM (VALUES (1), (2)) AS t(v)
WINDOW w AS (ORDER BY v);should return all NULL values for column ignore_nulls.
The fix is to replace the abs function in nodeWindowAgg.c with pg_abs_s32.
I confirmed the problem. It seems it's a corner case bug: only happens
when offset = -2147483648. Anyway, bug is a bug.
Attached is a patch which should be ready for commit IMO. I haven't
changed the C code part from yours. I have changed the regression test
part to use low case SQL statements which fits in better with
surroundings.
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
Hi Jian,
I confirmed the problem. It seems it's a corner case bug: only happens
when offset = -2147483648. Anyway, bug is a bug.Attached is a patch which should be ready for commit IMO. I haven't
changed the C code part from yours. I have changed the regression test
part to use low case SQL statements which fits in better with
surroundings.
Attached is the v2 patch. I just added a test case for lag() to
clarify that it is affected by the bug too. If there's no objection,
I will push it to master and 19 branches.
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
On Thu, 5 Nov 2026 at 09:18, Tatsuo Ishii <ishii@postgresql.org> wrote:
Hi Jian,
I confirmed the problem. It seems it's a corner case bug: only happens
when offset = -2147483648. Anyway, bug is a bug.Attached is a patch which should be ready for commit IMO. I haven't
changed the C code part from yours. I have changed the regression test
part to use low case SQL statements which fits in better with
surroundings.Attached is the v2 patch. I just added a test case for lag() to
clarify that it is affected by the bug too. If there's no objection,
I will push it to master and 19 branches.Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
Hi!
Discussion link in your v2 is wrong - for `IGNORE/RESPECT NULLS can be
specified for (prokind == 'f'). ` thread
Also, is there one more issue with leadlag_common:
result = WinGetFuncArgInPartition(winobj, 0,
(forward ? offset : -offset),
WINDOW_SEEK_CURRENT,
const_offset,
&isnull, &isout);
forward ? offset : -offset - same overflow? looks like lag(v,
-2147483648) would be wrong
--
Best regards,
Kirill Reshke
Attached is the v2 patch. I just added a test case for lag() to
clarify that it is affected by the bug too. If there's no objection,
I will push it to master and 19 branches.Hi!
Discussion link in your v2 is wrong - for `IGNORE/RESPECT NULLS can be
specified for (prokind == 'f'). ` thread
Opps. You are right.
Also, is there one more issue with leadlag_common:
result = WinGetFuncArgInPartition(winobj, 0,
(forward ? offset : -offset),
WINDOW_SEEK_CURRENT,
const_offset,
&isnull, &isout);forward ? offset : -offset - same overflow? looks like lag(v,
-2147483648) would be wrong
Good point. If offset == -2147483648, -offset will be -2147483648 due to an
overflow. However, this is an old problem with leadlag_common, not
specific to IGNORE NULLS. So I think this issue does not belong to v19
open items. What do you think?
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
On Thu, 5 Nov 2026 at 12:11, Tatsuo Ishii <ishii@postgresql.org> wrote:
However, this is an old problem with leadlag_common, not
specific to IGNORE NULLS. So I think this issue does not belong to v19
open items. What do you think?
Yes, we can fix this separately
--
Best regards,
Kirill Reshke
Hi Jian and Kirill,
On Thu, 5 Nov 2026 at 12:11, Tatsuo Ishii <ishii@postgresql.org> wrote:
However, this is an old problem with leadlag_common, not
specific to IGNORE NULLS. So I think this issue does not belong to v19
open items. What do you think?Yes, we can fix this separately
I have pushed v2 patch (with slight modifications to the commit
message). Thanks!
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp