Re: [HACKERS] WITHIN GROUP patch

2014-01-07 Thread Tom Lane
I wrote: > There's probably some overhead from traversing advance_transition_function > for each row, which your version wouldn't have done. 15% sounds pretty > high for that though, since advance_transition_function doesn't have much > to do when the transition function is non strict and the stat

Re: [HACKERS] WITHIN GROUP patch

2014-01-07 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> The key reason for that was, and remains, not having the > Tom> behavior hard-wired in nodeAgg; I believe that this design > Tom> permits things to be accomplished in aggregate implementation > Tom> functions that would not have been po

Re: [HACKERS] WITHIN GROUP patch

2014-01-07 Thread Andrew Gierth
> "Tom" == Tom Lane writes: >> Furthermore, I can't help noticing that the increased complexity >> has now pretty much negated your original arguments for moving so >> much of the work out of nodeAgg.c. Tom> The key reason for that was, and remains, not having the Tom> behavior hard-wir

Re: [HACKERS] WITHIN GROUP patch

2014-01-07 Thread Tom Lane
Andrew Gierth writes: > Retesting with your changes shows that the gap is down to 15% but still > present: There's probably some overhead from traversing advance_transition_function for each row, which your version wouldn't have done. 15% sounds pretty high for that though, since advance_transit

Re: [HACKERS] WITHIN GROUP patch

2014-01-07 Thread Andrew Gierth
> "Tom" == Tom Lane writes: >> Initial tests suggest that your version is ~40% slower than ours on >> some workloads. Tom> I poked at this a bit with perf and oprofile, and concluded that Tom> probably the difference comes from ordered_set_startup() Tom> repeating lookups for each group

Re: [HACKERS] WITHIN GROUP patch

2014-01-04 Thread David Rowley
On Sun, Jan 5, 2014 at 12:00 PM, Tom Lane wrote: > > > Looking at this example makes me wonder if it wouldn't be worthwhile to > provide a way to reset and re-use a tuplesort object, instead of redoing > all the lookup work involved. Or maybe just find a way to cache the > catalog lookups that ar

Re: [HACKERS] WITHIN GROUP patch

2014-01-04 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> I've committed this after significant editorialization --- most > Tom> notably, I pushed control of the sort step into the aggregate > Tom> support functions. > Initial tests suggest that your version is ~40% slower than ours on > some

Re: [HACKERS] WITHIN GROUP patch

2013-12-28 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> I've committed this after significant editorialization --- most Tom> notably, I pushed control of the sort step into the aggregate Tom> support functions. Initial tests suggest that your version is ~40% slower than ours on some workloads. On my system, th

Re: [HACKERS] WITHIN GROUP patch

2013-12-24 Thread Atri Sharma
Sent from my iPad > On 24-Dec-2013, at 2:50, Tom Lane wrote: > > Atri Sharma writes: >> Please find attached the latest patch for WITHIN GROUP. This patch is >> after fixing the merge conflicts. > > I've committed this after significant editorialization --- most notably, > I pushed control o

Re: [HACKERS] WITHIN GROUP patch

2013-12-23 Thread Tom Lane
Atri Sharma writes: > Please find attached the latest patch for WITHIN GROUP. This patch is > after fixing the merge conflicts. I've committed this after significant editorialization --- most notably, I pushed control of the sort step into the aggregate support functions. I didn't like the way no

Re: [HACKERS] WITHIN GROUP patch

2013-12-23 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> What I'm now thinking we want to do is: Tom> 1. Non-hypothetical direct args always contribute to determining Tom> the agg's collation. Tom> 2. Hypothetical and aggregated args contribute to the agg's Tom> collation only if the agg is designed so that t

Re: [HACKERS] WITHIN GROUP patch

2013-12-23 Thread Tom Lane
I wrote: > Or, really, why don't we just do the same thing I'm advocating for > the plain-ordered-set case? That is, if there's a single collation > applying to all the collatable inputs, that's the collation to use > for the aggregate; otherwise it has no determinate collation, and > it'll throw

Re: [HACKERS] WITHIN GROUP patch

2013-12-22 Thread Tom Lane
I wrote: > ... So my reaction to this example is not > that we should hack the behavior for plain ordered-set aggregates, > but that we ought to find a rule that allows result-collation > determination for hypotheticals. We speculated upthread about > "merge the collations normally, but ignore inp

Re: [HACKERS] WITHIN GROUP patch

2013-12-22 Thread Tom Lane
Andrew Gierth writes: > The examples I've thought of which would return collatable types are > all ones that would be implemented as plain ordered set functions even > if their logic was in some sense hypothetical. For example you could > envisage a value_prec(x) within group (order by y) that ret

Re: [HACKERS] WITHIN GROUP patch

