Re: Questionable result from lead(0) IGNORE NULLS - Mailing list pgsql-hackers

From Tatsuo Ishii
Subject Re: Questionable result from lead(0) IGNORE NULLS
Date
Msg-id 20251008.094537.1069126567025828266.ishii@postgresql.org
Whole thread Raw
In response to Re: Questionable result from lead(0) IGNORE NULLS  (Oliver Ford <ojford@gmail.com>)
List pgsql-hackers
Hi Oliver,

I have just pushed a change to WinGetFuncArgInPartition() in
nodeWindowAgg.c to fix Coverity issues. So please update your git
respository.

>  The result looks wrong. So I've just tried removing the "&& relpos != 0"
> and I get:
> 
> SELECT x, y, lead(x, 0) IGNORE NULLS OVER w FROM g
> WINDOW w AS (ORDER BY y);
>  x | y | lead
> ---+---+------
>    | 1 |
>    | 2 |
>  1 | 3 |
> (3 rows)
> 
> Nothing appears for lead at all. So it was doing something but doesn't look
> like it handles the lead(x, 0) case

I think we need to change this:

        forward = relpos > 0 ? 1 : -1;
:
:
    /*
     * Get the next nonnull value in the partition, moving forward or backward
     * until we find a value or reach the partition's end.
     */
    do
    {
        int            nn_info;    /* NOT NULL info */

        abs_pos += forward;
        if (abs_pos < 0)        /* apparently out of partition */
            break;

In lead(0, x) case, abs_pos==0 and foward==-1. So it exits the loop
due to out of partition. Probably we need to change
        forward = relpos > 0 ? 1 : -1;
        to
        forward = relpos >= 0 ? 1 : -1;
and change the do..while loop to a for loop?

Best regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp



pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: ReadRecentBuffer() doesn't scale well
Next
From: Amit Kapila
Date:
Subject: Re: comment for TwoPhaseGetOldestXidInCommit