pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: James Kelty <jamesk@ashlandagency.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Order by clause in 'select distinct'?
Date: Wed, 13 Mar 2002 17:18:32 -0800 (PST)
Message-ID: <20020313171324.N90759-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <MDEDIKPCLCIKDGEMDJGMOEHECDAA.jamesk@ashlandagency.com>

On Wed, 13 Mar 2002, James Kelty wrote:

> When I create a view by a query like the follow query:
>
> SELECT DISTINCT ON (o.ordergenkey) o.ordergenkey, lip.payment FROM Ordr o,
> LineItemPayment lip
> WHERE o.ordergenkey = lip.orderfkey
> and o.ordergenkey = ?
>
> The view is created with an ORDER BY clause on the o.ordergenkey...
>
> I think it might be an enforce rule for createing a view with a DISTINCT ON
> phrase.
>
> I would like to, if possible, get rid of the ORDER BY clause as it slow the
> query to
> a crawl.
>
> Any ideas?

There's not actually an order by, but IIRC distinct on is done with
unique-sort-... plan so the values get sorted before passed to the routine
that does the actual distincting.  I don't think there's a way to get rid
of the sorting step. Perhaps raising sort_mem will make the query run
better.




view thread (2+ messages)

Message-ID: <20020313171324.N90759-100000@megazone23.bigpanda.com>
Permalink:  ../20020313171324.N90759-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20020313171324.N90759-100000@megazone23.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, jamesk@ashlandagency.com
  Subject: Re: Order by clause in 'select distinct'?
  In-Reply-To: <20020313171324.N90759-100000@megazone23.bigpanda.com>
  References: <MDEDIKPCLCIKDGEMDJGMOEHECDAA.jamesk@ashlandagency.com> <20020313171324.N90759-100000@megazone23.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox