pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Coppens <peter.coppens@datylon.com>
To: Michael Lewis <mlewis@entrata.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: Execution plan does not use index
Date: Tue, 10 Nov 2020 23:23:59 +0100
Message-ID: <70D29A79-C968-4310-B4D7-3203A739F261@datylon.com> (raw)
In-Reply-To: <CAHOFxGqJE1BsTOqS2sbs6k7Lw--atw0Xufio263xHWzfa_tT=g@mail.gmail.com>
References: <CAEkf4WBnCDcqQXfw4z-TpTYucBE=AEHEQjLd3QvOtMrPrrK6fA@mail.gmail.com>
	<CAHOFxGrR-pOGQEiZdYzTB7EwoeW_3PsP0pxT0RfG3GQV9gPQCg@mail.gmail.com>
	<D797FCC9-FBCD-4206-BCB5-50A2F31C94E6@datylon.com>
	<CAFj8pRB6cxB2KRugFZDFg=ZX7VLpwQouF3C=wPhgv4=ZWaEwgw@mail.gmail.com>
	<1C729C96-97BB-46CF-9457-876DCC395923@datylon.com>
	<64AAA8DD-FD2F-4DFC-BDA4-109C024609B1@datylon.com>
	<CAHOFxGqJE1BsTOqS2sbs6k7Lw--atw0Xufio263xHWzfa_tT=g@mail.gmail.com>

> 
> 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=

view thread (14+ messages)  latest in thread

Message-ID: <70D29A79-C968-4310-B4D7-3203A739F261@datylon.com>
Permalink:  ../70D29A79-C968-4310-B4D7-3203A739F261@datylon.com/
Also on:    postgresql.org/message-id/70D29A79-C968-4310-B4D7-3203A739F261@datylon.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: peter.coppens@datylon.com, mlewis@entrata.com, pavel.stehule@gmail.com
  Subject: Re: Execution plan does not use index
  In-Reply-To: <70D29A79-C968-4310-B4D7-3203A739F261@datylon.com>
  References: <CAEkf4WBnCDcqQXfw4z-TpTYucBE=AEHEQjLd3QvOtMrPrrK6fA@mail.gmail.com> <CAHOFxGrR-pOGQEiZdYzTB7EwoeW_3PsP0pxT0RfG3GQV9gPQCg@mail.gmail.com> <D797FCC9-FBCD-4206-BCB5-50A2F31C94E6@datylon.com> <CAFj8pRB6cxB2KRugFZDFg=ZX7VLpwQouF3C=wPhgv4=ZWaEwgw@mail.gmail.com> <1C729C96-97BB-46CF-9457-876DCC395923@datylon.com> <64AAA8DD-FD2F-4DFC-BDA4-109C024609B1@datylon.com> <CAHOFxGqJE1BsTOqS2sbs6k7Lw--atw0Xufio263xHWzfa_tT=g@mail.gmail.com> <70D29A79-C968-4310-B4D7-3203A739F261@datylon.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox