From: Paul Jungwirth <pj@illuminatedcomputing.com>
To: hmidi slim <hmidi.slim2@gmail.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Proposition for better performance
Date: Tue, 27 Mar 2018 11:25:30 -0700
Message-ID: <d617ebc2-3e63-ba2a-660f-318dfb08b2a6@illuminatedcomputing.com> (raw)
In-Reply-To: <CAMsqVxu2jFANWNDnFRUnM76NS70_u+VrwhmPOiK9U97FK9sm8w@mail.gmail.com>
References: <CAMsqVxs8xwxH+f40nUNj+5L9Mo9+9z+xsjFxS0k+ajgG=qOz4Q@mail.gmail.com>
<2e436152-eda0-d67d-4b20-90da0db4a049@illuminatedcomputing.com>
<CAMsqVxtRD5dCVL3o_eCWNdwo4igQCzjMgXTdD+sDVD8AHHkgDg@mail.gmail.com>
<834d8a70-386d-7101-f846-ae572140af92@illuminatedcomputing.com>
<CAMsqVxu2jFANWNDnFRUnM76NS70_u+VrwhmPOiK9U97FK9sm8w@mail.gmail.com>
(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@illuminatedcomputing.com
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: pj@illuminatedcomputing.com, hmidi.slim2@gmail.com
Subject: Re: Proposition for better performance
In-Reply-To: <d617ebc2-3e63-ba2a-660f-318dfb08b2a6@illuminatedcomputing.com>
References: <CAMsqVxs8xwxH+f40nUNj+5L9Mo9+9z+xsjFxS0k+ajgG=qOz4Q@mail.gmail.com> <2e436152-eda0-d67d-4b20-90da0db4a049@illuminatedcomputing.com> <CAMsqVxtRD5dCVL3o_eCWNdwo4igQCzjMgXTdD+sDVD8AHHkgDg@mail.gmail.com> <834d8a70-386d-7101-f846-ae572140af92@illuminatedcomputing.com> <CAMsqVxu2jFANWNDnFRUnM76NS70_u+VrwhmPOiK9U97FK9sm8w@mail.gmail.com> <d617ebc2-3e63-ba2a-660f-318dfb08b2a6@illuminatedcomputing.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