Re: Finding nearest numeric value - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: Finding nearest numeric value
Date
Msg-id 20050817202902.GB15346@wolff.to
Whole thread Raw
In response to Re: Finding nearest numeric value  (Ron Mayer <rm_pg@cheapcomplexdevices.com>)
List pgsql-general
On Wed, Aug 17, 2005 at 11:57:52 -0700,
  Ron Mayer <rm_pg@cheapcomplexdevices.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).

pgsql-general by date:

Previous
From: Manfred Koizar
Date:
Subject: Re: speeding up a query on a large table
Next
From: Tom Lane
Date:
Subject: Re: How to "ping" the database