Re: Best database structure for timely ordered values

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Reiner Dassing <dassing(at)wettzell(dot)ifag(dot)de>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Best database structure for timely ordered values
Date: 2000-12-18 17:54:17
Message-ID: 20107.977162057@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Reiner Dassing <dassing(at)wettzell(dot)ifag(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ian Lance Taylor 2000-12-18 17:58:02 Re: Re: [SQL] PostgreSQL crashes on me :(
Previous Message Tom Lane 2000-12-18 17:40:32 Re: Re: [SQL] PostgreSQL crashes on me :(