From: Tobias Brox <tobias@nordicbet.com>
To: Jeffrey W. Baker <jwbaker@acm.org>
Cc: Tobias Brox <tobias@nordicbet.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Limit + group + join
Date: Fri, 26 Aug 2005 04:06:35 +0200
Message-ID: <20050826020635.GM10328@tobias.lan> (raw)
In-Reply-To: <1125021419.16451.0.camel@noodles>
References: <20050826002709.GK10328@tobias.lan>
<1125021419.16451.0.camel@noodles>
[Jeffrey W. Baker - Thu at 06:56:59PM -0700]
> > explain select c.id from c join b on c_id=c.id group by c.id order by c.id
> > desc limit 5;
>
> Where's b in this join clause?
"join b on c_id=c.id"
It just a funny way of writing:
select c.id from c,b where c_id=c.id group by c.id order by c.id desc limit 5;
> It looks like a cartesian product to me.
No. The query will return exactly the same as the simplest query:
select c.id from c order by c.id desc limit 5;
As said, this is a gross oversimplification of the production envorinment.
In the production environment, I really need to use both join, group and
limit. I tested a bit with subqueries, it was not a good solution
(selecting really a lot of rows and aggregates from many of the tables).
The next idea is to hack it up by manually finding out where the "limit"
will cut, and place a restriction in the where-part of the query.
--
Notice of Confidentiality: This information may be confidential, and
blah-blah-blah - so please keep your eyes closed. Please delete and destroy
this email. Failure to comply will cause my lawyer to yawn.
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: tobias@nordicbet.com, jwbaker@acm.org
Subject: Re: Limit + group + join
In-Reply-To: <20050826020635.GM10328@tobias.lan>
* 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