Re: expected O^2 looks line K^O, index problem not involved: [was] looping simpler query just faster - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: expected O^2 looks line K^O, index problem not involved: [was] looping simpler query just faster
Date
Msg-id 20080710135254.GB18528@svana.org
Whole thread Raw
In response to expected O^2 looks line K^O, index problem not involved: [was] looping simpler query just faster  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
Responses Re: expected O^2 looks line K^O, index problem not involved: [was] looping simpler query just faster
List pgsql-general
On Thu, Jul 10, 2008 at 02:19:30PM +0200, Ivan Sergio Borgonovo wrote:
> On Thu, 10 Jul 2008 11:50:01 +0200
> Martijn van Oosterhout <kleptog@svana.org> wrote:

Hmm, I just studied your query to determine what you're trying to do.
As I understand it:

For each item
  Determine the brand
  Get the top three items for this brand
  If this item is one of them, display it

This is pretty inefficient but I can't see an efficient way to do it
either. I suppose one thing to try would be a multicolumn index on
(brand,datainserimento) to avoid the sort step. Also, the table b1 in
the original query is redundant.

It's the fact that you want the top three items that makes it
difficult, not sure how to deal with that.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

Attachment

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: Starter
Next
From: aravind chandu
Date:
Subject: SPACE FOR POSTGRESQL DATABASE