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

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: expected O^2 looks line K^O, index problem not involved: [was] looping simpler query just faster
Date: 2008-07-10 13:52:54
Message-ID: 20080710135254.GB18528@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message aravind chandu 2008-07-10 14:18:39 SPACE FOR POSTGRESQL DATABASE
Previous Message Raymond O'Donnell 2008-07-10 12:41:04 Re: Starter