From: | Paul Jungwirth <pj(at)illuminatedcomputing(dot)com> |
---|---|
To: | hmidi slim <hmidi(dot)slim2(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Proposition for better performance |
Date: | 2018-03-27 18:25:30 |
Message-ID: | d617ebc2-3e63-ba2a-660f-318dfb08b2a6@illuminatedcomputing.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
(Including the list....)
On 03/27/2018 10:49 AM, hmidi slim wrote:
> Sorry I didn't copy it very well:
> create index idx on availability using gist(during);
>
> and during = daterange(start_date,end_date)
>
> And the query plan used was seq scan not index scan.
It sounds like there must be some important information missing. Here is
my attempt to mock up some fake data:
insert into availability
select p.id, concat('prod ', p.id::text), daterange((now() +
concat(r.v, ' days')::interval)::date, (now() + concat((r.v + 1 +
random() * 21)::int, ' days')::interval)::date)
from (select * from generate_series(1, 1000000)) p(id)
cross join (select * from generate_series(1, 15)) n(i)
join lateral (
select p2.id, n2.i, (random() * 600 - 300)::int AS v
from generate_series(1, 1000000) p2(id),
generate_series(1, 15) n2(i)
) r
on r.id = p.id and r.i = n.i
;
Then
explain select * from availability where during @>
daterange('2018-03-27', '2018-03-31');
QUERY PLAN
-----------------------------------------------------------------------------
Index Scan using idx on availability (cost=0.39..1644.41 rows=1
width=552)
Index Cond: (during @> '[2018-03-27,2018-03-31)'::daterange)
(2 rows)
Running that query for real I get:
...
(215044 rows)
Time: 1450.099 ms (00:01.450)
So if the index isn't being used you'll have to do some digging to find
out why.
--
Paul ~{:-)
pj(at)illuminatedcomputing(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Paul Jungwirth | 2018-03-27 18:36:12 | Re: Proposition for better performance |
Previous Message | Adrian Klaver | 2018-03-27 18:17:18 | Re: Postgresql 9.3 Server will not start after Ubuntu Upgrade |