Does anybody use ORDER BY x USING y?

Lists: pgsql-hackers
From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Does anybody use ORDER BY x USING y?
Date: 2005-09-18 17:20:49
Message-ID: 20050918172036.GC31394@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

PostgreSQL's grammer allows you to specify the operator to sort with in
the ORDER BY clause. Various bits of the backend support this feature,
yet it appears to partially undocumented. I can't find it in the ORDER
BY [1] section but there is a paragraph on it under the SELECT
documentation [2].

I'm asking because SQL COLLATE support is really doing something
similar. I was wondering if instead of adding something in parallel just
replace sortop with collateid. This means all the code relating to
pathkeys won't need to change since we still use OIDs for the pathkeys,
they're just not operator oids anymore.

We can continue to support USING [op] as long as [op] is one of the GT
or LT operators in the OPERATOR CLASS. This restriction may exist
already, I can't tell.

All we lose is the ability to say USING [arbitrary op]. Does anybody
use this. Would people object to requiring the operator after USING to
be part of an operator class?

Have a nice day,

[1] http://www.postgresql.org/docs/8.0/interactive/queries-order.html
[2] http://www.postgresql.org/docs/8.0/interactive/sql-select.html
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org, Martijn van Oosterhout <kleptog(at)svana(dot)org>
Subject: Re: Does anybody use ORDER BY x USING y?
Date: 2005-09-18 19:34:10
Message-ID: 200509181234.11040.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Martjin,

> We can continue to support USING [op] as long as [op] is one of the GT
> or LT operators in the OPERATOR CLASS. This restriction may exist
> already, I can't tell.
>
> All we lose is the ability to say USING [arbitrary op]. Does anybody
> use this. Would people object to requiring the operator after USING to
> be part of an operator class?

Hmmm ... would this prevent the hackish workaround for case-insensitive sort?

--
Josh Berkus
Aglio Database Solutions
San Francisco


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Does anybody use ORDER BY x USING y?
Date: 2005-09-18 20:01:22
Message-ID: 20050918200117.GD31394@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Sep 18, 2005 at 12:34:10PM -0700, Josh Berkus wrote:
> > All we lose is the ability to say USING [arbitrary op]. Does anybody
> > use this. Would people object to requiring the operator after USING to
> > be part of an operator class?
>
> Hmmm ... would this prevent the hackish workaround for case-insensitive sort?

Err, which hackish workaround would that be? The right solution is
citext which creates it's own operator class. This doesn't have
anything to do with functional indexes either.

I've been using Google to find any interesting use of the USING clause
but havn't found any yet.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Does anybody use ORDER BY x USING y?
Date: 2005-09-18 20:19:06
Message-ID: 432DCBBA.1070201@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Martijn van Oosterhout wrote:

>On Sun, Sep 18, 2005 at 12:34:10PM -0700, Josh Berkus wrote:
>
>
>>>All we lose is the ability to say USING [arbitrary op]. Does anybody
>>>use this. Would people object to requiring the operator after USING to
>>>be part of an operator class?
>>>
>>>
>>Hmmm ... would this prevent the hackish workaround for case-insensitive sort?
>>
>>
>
>Err, which hackish workaround would that be? The right solution is
>citext which creates it's own operator class. This doesn't have
>anything to do with functional indexes either.
>
>

Last time I looked it appeared to have significant limitations, and some
considerable inefficiencies (e.g, copying the strings and folding them
to canonical case on every comparison). I would certainly be extremely
wary of just saying "that's the solution".

cheers

andrew


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Does anybody use ORDER BY x USING y?
Date: 2005-09-18 20:28:34
Message-ID: 20050918202822.GE31394@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Sep 18, 2005 at 04:19:06PM -0400, Andrew Dunstan wrote:
> >Err, which hackish workaround would that be? The right solution is
> >citext which creates it's own operator class. This doesn't have
> >anything to do with functional indexes either.
>
> Last time I looked it appeared to have significant limitations, and some
> considerable inefficiencies (e.g, copying the strings and folding them
> to canonical case on every comparison). I would certainly be extremely
> wary of just saying "that's the solution".

Ok, so citext has its limitations. Case-insensetive sort is hard [1].
My real question was, what was the solution he was referring to using
the USING clause?

[1] http://lafstern.org/matt/col2_new.pdf

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Does anybody use ORDER BY x USING y?
Date: 2005-09-20 11:22:12
Message-ID: 20050920112207.GD8586@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

<much discussion on collation and ordering>

I'm going to take from this discussion that there is no use for the
USING clause with operators not in an operator class and that if this
changes we won't be seriously inconveniencing anybody.

Have a nice day,

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.