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 770C7D1B8DD for ; Tue, 19 Aug 2003 10:45:12 -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 58540-01 for ; Tue, 19 Aug 2003 10:45:04 -0300 (ADT) Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by svr1.postgresql.org (Postfix) with ESMTP id B427CD1B8D5 for ; Tue, 19 Aug 2003 10:45:00 -0300 (ADT) Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with SMTP id 11A12DC79; Tue, 19 Aug 2003 13:45:04 +0000 (GMT) Received: by zeta.dmz-eu.st.com (STMicroelectronics, from userid 0) id E55966150; Tue, 19 Aug 2003 13:45:03 +0000 (GMT) Received: from agx003.agr.st.com (localhost [127.0.0.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1FFBD1845; Tue, 19 Aug 2003 13:45:03 +0000 (GMT) Received: from st.com (web.rdd.agr.st.com [164.130.32.138]) by agx003.agr.st.com (8.9.3 (PHNE_24419+JAGae58098)/8.9.3) with ESMTP id PAA29258; Tue, 19 Aug 2003 15:45:01 +0200 (METDST) Message-ID: <3F4228ED.2962F13F@st.com> Date: Tue, 19 Aug 2003 15:41:01 +0200 From: Marco Vezzoli X-Mailer: Mozilla 4.76 [en] (X11; U; SunOS 5.8 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: tgl@sss.pgh.pa.us Cc: pgsql-sql@postgresql.org Subject: Re: postgres 7.1.3: why does the query plan ignore indexes? References: <3F41E343.AE3B5E@st.com> <27563.1061299589@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/219 X-Sequence-Number: 14835 tgl@sss.pgh.pa.us wrote: > > 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. thank you, now it works better; however it seems that the date index is ignored. ewsweb_test=> explain select zero_yield, gross from measures where product_id=29::smallint and date between '2003-03-12' and '2003-08-14'; NOTICE: QUERY PLAN: Index Scan using measures_product on measures (cost=0.00..3792.27 rows=254 width=12) EXPLAIN -- Marco Vezzoli tel. +39 039 603 6852 STMicroelectronics fax. +39 039 603 5055