Re: Table access method not behaving like Oracle (index vs sequential scan). Examples and stats provided. - Mailing list pgsql-general

From Greg Stark
Subject Re: Table access method not behaving like Oracle (index vs sequential scan). Examples and stats provided.
Date
Msg-id 87isc6rem9.fsf@stark.xeocode.com
Whole thread Raw
In response to Table access method not behaving like Oracle (index vs sequential scan). Examples and stats provided.  ("Kevin Macdonald" <nospam@please.thankyou>)
List pgsql-general
"Kevin Macdonald" <nospam@please.thankyou> writes:

> QUERY 2: select sobjid from p1_nrn_road where v = 1
>
> The plan is "Seq Scan on p1_nrn_road (cost=0.00..22158.54 rows=2 width=8)"

Incidentally, you should send the whole plan. In general you should send all
the information you have, not just the parts you think are relevant. The next
line would have clearly shown the problem to someone who knew what to look
for.

try
 where v = '1'
or
 where v = 1::bigint

The problem is that in 7.4 and previous indexes can't be used for cross-type
comparisons and integer constants are assumed to be integer not bigint type.
If you leave it in quotes then postgres doesn't pick a type until it looks at
what you're comparing it with. Or if you cast it then you force it to be a
bigint=bigint comparison.

7.5 will avoid this problem.

--
greg

pgsql-general by date:

Previous
From: Harald Fuchs
Date:
Subject: Re: Sql injection attacks
Next
From: "Jason Tesser"
Date:
Subject: Backup questions