Re: Hash Anti Join performance degradation

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "panam" <panam(at)gmx(dot)net>,<pgsql-performance(at)postgresql(dot)org>
Subject: Re: Hash Anti Join performance degradation
Date: 2011-05-26 17:08:18
Message-ID: 4DDE42B2020000250003DD5E@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

panam <panam(at)gmx(dot)net> wrote:

> I cannot use it because of the way that query is generated
> (by hibernate).
>
> The (simplyfied) base query is just
>
> SELECT b.id from box
>
> the subquery
>
> (SELECT m1.id FROM message m1
> LEFT JOIN message m2
> ON (m1.box_id = m2.box_id AND m1.id < m2.id )
> WHERE m2.id IS NULL AND m1.box_id = b.id) as lastMessageId
>
> is due to a hibernate formula (containing more or less plain SQL)
> to determine the last message id for that box. It ought to return
> just one row, not multiple. So I am constrained to the subquery in
> all optimization attemps (I cannot combine them as you did), at
> least I do not see how. If you have an idea for a more performant
> subquery though, let me know, as this can easily be replaced.

Maybe:

(SELECT max(m1.id) FROM message m1 WHERE m1.box_id = b.id)

-Kevin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2011-05-26 17:08:46 Re: [ADMIN] pg_class reltuples/relpages not updated by autovacuum/vacuum
Previous Message Stephen Frost 2011-05-26 16:53:38 Re: Pre-alloc ListCell's optimization

Browse pgsql-performance by date

  From Date Subject
Next Message Kevin Grittner 2011-05-26 17:45:32 Re: The shared buffers challenge
Previous Message Tom Lane 2011-05-26 17:00:43 Re: LIMIT and UNION ALL