2013-12-22 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> I eventually decided that we were overthinking this problem. At Tom> least for regular ordered-set aggregates, we can just deem that Tom> the collation of the aggregate is indeterminate unless all the Tom> inputs (both direct and aggregated) agree on the

Re: [HACKERS] WITHIN GROUP patch

2013-12-21 Thread Tom Lane
[ still hacking away at this patch ] Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> Not wanting to consider the sort args when there's more than one > Tom> doesn't square with forcing them to be considered when there's > Tom> just one. It's the same aggregate after all, > This log

Re: [HACKERS] WITHIN GROUP patch

2013-12-09 Thread Peter Eisentraut
On 11/21/13, 5:04 AM, Atri Sharma wrote: > Please find attached the latest patch for WITHIN GROUP. This patch is > after fixing the merge conflicts. I would like to see more explanations and examples in the documentation. You introduce this feature with "Ordered set functions compute a single res

Re: [HACKERS] WITHIN GROUP patch

2013-12-08 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> We could alternatively decide that the agg has level 0, but that Tom> doesn't seem terribly useful, and I think it's not per spec Tom> either. SQL:2008 section 6.9 seems Tom> pretty clear that only aggregated arguments should be considered Tom> when det

Re: [HACKERS] WITHIN GROUP patch

2013-12-08 Thread Tom Lane
Andrew Gierth writes: > There's also the question of ungrouped vars, maybe. Consider these two > queries: > select array(select a+sum(x) from (values (0.3),(0.7)) v(a) group by a) > from generate_series(1,5) g(x); > select array(select percentile_disc(a) within group (order by x) >

Re: [HACKERS] WITHIN GROUP patch

2013-12-07 Thread Andrew Gierth
> "Tom" == Tom Lane writes: >> Hmm... yes, you're probably right; but we'd still have to check >> somewhere for improper nesting, no? since not even the direct args >> are allowed to contain nested aggregate calls. Tom> Yeah, I had come to that same conclusion while making the Tom> chan

Re: [HACKERS] WITHIN GROUP patch

2013-12-07 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> After examining this more closely, ISTM that the direct > Tom> arguments are supposed to be processed as if they weren't inside > Tom> an aggregate call at all. That being the case, isn't it flat > Tom> out wrong for check_agg_argument

Re: [HACKERS] WITHIN GROUP patch

2013-12-07 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> After examining this more closely, ISTM that the direct Tom> arguments are supposed to be processed as if they weren't inside Tom> an aggregate call at all. That being the case, isn't it flat Tom> out wrong for check_agg_arguments() to be examining the T

Re: [HACKERS] WITHIN GROUP patch

