X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id F267DD1B8D1 for ; Tue, 19 Aug 2003 10:26:38 -0300 (ADT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 48059-10 for ; Tue, 19 Aug 2003 10:26:31 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 03C92D1B89D for ; Tue, 19 Aug 2003 10:26:28 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h7JDQT5H027564; Tue, 19 Aug 2003 09:26:31 -0400 (EDT) To: Marco Vezzoli Cc: sql Subject: Re: postgres 7.1.3: why does the query plan ignore indexes? In-reply-to: <3F41E343.AE3B5E@st.com> References: <3F41E343.AE3B5E@st.com> Comments: In-reply-to Marco Vezzoli message dated "Tue, 19 Aug 2003 10:43:47 +0200" Date: Tue, 19 Aug 2003 09:26:29 -0400 Message-ID: <27563.1061299589@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/218 X-Sequence-Number: 14834 Marco Vezzoli 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.