seq-scan or index-scan

Поиск
Список
Период
Сортировка
От Andreas Kretschmer
Тема seq-scan or index-scan
Дата
Msg-id 20120703155859.GA5956@tux
обсуждение исходный текст
Ответы Re: seq-scan or index-scan  ("Tomas Vondra" <tv@fuzzy.cz>)
Re: seq-scan or index-scan  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Dear list,

i have a table and i'm selecting all records without a where-condition, and i don't need a ORDER BY:



production=*# explain analyse select * from boxes;
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on boxes  (cost=0.00..990783.99 rows=6499 width=581) (actual time=6.514..4588.136 rows=3060 loops=1)
 Total runtime: 4588.729 ms
(2 rows)


It's slow, so i tried with an ORDER BY:



production=# explain analyse select * from boxes order by id;
                                                           QUERY PLAN

--------------------------------------------------------------------------------------------------------------------------------
 Index Scan using boxes_pkey on boxes  (cost=0.00..162437.00 rows=6499 width=581) (actual time=0.065..55.730 rows=3060
loops=1)
 Total runtime: 56.169 ms
(2 rows)


Why not using the index (it's a primary key) for the first query?

PG 9.1.3



Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: ERROR: function crosstab(unknown, unknown) does not exist
Следующее
От: "Tomas Vondra"
Дата:
Сообщение: Re: seq-scan or index-scan