Re: Questionable result from lead(0) IGNORE NULLS
| От | Tatsuo Ishii | 
|---|---|
| Тема | Re: Questionable result from lead(0) IGNORE NULLS | 
| Дата | |
| Msg-id | 20251008.094537.1069126567025828266.ishii@postgresql.org обсуждение исходный текст  | 
		
| Ответ на | Re: Questionable result from lead(0) IGNORE NULLS (Oliver Ford <ojford@gmail.com>) | 
| Ответы | 
                	
            		Re: Questionable result from lead(0) IGNORE NULLS
            		
            		 | 
		
| Список | 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 по дате отправления: