Re: Finding nearest numeric value

Поиск
Список
Период
Сортировка
От Ron Mayer
Тема Re: Finding nearest numeric value
Дата
Msg-id 430388B0.1000709@cheapcomplexdevices.com
обсуждение исходный текст
Ответ на Re: Finding nearest numeric value  (Richard Huxton <dev@archonet.com>)
Ответы Re: Finding nearest numeric value  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-general
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))?

Or is the optimizer smart enough to find an index on myval
and stop after the first one (assuming the index returned
things sequentially.

If not, it seems this could do things in O(n) time:
   select min(abs(value - CONSTANT)) from tablename
followed by
   select * from tablename where abs(value - CONSTANT) = [result]
though I'm sure someone could roll that up into a single statement.

В списке pgsql-general по дате отправления:

Предыдущее
От: Ron Mayer
Дата:
Сообщение: Re: table clustering brings joy
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: postgres 8.x on debian