Re: postgres 7.1.3: why does the query plan ignore indexes? - Mailing list pgsql-sql

From Tom Lane
Subject Re: postgres 7.1.3: why does the query plan ignore indexes?
Date
Msg-id 27563.1061299589@sss.pgh.pa.us
Whole thread Raw
In response to postgres 7.1.3: why does the query plan ignore indexes?  (Marco Vezzoli <marco.vezzoli@st.com>)
Responses Re: postgres 7.1.3: why does the query plan ignore indexes?  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-sql
Marco Vezzoli <marco.vezzoli@st.com> writes:
> ewsweb_test=> \d measures_product
> Index "measures_product"
>  Attribute  |   Type   
> ------------+----------
>  product_id | smallint               ^^^^^^^^

> ewsweb_test=> explain select zero_yield, gross from measures where
> product_id=29 and date between '2003-03-12' and '2003-08-14'; ^^^^^^^^^^^^^

"29" is taken as an integer (int4).  To get an indexscan on an int2
column, you need to explicitly cast it to int2:product_id = 29::smallint
or you can put it in quotes and let the parser figure out the right
type:product_id = '29'

Yes, we'd like to make this better, but there are surprisingly many
pitfalls in tinkering with the assignment of datatypes to constants...
        regards, tom lane

PS: you could also consider whether it's really saving you any space to
store product_id as a smallint instead of int.  Because of alignment
considerations, it very possibly isn't.


pgsql-sql by date:

Previous
From: Rado Petrik
Date:
Subject: Query problem
Next
From: Marco Vezzoli
Date:
Subject: Re: postgres 7.1.3: why does the query plan ignore indexes?