Re: Efficiency Question

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Colin Fox <cfox(at)cfconsulting(dot)ca>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Efficiency Question
Date: 2002-09-09 13:57:31
Message-ID: 20020909135731.GA1461@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Sep 09, 2002 at 00:13:04 +0000,
Colin Fox <cfox(at)cfconsulting(dot)ca> wrote:
>
> select
> *
> from
> motm
> order by
> creation_date desc
> limit 1;
>
> So in the first case I select the record that has the largest date. In the
> second case, I order all the records, and then return only one.

If you have an index on creation_date an index scan can be used which
will make the second form run a lot faster if there are lots of records.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Viacheslav N Tararin 2002-09-09 14:01:15 Re: new calculated column
Previous Message Viacheslav N Tararin 2002-09-09 12:23:41 Re: the best way to get the topest 3 record in every group