Re: Any advice tuning this query ? - Mailing list pgsql-performance

From Andreas Karlsson
Subject Re: Any advice tuning this query ?
Date
Msg-id d9eb436f-7d9b-60f6-7f08-3c63579f9781@proxel.se
Whole thread Raw
In response to Any advice tuning this query ?  (Henrik Ekenberg <henrik@ekenberg.pw>)
List 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


pgsql-performance by date:

Previous
From: "ldh@laurent-hasson.com"
Date:
Subject: Re: Inlining of functions (doing LIKE on an array)
Next
From: Tom Lane
Date:
Subject: Re: Inlining of functions (doing LIKE on an array)