Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-23 Thread Simon Riggs
On Sat, 2007-01-20 at 14:20 +, Simon Riggs wrote: > On Sat, 2007-01-20 at 23:54 +1100, Gavin Sherry wrote: > > Windows are slightly more complex though. As you > > probably know, there are two ways of specifying the window frame: by an > > absolute number of rows (ROWS N PRECEDING, for example

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Simon Riggs
On Sat, 2007-01-20 at 13:36 +, Gregory Stark wrote: > "Alvaro Herrera" <[EMAIL PROTECTED]> writes: > > > Simon Riggs wrote: > > > >> I'm working on modifying Tuplestore that will allow you to store the > >> last N tuples, rather than all previous input. This is specifically > >> designed to al

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Simon Riggs
On Sat, 2007-01-20 at 23:54 +1100, Gavin Sherry wrote: > > > Yep. I was thinking about this all morning. I think I've over engineered > > > the problem in my head. Window function input just looks like a slightly > > > more complex distinct aggregate input. I'll think on it more though. > > > > I'

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Gavin Sherry
On Sat, 20 Jan 2007, Gregory Stark wrote: > However for RANGE UNBOUNDED PRECEDING we can apply a different plan. Keep the > state variable for each window aggregate around for the entire time. For each > record apply the state transition function then apply the FINAL function to > generate the res

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Gregory Stark
"Gavin Sherry" <[EMAIL PROTECTED]> writes: > Wow. What a coincidence! Windows are slightly more complex though. As you > probably know, there are two ways of specifying the window frame: by an > absolute number of rows (ROWS N PRECEDING, for example); or, by a 'range' > (RANGE N PRECEDING), where

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Oleg Bartunov
Gavin, I'm also interested in the topic, but right now I am wondering if rank() function is a reserved name ? We're working on built-in tsearch2 for 8.3 release and we already have rank() function. Oleg On Sun, 21 Jan 2007, Gavin Sherry wrote: On Sat, 20 Jan 2007, Tom Lane wrote: Gavin She

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Gregory Stark
"Alvaro Herrera" <[EMAIL PROTECTED]> writes: > Simon Riggs wrote: > >> I'm working on modifying Tuplestore that will allow you to store the >> last N tuples, rather than all previous input. This is specifically >> designed to allow Merge Join to do Mark/Restore without materializing >> the whole s

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Gavin Sherry
On Sat, 20 Jan 2007, Tom Lane wrote: > Gavin Sherry <[EMAIL PROTECTED]> writes: > > We want to answer the following: for each employee: what is their rank in > > terms of salary and what is their rank in terms of age. This query > > answers that: > > > select empno, rank() over (order by salary) a

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Gavin Sherry
On Sat, 20 Jan 2007, Simon Riggs wrote: > On Sat, 2007-01-20 at 15:58 +1100, Gavin Sherry wrote: > > On Fri, 19 Jan 2007, Tom Lane wrote: > > > > > Gavin Sherry <[EMAIL PROTECTED]> writes: > > > > On Fri, 19 Jan 2007, Tom Lane wrote: > > > >> Er, what primary key would that be exactly? And even i

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Alvaro Herrera
Simon Riggs wrote: > I'm working on modifying Tuplestore that will allow you to store the > last N tuples, rather than all previous input. This is specifically > designed to allow Merge Join to do Mark/Restore without materializing > the whole sort set. This can also be used to materialize Windows

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Simon Riggs
On Sat, 2007-01-20 at 15:58 +1100, Gavin Sherry wrote: > On Fri, 19 Jan 2007, Tom Lane wrote: > > > Gavin Sherry <[EMAIL PROTECTED]> writes: > > > On Fri, 19 Jan 2007, Tom Lane wrote: > > >> Er, what primary key would that be exactly? And even if you had a key, > > >> I wouldn't call joining on i

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Simon Riggs
On Sat, 2007-01-20 at 09:34 +1100, Gavin Sherry wrote: > On Sat, 19 Jan 2007, Karen Hill wrote: > > > Gavin Sherry wrote: > > > Recenly, I've been researching and putting together a proposal for window > > > functions. Good news. > > Implementing NULLS FIRST and NULLS LAST appears like another >

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-20 Thread Markus Schiltknecht
Hi, Tom Lane wrote: select empno, rank() over (order by salary) as srank, rank() over (order by age) as arank from employees order by empno; Eeek. This seems like the worst sort of action-at-a-distance. How does rank() know what value it's supposed to report the rank of? All of these r

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-19 Thread Tom Lane
Gavin Sherry <[EMAIL PROTECTED]> writes: > We want to answer the following: for each employee: what is their rank in > terms of salary and what is their rank in terms of age. This query > answers that: > select empno, rank() over (order by salary) as srank, > rank() over (order by age) as arank

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-19 Thread Gavin Sherry
On Fri, 19 Jan 2007, Tom Lane wrote: > Gavin Sherry <[EMAIL PROTECTED]> writes: > > On Fri, 19 Jan 2007, Tom Lane wrote: > >> Er, what primary key would that be exactly? And even if you had a key, > >> I wouldn't call joining on it trivial; I'd call it expensive ... > > > I should have used sligh

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-19 Thread Tom Lane
Gavin Sherry <[EMAIL PROTECTED]> writes: > On Fri, 19 Jan 2007, Tom Lane wrote: >> Er, what primary key would that be exactly? And even if you had a key, >> I wouldn't call joining on it trivial; I'd call it expensive ... > I should have used slightly different language. What I meant to say was,

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-19 Thread Gavin Sherry
On Sat, 19 Jan 2007, Karen Hill wrote: > Gavin Sherry wrote: > > Recenly, I've been researching and putting together a proposal for window > > functions. > > Implementing NULLS FIRST and NULLS LAST appears like another > challenging step to getting window functions wrapped up. Has your > research

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-19 Thread Gavin Sherry
On Fri, 19 Jan 2007, Tom Lane wrote: > Gavin Sherry <[EMAIL PROTECTED]> writes: > > What we want to do is have a kind of 'sub plan' for each aggregate. In > > effect, the plan might start looking like a directed graph. Here is part > > of the plan as a directed graph. > > >

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-19 Thread Karen Hill
Stefan Kaltenbrunner wrote: > Karen Hill wrote: > > Gavin Sherry wrote: > >> Recenly, I've been researching and putting together a proposal for window > >> functions. > > > > Implementing NULLS FIRST and NULLS LAST appears like another > > challenging step to getting window functions wrapped up.

Re: [HACKERS] Planning aggregates which require sorted or distinct

2007-01-19 Thread Stefan Kaltenbrunner
Karen Hill wrote: > Gavin Sherry wrote: >> Recenly, I've been researching and putting together a proposal for window >> functions. > > Implementing NULLS FIRST and NULLS LAST appears like another > challenging step to getting window functions wrapped up. Has your > research lead you to any ideas

Re: [HACKERS] Planning aggregates which require sorted or distinct input

2007-01-19 Thread Karen Hill
Gavin Sherry wrote: > Recenly, I've been researching and putting together a proposal for window > functions. Implementing NULLS FIRST and NULLS LAST appears like another challenging step to getting window functions wrapped up. Has your research lead you to any ideas on what your strategy for NULL

Re: [HACKERS] Planning aggregates which require sorted or distinct input

2007-01-19 Thread Tom Lane
Gavin Sherry <[EMAIL PROTECTED]> writes: > What we want to do is have a kind of 'sub plan' for each aggregate. In > effect, the plan might start looking like a directed graph. Here is part > of the plan as a directed graph. >GroupAggregate > /

[HACKERS] Planning aggregates which require sorted or distinct input

2007-01-18 Thread Gavin Sherry
Recenly, I've been researching and putting together a proposal for window functions. I have not finished this but when I do, I will post it. A nice list of examples can be found here[1]. Rather than spend a lot of time talking about the problems window functions present to the planner and executor