Re: Performance issue with NestedLoop query - Mailing list pgsql-performance

From Matheus de Oliveira
Subject Re: Performance issue with NestedLoop query
Date
Msg-id CAJghg4+En3Uj9JVARL6Zsfp1hnVmxBaXXa11QSaXEh830dCYwg@mail.gmail.com
Whole thread Raw
In response to Performance issue with NestedLoop query  (Ram N <yramiyer@gmail.com>)
Responses Re: Performance issue with NestedLoop query  (Matheus de Oliveira <matioli.matheus@gmail.com>)
List pgsql-performance

On Thu, Jul 30, 2015 at 4:51 AM, Ram N <yramiyer@gmail.com> wrote:
select sum(a), count(id), a.ts, st from table1 a, table2 b where a.ts > b.start_date and a.ts < b.end_date and a.ts > '2015-01-01 20:50:44.000000 +00:00:00' and a.ts < '2015-07-01 19:50:44.000000 +00:00:00' group by a.ts, st order by a.ts

You could try to use a range type:

    CREATE INDEX ON table2 USING gin (tstzrange(start_date, end_date, '()'));

Then:

    select sum(a), count(id), a.ts, st
    from table1 a, table2 b
    where tstzrange(b.start_date, b.end_date, '()') @> a.ts
        and a.ts < '2015-07-01 19:50:44.000000 +00:00:00'
    group by a.ts, st
    order by a.ts


Regards,
--
Matheus de Oliveira


pgsql-performance by date:

Previous
From: Ram N
Date:
Subject: Re: Performance issue with NestedLoop query
Next
From: Matheus de Oliveira
Date:
Subject: Re: Performance issue with NestedLoop query