Re: Best database structure for timely ordered values
От | Tom Lane |
---|---|
Тема | Re: Best database structure for timely ordered values |
Дата | |
Msg-id | 20107.977162057@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: Best database structure for timely ordered values (Reiner Dassing <dassing@wettzell.ifag.de>) |
Список | pgsql-sql |
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
В списке pgsql-sql по дате отправления: