pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Peter Childs <peterachilds@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: optimize query with a maximum(date) extraction
Date: Wed, 5 Sep 2007 14:48:18 +0200
Message-ID: <162867790709050548l3e1fd155g40b745f2ae42834e@mail.gmail.com> (raw)
In-Reply-To: <a2de01dd0709050543j57de8774s9e9e0a576cc21bd1@mail.gmail.com>
References: <302443.65402.qm@web26209.mail.ukl.yahoo.com>
	<87abs1qrhu.fsf@oxford.xeocode.com>
	<87642pqpue.fsf@oxford.xeocode.com>
	<a2de01dd0709050543j57de8774s9e9e0a576cc21bd1@mail.gmail.com>

>
> why not
>
> select id,
>        min(the_date) as min_date,
>        max(the_date) as max_date
>   from my_table group by id;
>
> Since 8.0 or was it earlier this will use an index should a reasonable one
> exist.

without any limits, seq scan is optimal.

Regards
Pavel Stehule



view thread (12+ messages)  latest in thread

Message-ID: <162867790709050548l3e1fd155g40b745f2ae42834e@mail.gmail.com>
Permalink:  ../162867790709050548l3e1fd155g40b745f2ae42834e@mail.gmail.com/
Also on:    postgresql.org/message-id/162867790709050548l3e1fd155g40b745f2ae42834e@mail.gmail.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-performance@postgresql.org
  Cc: pavel.stehule@gmail.com, peterachilds@gmail.com
  Subject: Re: optimize query with a maximum(date) extraction
  In-Reply-To: <162867790709050548l3e1fd155g40b745f2ae42834e@mail.gmail.com>
  References: <302443.65402.qm@web26209.mail.ukl.yahoo.com> <87abs1qrhu.fsf@oxford.xeocode.com> <87642pqpue.fsf@oxford.xeocode.com> <a2de01dd0709050543j57de8774s9e9e0a576cc21bd1@mail.gmail.com> <162867790709050548l3e1fd155g40b745f2ae42834e@mail.gmail.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