Re: How to use index in WHERE int = float - Mailing list pgsql-general

From Andrus
Subject Re: How to use index in WHERE int = float
Date
Msg-id 6C07D560D6F34095AF2DD2694552B76D@andrusnotebook
Whole thread Raw
In response to Re: How to use index in WHERE int = float  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Responses Re: How to use index in WHERE int = float
Re: How to use index in WHERE int = float
List 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.


pgsql-general by date:

Previous
From: "Andrus"
Date:
Subject: Speeding up startswith query
Next
From: "Scott Marlowe"
Date:
Subject: Re: How to use index in WHERE int = float