| From: | Mark Kirkwood <mark(dot)kirkwood(at)catalyst(dot)net(dot)nz> |
|---|---|
| To: | Johann Spies <johann(dot)spies(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | pgsql-performance(at)postgresql(dot)org |
| Subject: | Re: query not using index |
| Date: | 2013-12-28 02:31:11 |
| Message-ID: | 52BE37EF.7090109@catalyst.net.nz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-performance |
On 23/12/13 21:58, Johann Spies wrote:
>
>
>
> On 19 December 2013 16:48, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us
> <mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us>> wrote:
>
> Johann Spies <johann(dot)spies(at)gmail(dot)com
> <mailto: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.
>
>
> Thanks Tom. Raising work_mem from 384MB to 512MB made a significant
> difference.
>
> You said "hash or merge join id going to be a lot better than
> nestloop". Is that purely in the hands of the query planner or what can
> I do to get the planner to use that options apart from raising the work_mem?
>
>
You can disable the hash and merge join options by doing:
SET enable_hashjoin=off;
SET enable_mergejoin=off;
before running the query again. Timing it (or EXPLAIN ANALYZE) should
demonstrate if that planner made the right call by choosing hash or
merge in the first place.
regards
Mark
| From | Date | Subject | |
|---|---|---|---|
| Next Message | ankush upadhyay | 2013-12-28 05:19:01 | Are there some additional postgres tuning to improve performance in multi tenant system |
| Previous Message | Andreas Karlsson | 2013-12-27 16:27:14 | Re: Does fsync on/off for wal AND Checkpoint? |