Re: Execution plan does not use index

2020-11-11 Thread Peter Coppens
> Good luck! Tx! And tx for your support.

Re: Execution plan does not use index

2020-11-11 Thread Michael Lewis
On Wed, Nov 11, 2020, 7:30 AM Peter Coppens wrote: > > > It seems odd to me to not do any basic adjustment of random_page_cost > though. It isn't a magic number that the core team know to be perfect. It > is a baseline that is likely to be quite different for each use case and > server config. Wh

Re: Execution plan does not use index

2020-11-11 Thread Peter Coppens
> > Ahhh. You don't have a single column index on the timestamp value or a multi > column one with timestamp first. No wonder the subquery didn't help. My > apologies for not realizing that before. Thanks for satisfying my curiosity > why it didn't perform like it should. Certainly, that index

Re: Execution plan does not use index

2020-11-11 Thread Michael Lewis
On Tue, Nov 10, 2020, 10:51 PM Peter Coppens wrote: > If you disable sequential scan, does it choose the index and what cost > does it show? > > > It chooses the index, but apparently to create some intermediate structure > that then later still needs to be joined on the device_id. Probably > req

Re: Execution plan does not use index

2020-11-10 Thread Peter Coppens
> Curious, how accurate is that row count of 1.2 million records for 3 days? Not to bad actually select count(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'

Re: Execution plan does not use index

2020-11-10 Thread Michael Lewis
On Tue, Nov 10, 2020, 3:24 PM Peter Coppens wrote: > 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

Re: Execution plan does not use index

2020-11-10 Thread Peter Coppens
> > 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 a

Re: Execution plan does not use index

2020-11-10 Thread Michael Lewis
On Tue, Nov 10, 2020 at 1:25 AM Peter Coppens wrote: > Triggered by Michael mentioning subqueries I ended up trying > > explain > select d.short_id,mv.timestamp ,mv.I64_01 > from device d, device_configuration dc, measurement_value mv > where mv.device_id=d.short_id and dc.device_id = d.id

Re: Execution plan does not use index

2020-11-10 Thread Peter Coppens
Triggered by Michael mentioning subqueries I ended up trying explain select d.short_id,mv.timestamp ,mv.I64_01 from device d, device_configuration dc, measurement_value mv where mv.device_id=d.short_id and dc.device_id = d.id and dc.latest=true and mv.timestamp > '2020-11-06'::times

Re: Execution plan does not use index

2020-11-10 Thread Peter Coppens
Pavel Tx for the tip. But given that if the I64_01 column is removed from the select list, the index is used I guess the cast is not likely to be the cause. Like so explain select d.short_id,mv.timestamp --,mv.I64_01 from device d, device_configuration dc, measurement_value mv, pg_timezo

Re: Execution plan does not use index

2020-11-09 Thread Pavel Stehule
út 10. 11. 2020 v 8:18 odesílatel Peter Coppens napsal: > Michael > > Many thanks for spending your time on this. Your alternative does not help > unfortunately (see execution plan) > > Still a sequential scan on the complete table. I have tried many > alternatives and somehow whenever I add a co

Re: Execution plan does not use index

2020-11-09 Thread Peter Coppens
Michael Many thanks for spending your time on this. Your alternative does not help unfortunately (see execution plan) Still a sequential scan on the complete table. I have tried many alternatives and somehow whenever I add a column that is not in the index (I64_01) the optimizer decides not to

Re: Execution plan does not use index

2020-11-09 Thread Michael Lewis
On Mon, Nov 9, 2020 at 1:11 PM Peter Coppens wrote: > Adding the tzn.utc_offset results in the fact that the execution plan no > longer considers to use the index on the measurement_value table. Is there > any way the SQL can be rewritten so that the index is used? Or any other > solution so that

Execution plan does not use index

2020-11-09 Thread Peter Coppens
Hello, Consider the following PostgreSQL 9.6.18 tables - measurement_value: time series table with a unique key on (device_id,timestamp) columns and a number of columns with measurements. Table contains a large number of rows (>150million) - device table: with device properties (short_id joins to