Re: Limit + group + join - Mailing list pgsql-performance

From Tobias Brox
Subject Re: Limit + group + join
Date
Msg-id 20050826020635.GM10328@tobias.lan
Whole thread Raw
In response to Re: Limit + group + join  ("Jeffrey W. Baker" <jwbaker@acm.org>)
List pgsql-performance
[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.

pgsql-performance by date:

Previous
From: "Jeffrey W. Baker"
Date:
Subject: Re: Limit + group + join
Next
From: "Jeffrey W. Baker"
Date:
Subject: Re: Limit + group + join