Received: from sss.pgh.pa.us (sss.pgh.pa.us [209.114.132.154]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eBIHsl603464 for ; Mon, 18 Dec 2000 12:54:47 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.1/8.11.1) with ESMTP id eBIHsHL20110; Mon, 18 Dec 2000 12:54:18 -0500 (EST) To: Reiner Dassing cc: Bruce Momjian , pgsql-sql@postgresql.org Subject: Re: Best database structure for timely ordered values In-reply-to: <3A3E45CA.E5A84504@wettzell.ifag.de> References: <200012181646.LAA29528@candle.pha.pa.us> <3A3E45CA.E5A84504@wettzell.ifag.de> Comments: In-reply-to Reiner Dassing message dated "Mon, 18 Dec 2000 18:13:46 +0100" Date: Mon, 18 Dec 2000 12:54:17 -0500 Message-ID: <20107.977162057@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200012/200 X-Sequence-Number: 534 Reiner Dassing 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