From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mikkel Lauritsen <renard@tala.dk>
Cc: pgsql-performance@postgresql.org
Subject: Re: Different execution plans for semantically equivalent queries
Date: Sun, 06 Feb 2011 16:29:01 -0500
Message-ID: <15642.1297027741@sss.pgh.pa.us> (raw)
In-Reply-To: <bbe20a8f4ef774a3f221f637b1d1cac1@localhost>
References: <bbe20a8f4ef774a3f221f637b1d1cac1@localhost>
Mikkel Lauritsen <renard@tala.dk> writes:
> I would like to do a query which retrieves the newest record for each
> type, and the persistence framework that I'm using does something
> which is structurally like
> SELECT * FROM table t1 WHERE 0 = (SELECT COUNT(*) FROM table t2 WHERE
> t2.type = t1.type AND t2.timestamp > t1.timestamp)
I suspect that *any* database is going to have trouble optimizing that.
You'd be well advised to lobby the persistence framework's authors to
produce less brain-dead SQL. The NOT EXISTS formulation seems to
express what's wanted much less indirectly.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, renard@tala.dk
Subject: Re: Different execution plans for semantically equivalent queries
In-Reply-To: <15642.1297027741@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox