Re: Window Functions: buffering strategy - Mailing list pgsql-hackers

From Hitoshi Harada
Subject Re: Window Functions: buffering strategy
Date
Msg-id e08cc0400810200841t6c241132t92d4c687441b9f59@mail.gmail.com
Whole thread Raw
In response to Re: Window Functions: buffering strategy  (Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>)
Responses Re: Window Functions: buffering strategy
List pgsql-hackers
2008/10/20 Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>:
> Hitoshi Harada wrote:
>>
>> Hi,
>>
>> 2008/10/20 Simon Riggs <simon@2ndquadrant.com>:
>>>
>>> On Mon, 2008-10-20 at 10:32 +0900, Hitoshi Harada wrote:
>>>
>>>> So I propose three Window node buffering strategies,
>>>> row/frame/partition buffering so as to avoid unnecessary row
>>>> buffering.
>>>
>>> Sounds good from here. Can I suggest you release the code in phases?
>>>
>>> It would be better if we got just one of those done (row?), than to
>>> attempt all 3 and end up with none because of emerging details.
>>
>> Thank you for your feedback.
>> Ok, actually the first will be partition buffering, because it covers
>> all of the functions' requirement. The row buffering is kind of
>> optimization in the special case.
>
> The thought I had during the last commit fest was that the function would
> call a callback, something like window_forget(pos), that would tell the
> system that it can release any rows before the given position. That way you
> only need one method, and it's also be optimal for functions like lag(),
> that doesn't fit perfectly into either the row or frame buffering category.
> Or do we need the information at plan-time?
>

Right. In the last commit fest we discussed about run-time cut-off
signal API. But I have finally come to that we must know how to buffer
*before* any execution.

The real problem is not how to cut off preceding rows, but how to read
ahead after the current row. I intend to avoid reading ahead until end
of the partition for only row_number() that doesn't need any following
rows. Sometimes we have to store whole the partition before returning
the first result and sometimes not. It depends on function categories,
or function access range. My current idea is classify Window function
API to three parallel to buffering strategies.

And the lag()/lead(), spec says "OFFSET is exact numeric literal" but
we postgres doesn't have mechanism to limit the function argument data
type to Const integer only. So I am thinking about OFFSET for
lag()/lead() may be dynamic integer variable. If it comes, even those
functions don't know how many rows should be cut off. The lag()/lead()
can access any row of partition, per spec.

Regards,


-- 
Hitoshi Harada


pgsql-hackers by date:

Previous
From: Martin Pihlak
Date:
Subject: Re: contrib/pg_stat_statements
Next
From: Teodor Sigaev
Date:
Subject: Re: Index use during Hot Standby