2013-12-07 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> I believe that the spec requires that the "direct" arguments of > Tom> an inverse or hypothetical-set aggregate must not contain any > Tom> Vars of the current query level. > False. After examining this more closely, ISTM that the dire

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> Not wanting to consider the sort args when there's more than one Tom> doesn't square with forcing them to be considered when there's Tom> just one. It's the same aggregate after all, This logic is only applied in the patch to aggregates that _aren't_ hypo

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> Meh. I don't think you can have that and also have the behavior > Tom> that multiple ORDER BY items aren't constrained to have the same > Tom> collation; at least not without some rule that amounts to a > Tom> special case for percenti

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> 2. For an ordered set function, n must equal aggnfixedargs. We Tom> treat all n fixed arguments as contributing to the aggregate's Tom> result collation, but ignore the sort arguments. >> That doesn't work for getting a sensible collation out of >> perc

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Tom Lane
Andrew Gierth writes: > The patch as submitted answers those questions as follows: > CREATE AGGREGATE func(integer) WITHIN GROUP (text) ... You've glossed over a significant amount of complexity, as shown by your example that prints WITHIN GROUP (*), a syntax that you've not defined here. In th

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Andrew Gierth
> "Josh" == Josh Berkus writes: >> Since I don't particularly trust my own judgement on aesthetics, I >> used the feedback I got from others when deciding what to >> do. Frankly I think this one needs wider input than just you and >> me arguing over it. Josh> Can someone paste examples

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Tom Lane
Josh Berkus writes: > Can someone paste examples of the two syntax alternatives we're talking > about here? I've lost track. I'll leave it to Andrew to describe/defend exactly what his patch is doing. The alternative I'm thinking about is that in CREATE AGGREGATE as well as \da output, the argu

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> Another thing to think about here is to wonder why the committee chose Tom> anything as verbose as "agg(...) WITHIN GROUP (ORDER BY ...)" in the Tom> first place. The words ORDER BY certainly seem pretty unnecessary. All of the ordered-set functions that

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Josh Berkus
On 12/06/2013 01:30 PM, Andrew Gierth wrote: > Since I don't particularly trust my own judgement on aesthetics, I used > the feedback I got from others when deciding what to do. Frankly I think > this one needs wider input than just you and me arguing over it. Can someone paste examples of the two

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Andrew Gierth
> "Tom" == Tom Lane writes: >> pg_get_function_arguments()'s interface assumes that the caller is >> providing the enclosing parens. Changing it would have meant >> returning a result like 'float8) WITHIN GROUP (float8' which I >> reckoned would have too much chance of breaking existing c

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> Actually, now that I think of it, why not use this syntax for > Tom> declaration and display purposes: > Tom> type1, type2 ORDER BY type3, type4 > But unfortunately it looks exactly like the calling sequence for a > normal aggre

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread David Johnston
Andrew Gierth wrote >> "Tom" == Tom Lane < > tgl@.pa > > writes: > > >> Please don't object that that doesn't look exactly like the syntax > >> for calling the function, because it doesn't anyway --- remember > >> you also need ORDER BY in the call. > > Tom> Actually, now that I think o

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Andrew Gierth
> "Tom" == Tom Lane writes: >> Please don't object that that doesn't look exactly like the syntax >> for calling the function, because it doesn't anyway --- remember >> you also need ORDER BY in the call. Tom> Actually, now that I think of it, why not use this syntax for Tom> declaratio

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Tom Lane
I wrote: > One possibility is to forget all the parens and say that the display > looks like > type1, type2 WITHIN GROUP type3, type4 > Please don't object that that doesn't look exactly like the syntax > for calling the function, because it doesn't anyway --- remember you > also need ORDER B

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> Regardless of that, though ... what is the reasoning for > Tom> inventing pg_get_aggregate_arguments() rather than just making > Tom> pg_get_function_arguments() do the right thing? > pg_get_function_arguments()'s interface assumes that

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> Regardless of that, though ... what is the reasoning for Tom> inventing pg_get_aggregate_arguments() rather than just making Tom> pg_get_function_arguments() do the right thing? pg_get_function_arguments()'s interface assumes that the caller is providing t

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Tom Lane
I don't especially like the syntax you invented for listing arguments in CREATE AGGREGATE, especially not the WITHIN GROUP (*) special case. If we stick with that we're going to need to touch a lot more places than you have, notably regprocedure. I also fear that this syntax is not appropriate for

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> I believe that the spec requires that the "direct" arguments of > Tom> an inverse or hypothetical-set aggregate must not contain any > Tom> Vars of the current query level. > In any event, going by the docs on the web, Oracle does not f

Re: [HACKERS] WITHIN GROUP patch

2013-12-06 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> Further questions about WITHIN GROUP: Tom> I believe that the spec requires that the "direct" arguments of Tom> an inverse or hypothetical-set aggregate must not contain any Tom> Vars of the current query level. False. The spec requires that the direct

Re: [HACKERS] WITHIN GROUP patch

2013-12-05 Thread Tom Lane
David Johnston writes: > The original design references the spec as allowing a column reference if it > is a group by key: > Select cume_dist(f1) within group ( order by f1 ) from text_tbl group by f1 > No example was shown where this would be useful...but nonetheless the > comment and error bot

Re: [HACKERS] WITHIN GROUP patch

2013-12-05 Thread David Johnston
Tom Lane-2 wrote > Further questions about WITHIN GROUP: > > I believe that the spec requires that the "direct" arguments of an inverse > or hypothetical-set aggregate must not contain any Vars of the current > query level. They don't manage to say that in plain English, of course, > but in the

Re: [HACKERS] WITHIN GROUP patch

2013-12-05 Thread Tom Lane
Further questions about WITHIN GROUP: I believe that the spec requires that the "direct" arguments of an inverse or hypothetical-set aggregate must not contain any Vars of the current query level. They don't manage to say that in plain English, of course, but in the case the behavior is defined

Re: [HACKERS] WITHIN GROUP patch

2013-12-04 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> But anyway, what I'm thinking right now is that these questions > Tom> would all go away if the aggregate transfunction were receiving > Tom> the rows and sticking them into the tuplestore. It could add > Tom> whatever columns it felt

Re: [HACKERS] WITHIN GROUP patch

2013-12-04 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> Well, sure, but I was only suggesting adding it when the Tom> aggregate asks for it, probably via a new flag column in Tom> pg_aggregate. Sure, I was only pointing out the necessity. Tom> The question you're evading is what additional functionality Tom>

Re: [HACKERS] WITHIN GROUP patch

2013-12-04 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> Well, okay, but you've not said anything that wouldn't be > Tom> handled just as well by some logic that adds a fixed > Tom> integer-constant-zero flag column to the rows going into the > Tom> tuplesort. > Adding such a column uncondit

Re: [HACKERS] WITHIN GROUP patch

2013-12-04 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> Well, okay, but you've not said anything that wouldn't be Tom> handled just as well by some logic that adds a fixed Tom> integer-constant-zero flag column to the rows going into the Tom> tuplesort. Adding such a column unconditionally even for non-hypothe

Re: [HACKERS] WITHIN GROUP patch

2013-12-03 Thread Tom Lane
Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> 1. I really hate the way you've overloaded the transvalue to do > Tom> something that has approximately nothing to do with transition > Tom> state (and haven't updated catalogs.sgml to explain that, > Tom> either). Seems like it'd be c

