Re: Stupid database use the index! - Mailing list pgsql-general

From Mike Mascari
Subject Re: Stupid database use the index!
Date
Msg-id 200008241928.PAA16180@corvette.mascari.com
Whole thread Raw
In response to Stupid database use the index!  (Greg Maxwell <gmaxwell@martin.fl.us>)
Responses Re: Stupid database use the index!
List pgsql-general
> Why is this?
>
> web=# explain select account_nbr from apprsl_accounts where account_nbr =
> 3315;
> NOTICE:  QUERY PLAN:
>
> Seq Scan on apprsl_accounts  (cost=0.00..10317.24 rows=1 width=8)
>
> EXPLAIN
> web=# explain select account_nbr from apprsl_accounts where account_nbr =
> '3315';
> NOTICE:  QUERY PLAN:
>
> Index Scan using apprsl_accounts_account_nbr on apprsl_accounts
> (cost=0.00..4.80 rows=1 width=8)
>
> EXPLAIN

I suspect there is a type conversion issue here. I believe 3315 will
get converted implicitly to an int4 (in the parser). If the type of the
field isn't an int4, then the database has to use a sequential scan
because the indexes are built using non-int4 comparitive functions.
Meanwhile, the quoted version gets automatically type-cast
appropriately after parsing and can then use the index.

Hope that helps,

Mike Mascari


pgsql-general by date:

Previous
From: Philip Murray
Date:
Subject: enum datatype?
Next
From: richard excite
Date:
Subject: 2-phase commit