Re: Please help with a slow query: there are millions of records, what can we do?

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "'Pat Maddox *EXTERN*'" <pat(at)adorable(dot)io>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Please help with a slow query: there are millions of records, what can we do?
Date: 2017-03-08 10:05:07
Message-ID: A737B7A37273E048B164557ADEF4A58B53A069B0@ntex2010i.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Pat Maddox wrote:
> I’ve been asked to help with a project dealing with slow queries. I’m brand new to the project, so I
> have very little context. I’ve gathered as much information as I can.
>
> I’ve put the schema, query, and explain info in gists to maintain their formatting.
>
> We are stumped with this slow query right now. I could really use some help looking for ways to speed
> it up.

I don't know if the plan can be improved; it has to retrieve and sort 347014 rows,
most of which are read from diak, so it will take some time.

One thing I notice is that some statistics seem to be bad (the estimate for
the index scan on "permissions" is off the mark), so maybe you can ANALYZE
both tables (perhaps with higher "default_statistics_target") and see if that
changes anything.

Is there any chance you could give the machine lots of RAM?
That would speed up the bitmap heap scan (but not the sort).

Yours,
Laurenz Albe

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Jeff Janes 2017-03-08 18:00:47 Re: Please help with a slow query: there are millions of records, what can we do?
Previous Message Pat Maddox 2017-03-08 02:26:36 Please help with a slow query: there are millions of records, what can we do?