Re: Query tuning: partitioning, DISTINCT ON, and indexing

From: bricklen <bricklen(at)gmail(dot)com>
To: Maciek Sakrejda <m(dot)sakrejda(at)gmail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Query tuning: partitioning, DISTINCT ON, and indexing
Date: 2013-06-21 04:13:11
Message-ID: CAGrpgQ-gOVq3v=TaskKKwY5f=A5eoNvKCCKgxJugnO=paKJJPg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, Jun 20, 2013 at 6:24 PM, Maciek Sakrejda <m(dot)sakrejda(at)gmail(dot)com>wrote:

> SELECT
> DISTINCT ON (type) ts, type, details
> FROM
> observations
> WHERE
> subject = '...'
> ORDER BY
> type, ts DESC;
>

First thing: What is your "work_mem" set to, and how much RAM is in the
machine? If you look at the plan, you'll immediately notice the "external
merge Disk" line where it spills to disk on the sort. Try setting your
work_mem to 120MB or so (depending on how much RAM you have, # concurrent
sessions, complexity of queries etc)

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Maciek Sakrejda 2013-06-21 05:14:40 Re: Query tuning: partitioning, DISTINCT ON, and indexing
Previous Message Maciek Sakrejda 2013-06-21 01:24:46 Query tuning: partitioning, DISTINCT ON, and indexing