Re: Any advice tuning this query ?

From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: henrik(at)ekenberg(dot)pw, pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Any advice tuning this query ?
Date: 2016-11-11 16:22:37
Message-ID: d9eb436f-7d9b-60f6-7f08-3c63579f9781@proxel.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

I have a couple of suggestions which should lead to some minor
improvements, but in general I am surprised by the huge size of the
result set. Is your goal really to get a 43 million row result? When a
query returns that many rows usually all possible query plans are more
or less bad.

1) You can remove "3" from the group by clause to avoid having to sort
that data when we already sort by d.date.

2) If (books, date) is the primary key of dates_per_books we can also
safely remove "4" from the group by clause further reducing the length
of the keys that we need to sort.

3) For a minor speed up change "coalesce(sum(case when i.invno is not
null then 1 else 0 end),0)" to "count(i.invno)".

Andreas

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2016-11-11 16:46:24 Re: Inlining of functions (doing LIKE on an array)
Previous Message ldh@laurent-hasson.com 2016-11-11 16:14:08 Re: Inlining of functions (doing LIKE on an array)