Re: [PERFORM] slow sort

2013-09-12 Thread Maximilian Tyrtania
Am 11.09.2013 um 17:31 schrieb Andrew Dunstan : > I recently had to diagnose and remedy a case such as this. > > The short answer is to rewrite your query so you don't have to group by so > many things. Collect your aggregates in a common table expression query (or > possibly more than one, dep

Re: [PERFORM] slow sort

2013-09-11 Thread Andrew Dunstan
On 09/11/2013 06:36 AM, Maximilian Tyrtania wrote: Hi there, here is another one from the "why is my query so slow?" category. First post, so please bare with me. The query (which takes around 6 seconds) is this: SET work_mem TO '256MB';//else sort spills to disk SELECT et.subject,

Re: [PERFORM] slow sort

2013-09-11 Thread Maximilian Tyrtania
Thanks, unfortunately it (creating that index) didn't. But I rewrote my query using inline subqueries, which already helped a lot. Thanks again, Maximilian Tyrtania http://www.contactking.de Am 11.09.2013 um 15:58 schrieb bricklen : > > On Wed, Sep 11, 2013 at 3:36 AM, Maximilian Tyrtania >

Re: [PERFORM] slow sort

2013-09-11 Thread bricklen
On Wed, Sep 11, 2013 at 3:36 AM, Maximilian Tyrtania wrote: > > JOIN emailsendings es ON et. ID = es.emailtemplate_id > ORDER BY > es.sentonat desc > Perhaps on an index on (es.emailtemplate_id, es.sentonat desc) would help?