From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marco Vezzoli <marco.vezzoli@st.com>
Cc: sql <pgsql-sql@postgresql.org>
Subject: Re: postgres 7.1.3: why does the query plan ignore indexes?
Date: Tue, 19 Aug 2003 09:26:29 -0400
Message-ID: <27563.1061299589@sss.pgh.pa.us> (raw)
In-Reply-To: <3F41E343.AE3B5E@st.com>
References: <3F41E343.AE3B5E@st.com>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, marco.vezzoli@st.com
Subject: Re: postgres 7.1.3: why does the query plan ignore indexes?
In-Reply-To: <27563.1061299589@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox