pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Reiner Dassing <dassing@wettzell.ifag.de>
Cc: Bruce Momjian <pgman@candle.pha.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: Best database structure for timely ordered values
Date: Mon, 18 Dec 2000 12:54:17 -0500
Message-ID: <20107.977162057@sss.pgh.pa.us> (raw)
In-Reply-To: <3A3E45CA.E5A84504@wettzell.ifag.de>
References: <200012181646.LAA29528@candle.pha.pa.us>
	<3A3E45CA.E5A84504@wettzell.ifag.de>

Reiner Dassing <dassing@wettzell.ifag.de> writes:
> Here is another example, which is even worse:
> select value from table where id=1 order by epoch desc limit 1;
> to ask for the last stored value.
> This request needs about 5 minutes to complete.

Hm.  That should produce a decent plan given the right indexes.
On 7.0.2 I see:

play=> create table foo (id int, epoch timestamp primary key);
NOTICE:  CREATE TABLE/PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo'
CREATE
play=> explain select * from foo where id=1 order by epoch desc limit 1;
NOTICE:  QUERY PLAN:

Index Scan Backward using foo_pkey on foo  (cost=0.00..62.50 rows=10 width=12)

EXPLAIN

which ought to work pretty well unless id=1 is very rare.

> The explain statements results in:

> explain select * from table where id=1 order by epoche desc limit 1;
> NOTICE:  QUERY PLAN:

> Sort  (cost=12692.74 rows=202175 width=16)
>   -> Index Scan using wetter_pkey on table  (cost=12692.74 rows=202175 width=16)

That's not very informative, since you haven't told us what that index is...

			regards, tom lane



view thread (7+ messages)

Message-ID: <20107.977162057@sss.pgh.pa.us>
Permalink:  ../20107.977162057@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20107.977162057@sss.pgh.pa.us

 · 

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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dassing@wettzell.ifag.de, pgman@candle.pha.pa.us
  Subject: Re: Best database structure for timely ordered values
  In-Reply-To: <20107.977162057@sss.pgh.pa.us>
  References: <200012181646.LAA29528@candle.pha.pa.us> <3A3E45CA.E5A84504@wettzell.ifag.de> <20107.977162057@sss.pgh.pa.us>

* 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