Re: Finding nearest numeric value

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>
Cc: Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Finding nearest numeric value
Date: 2005-08-17 20:29:02
Message-ID: 20050817202902.GB15346@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Aug 17, 2005 at 11:57:52 -0700,
Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com> wrote:
> Richard Huxton wrote:
> >
> >While the other answers all do their job, and in one go too, I'd be
> >surprised if you found anything faster than:
> >
> >SELECT myval FROM mytable WHERE myval > 1234 ORDER BY myval LIMIT 1
>
> Really? Aren't most things with ORDER BY O(n*log(n))?

No. Index lookups are O(log(n)). And you need to do only a constant number
of index lookups (2 or 4 depending on whether the values are unique).

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mario Guenterberg 2005-08-17 20:29:38 Re: Adding contrib modules
Previous Message Manfred Koizar 2005-08-17 20:28:49 Re: speeding up a query on a large table