Re: Execution plan does not use index

Поиск
Список
Период
Сортировка
От Peter Coppens
Тема Re: Execution plan does not use index
Дата
Msg-id 70D29A79-C968-4310-B4D7-3203A739F261@datylon.com
обсуждение исходный текст
Ответ на Re: Execution plan does not use index  (Michael Lewis <mlewis@entrata.com>)
Ответы Re: Execution plan does not use index  (Michael Lewis <mlewis@entrata.com>)
Список pgsql-general

Curious, what is seq_page_cost and random_page_cost?

show seq_page_cost
->1

show random_page_cost
->4


Any idea of your cache hits for indexes?

No, I am afraid not. It’s been a long time since I went that deep in the RDBMS behaviour (must have been Oracle 7.something  :) )


If they are very high and/or you have SSD or similar fast storage, then maybe random_page_cost should be 1.1-2 and not default 4 (assuming seq_page_cost is still 1). The planner will be more likely to use an index scan if the expected cost for scanning an index (random) is closer to a sequential read. Sorry if this explanation is completely superfluous and you have already configured this.

I played around with some of the settings (also with setting enable_seqscan to false). While some of the plans did no longer use a full table scan, the performance did not really work out when I tried. Tbh, I never got too deep in those plans to find out why that would be, as I am not too keen on changing these settings in the first place.


It would be interesting to see explain (analyze buffers) output so we can see the actual counts for these nodes. I'm rather surprised that the query I provided didn't use the timestamp index unless the inclusion of 3 days worth of range meant that it was estimated to be too high a fraction of the table. If you just execute only the subquery, is the index used by chance?

Index is not used for the subquery

explain 
select mv_inner.*
  from measurement_value AS mv_inner
  where mv_inner.timestamp > '2020-11-06'::timestamp - interval '1 day' and mv_inner.timestamp < '2020-11-07'::timestamp + interval '1 day'
offset 0

==>

Seq Scan on measurement_value mv_inner (cost=0.00..7175777.00 rows=1219616 width=1006)
  Filter: (("timestamp" > '2020-11-05 00:00:00'::timestamp without time zone) AND ("timestamp" < '2020-11-08 00:00:00'::timestamp without time zone))



Top posting (reply with all previous copied below) is discouraged on these lists. I think because it makes the archives rather messy. 

Will try to remember

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

Предыдущее
От: Michael Lewis
Дата:
Сообщение: Re: Execution plan does not use index
Следующее
От: Michael Lewis
Дата:
Сообщение: Re: Execution plan does not use index