Re: How to use index in WHERE int = float

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to use index in WHERE int = float
Date: 2008-11-05 21:42:12
Message-ID: 6C07D560D6F34095AF2DD2694552B76D@andrusnotebook
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> 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?

My query contains

'1228137'::float8

I do'nt see

1228136.9999999999999999

in this query.

Those strange casts are auto-generated by ODBC parameter passing software
which I must use so I must live with it.

Only way to fix this it to replace parameters manually by creating strings
which I'm trying to do for slow queries.

> I have a feeling you've given us a
> simplified example of your problem. It might help to see the real
> problem.

I has feeling that PostgreSql must determine that index is integer type and
convert float to integer itself to speed it up.

Another issue:

Wuery

SELECT dokumnr
FROM DOK
where dokumnr IN (123)
AND ( '0' or
dokumnr IN (SELECT dokumnr FROM bilkaib WHERE
alusdok='LG' AND masin LIKE 'a%') )

runs slowly.

If

'0' or

is removed form where clause it runs fast since it founds indexes.

It is real surpise that expression containing

'0' or

prevents PostgreSql to use indexes.

I have changed those queries to manually created better sql statements which
run fast.
however I expected that PsotgreSql can optimize those itself.

Andrus.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2008-11-05 21:48:57 Re: How to use index in WHERE int = float
Previous Message Jason Long 2008-11-05 21:40:19 Re: Debugging infrequent pegged out CPU usage