Re: Seq scan vs. Index scan with different query conditions

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: Seq scan vs. Index scan with different query conditions
Дата
Msg-id 40E93E5C.1000907@archonet.com
обсуждение исходный текст
Ответ на Seq scan vs. Index scan with different query conditions  (eleven@ludojad.itpp.pl)
Список pgsql-performance
eleven@ludojad.itpp.pl wrote:

> ->  Index Scan using "DateTimeIndex" on "tablex"  (cost=0.00..298272.66 rows=89903 width=8)

> ->  Seq Scan on "tablex"  (cost=0.00..307137.34 rows=97900 width=8)

> Basically, the difference is in upper "Time" value (as you can see, it's
> 18:01:00 in the first query and 19:01:00 in the other one).
> The question is - why does it use index in first case and
> it tries to do full sequential scan when the upper "Time" value
> is different?

Look at the rows, and more importantly the cost. PG thinks the cost in
the second case (seq scan) is only slightly more than in the first case
(index), so presumably the index scan worked out more expensive.

You can test this by issuing "SET ENABLE_SEQSCAN=OFF;" and re-running
the second explain.

Now, the question is whether PG is right in these cost estimates. You'll
need to run "EXPLAIN ANALYSE" rather than just EXPLAIN to see what it
actually costs.

PS - all the usual questions: make sure you've vacuumed, have you read
the tuning document on varlena.com?

--
   Richard Huxton
   Archonet Ltd

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

Предыдущее
От: eleven@ludojad.itpp.pl
Дата:
Сообщение: Seq scan vs. Index scan with different query conditions
Следующее
От: Andrew McMillan
Дата:
Сообщение: Re: Seq scan vs. Index scan with different query