Re: [HACKERS] WITHIN GROUP patch

2013-12-03 Thread Andrew Gierth
> "Tom" == Tom Lane writes: Tom> 1. I really hate the way you've overloaded the transvalue to do Tom> something that has approximately nothing to do with transition Tom> state (and haven't updated catalogs.sgml to explain that, Tom> either). Seems like it'd be cleaner to just hardwire a

Re: [HACKERS] WITHIN GROUP patch

2013-12-03 Thread Tom Lane
Atri Sharma writes: > Please find attached the latest patch for WITHIN GROUP. This patch is > after fixing the merge conflicts. I've started to look at this patch now. I have a couple of immediate reactions to the catalog changes: 1. I really hate the way you've overloaded the transvalue to do

Re: [HACKERS] WITHIN GROUP patch

2013-11-21 Thread Andrew Gierth
> "Vik" == Vik Fearing writes: Vik> I certainly want it. I do not have a copy of the SQL standard, Vik> but I have full faith in the Andrew Gierth's claim that this is Vik> part of it. For reference, this is how I believe it matches up against the spec (I'm working from the 2008 final):

Re: [HACKERS] WITHIN GROUP patch

2013-11-21 Thread Vik Fearing
On 11/21/2013 11:04 AM, Atri Sharma wrote: > Please find attached the latest patch for WITHIN GROUP. This patch is > after fixing the merge conflicts. I have spent quite some time on this and the previous versions. Here is my review, following the questions on the wiki. This patch is in context

Re: [HACKERS] WITHIN GROUP patch

2013-11-17 Thread Peter Eisentraut
On Fri, 2013-11-15 at 00:05 +0530, Atri Sharma wrote: > Please find the latest version of the patch. This version fixes the > issues pointed out by the reviewer and the divide by zero bug in > percent_rank function. This version also adds a regression test for > the divide by zero case in percent_r

Re: [HACKERS] WITHIN GROUP patch

2013-11-04 Thread Vik Fearing
On 11/04/2013 08:43 AM, Atri Sharma wrote: > Please find attached our latest version of the patch. This version > fixes the issues pointed out by the reviewers. No, it doesn't. The documentation still contains formatting and grammatical errors, and the code comments still do not match the their s

Re: [HACKERS] WITHIN GROUP patch

2013-10-15 Thread Vik Fearing
On 10/09/2013 04:19 PM, Pavel Stehule wrote: > > I checked a conformance with ANSI SQL - and I didn't find any issue. > > I found so following error message is not too friendly (mainly > because this functionality will be new) > > postgres=# select dense_rank(3,3,2) within group (or

Re: [HACKERS] WITHIN GROUP patch

2013-10-11 Thread Robert Haas
On Thu, Oct 10, 2013 at 10:35 PM, Andrew Gierth wrote: > The first alternative that springs to mind is: > > ERROR: Incorrect number of arguments for hypothetical set function > DETAIL: Number of hypothetical arguments (3) must equal number of ordered > columns (2) I'd suggest trying to collapse

Re: [HACKERS] WITHIN GROUP patch

2013-10-10 Thread Pavel Stehule
2013/10/11 Andrew Gierth > > "Pavel" == Pavel Stehule writes: > > >> I found so following error message is not too friendly (mainly because > >> this functionality will be new) > >> > >> postgres=# select dense_rank(3,3,2) within group (order by num desc, > odd) > >> from test4; > >> E

Re: [HACKERS] WITHIN GROUP patch

2013-10-10 Thread Andrew Gierth
> "Pavel" == Pavel Stehule writes: >> I found so following error message is not too friendly (mainly because >> this functionality will be new) >> >> postgres=# select dense_rank(3,3,2) within group (order by num desc, odd) >> from test4; >> ERROR: Incorrect number of arguments for hy

Re: [HACKERS] WITHIN GROUP patch

2013-10-09 Thread Pavel Stehule
2013/10/9 Pavel Stehule > Hello > > I checked a conformance with ANSI SQL - and I didn't find any issue. > > I found so following error message is not too friendly (mainly because > this functionality will be new) > > postgres=# select dense_rank(3,3,2) within group (order by num desc, odd) > fro