Re: WITHIN GROUP patch

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Atri Sharma <atri(dot)jiit(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Vik Fearing <vik(dot)fearing(at)dalibo(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: WITHIN GROUP patch
Date: 2013-12-22 13:37:37
Message-ID: 87y53dnif6.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> 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 collation to
Tom> use. This gives us the right answer for all the standard
Tom> aggregates, which have at most one collatable input, and it's
Tom> very unclear that anything more complicated would be an
Tom> improvement. I definitely didn't like the hack that was in
Tom> there that'd force a sort column to absorb a possibly-unrelated
Tom> collation.

Yeah, I can go along with that, but see below.

Tom> For hypotheticals, I agree after reading the spec text that
Tom> we're supposed to unify the collations of matching hypothetical
Tom> and aggregated arguments to determine the collation to use for
Tom> sorting that column.

Yeah, the spec seemed clear enough on that.

Tom> I see that the patch just leaves these columns out of the
Tom> determination of the aggregate's result collation. That's okay
Tom> for the time being at least, since we have no hypotheticals with
Tom> collatable output types, but I wonder if anyone wants to argue
Tom> for some other rule (and if so, what)?

Any alternative seems a bit ad-hoc to me.

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 returns the
value of y which sorts immediately before x, but this would just be
declared as value_prec(anyelement) within group (anyelement) rather
than engaging the hypothetical argument stuff. (It's this sort of
thing that suggested pushing down the collation into the sort column
even for non-hypothetical ordered set functions.)

--
Andrew (irc:RhodiumToad)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2013-12-22 15:02:58 Re: ALTER SYSTEM SET command to change postgresql.conf parameters
Previous Message MauMau 2013-12-22 10:51:55 Re: [bug fix] multibyte messages are displayed incorrectly on the client