Re: query not using index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Johann Spies <johann(dot)spies(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: query not using index
Date: 2013-12-19 14:48:55
Message-ID: 8767.1387464535@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Johann Spies <johann(dot)spies(at)gmail(dot)com> writes:
> I would appreciate some help optimising the following query:

It's a mistake to imagine that indexes are going to help much with
a join of this size. Hash or merge join is going to be a lot better
than nestloop. What you need to do is make sure those will perform
as well as possible, and to that end, it'd likely help to raise
work_mem. I'm not sure if you can sanely put it high enough to
make the query operate totally in memory --- it looks like you'd
need work_mem of 500MB or more to prevent any of the sorts or
hashes from spilling to disk, and keep in mind that this query
is going to use several times work_mem because there are multiple
sorts/hashes going on. But if you can transiently dedicate a lot
of RAM to this query, that should help some. I'd suggest increasing
work_mem via a SET command in the particular session running this
query --- you don't want such a high value to be the global default.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Marc Cousin 2013-12-19 15:33:24 query plan not optimal
Previous Message Johann Spies 2013-12-19 13:06:21 query not using index