X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7D3B0D1B4EB for ; Wed, 17 Sep 2003 20:45:24 +0000 (GMT) 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 98440-01 for ; Wed, 17 Sep 2003 17:44:53 -0300 (ADT) Received: from host2.hostseguro.com (unknown [200.198.188.133]) by svr1.postgresql.org (Postfix) with ESMTP id 55975D1B4E1 for ; Wed, 17 Sep 2003 17:44:51 -0300 (ADT) Received: from cpanel by host2.hostseguro.com with local (Exim 4.20) id 19zjAI-0003jl-PB for pgsql-admin@postgresql.org; Wed, 17 Sep 2003 17:44:42 -0300 Received: from 200.203.32.180 ([200.203.32.180]) by sistemica.info (IMP) with HTTP for ; Wed, 17 Sep 2003 17:44:42 -0300 Message-ID: <1063831482.3f68c7bab4b1a@sistemica.info> Date: Wed, 17 Sep 2003 17:44:42 -0300 From: Rhaoni Chiu Pereira To: PostgreSQL ADMIN Subject: How can I make PosgreSQL use an Index ? MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.1 X-Originating-IP: 200.203.32.180 X-MailScanner-Information: Verificado pelo McAfee VirusScan / Scanned by McAfee VirusScan X-MailScanner: Nao infectado / Found to be clean X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host2.hostseguro.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [32001 32001] / [47 12] X-AntiAbuse: Sender Address Domain - sistemica.info X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/297 X-Sequence-Number: 10385 Hi list, I have a table like this: CREATE TABLE "gsames00" ( "ano_mes" varchar(6) NOT NULL, "descricao" varchar(30), PRIMARY KEY ("ano_mes") ); and an index like this: CREATE INDEX GSAMES01 ON GSAMES00 (ANO_MES); When I run a explain analyze with this where clause: ... gsames00.ano_mes = to_char(ftnfco00.data_emissao,'YYYYMM') AND ... ftnfco00.data_emissao is a timestamp. When I run the explain analyze it says: ... -> Seq Scan on gsames00 (cost=100000000.00..100000006.72 rows=372 width=10) (actual time=0.01..0.96 rows=372 loops=19923) ... So it is not using the index, and it makes the query too slow to return the result. If a run the same query without this clause it gets about 1 minute faster. You you're wondering : If you can run this query without this clause, Why don't you take it out ? I must use it because this query is created by a BI software and to change it, I'll have to make a lot of changes in the BI software source. In the Oracle DB it works fine 'cuz Oracle use the index and do it instantly. Any suggestion on how to force PostgreSQL tu use this index ??? Atenciosamente, Rhaoni Chiu Pereira Sistêmica Computadores Visite-nos na Web: http://sistemica.info Fone/Fax : +55 51 3328 1122