Re: How to use index in WHERE int = float

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: How to use index in WHERE int = float
Дата
Msg-id dcc563d10811051321s117c9262tb17eaaa3c2eea0d5@mail.gmail.com
обсуждение исходный текст
Ответ на How to use index in WHERE int = float  ("Andrus" <kobruleht2@hot.ee>)
Ответы Re: How to use index in WHERE int = float  ("Andrus" <kobruleht2@hot.ee>)
Re: How to use index in WHERE int = float  (Sam Mason <sam@samason.me.uk>)
Список pgsql-general
On Wed, Nov 5, 2008 at 11:52 AM, Andrus <kobruleht2@hot.ee> wrote:
> I have table with index
>
> CREATE TABLE firma2.dok(
> ...
>  dokumnr serial NOT NULL,
> ...
>  CONSTRAINT dok_pkey PRIMARY KEY (dokumnr),
> ...
> );
>
> CREATE INDEX dok_dokumnr_idx
>  ON firma2.dok
>  USING btree
>  (dokumnr);
>
> I ran analyze command on it.
>
> explain analyze select * from firma2.dok where  dokumnr='1228137'::float8
>
> "Seq Scan on dok  (cost=0.00..187766.23 rows=6255 width=1145) (actual
> time=43168.460..43176.063 rows=1 loops=1)"
> "  Filter: ((dokumnr)::double precision = 1228137::double precision)"
> "Total runtime: 43176.375 ms"
>
> shows that index is not used and thus query takes very long time.
>
> How to force PostgreSql to speed up without changing query ?

Stop trying to compare exact and inexact types?

You do realize that a float is not an exact number.  What you and I
see as 1228137 might really be, internally, 1228136.9999999999999999 ?
 So it won't get an exact match.  What's wrong with trying to match to
an exact number instead?  I have a feeling you've given us a
simplified example of your problem.  It might help to see the real
problem.

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

Предыдущее
От: Sam Mason
Дата:
Сообщение: Re: How to use index in WHERE int = float
Следующее
От: Jason Long
Дата:
Сообщение: Re: Debugging infrequent pegged out CPU usage