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 86BA0D1B8C8 for ; Tue, 26 Aug 2003 16:40:33 -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 15659-03 for ; Tue, 26 Aug 2003 16:40:03 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id B4807D1B8B0 for ; Tue, 26 Aug 2003 16:40:01 -0300 (ADT) Received: (qmail 19205 invoked by uid 500); 26 Aug 2003 19:45:58 -0000 Date: Tue, 26 Aug 2003 14:45:58 -0500 From: Bruno Wolff III To: Rhaoni Chiu Pereira Cc: Lista PostgreSQL Subject: Re: How to force an Index ? Message-ID: <20030826194558.GA19181@wolff.to> Mail-Followup-To: Rhaoni Chiu Pereira , Lista PostgreSQL References: <1061925116.3f4bb0fc641b2@www.sistemica.info> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1061925116.3f4bb0fc641b2@www.sistemica.info> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/306 X-Sequence-Number: 10027 On Tue, Aug 26, 2003 at 16:11:56 -0300, Rhaoni Chiu Pereira wrote: > Hi List, > > I'm looking for a way to force an Index to be used in a SQL query. In a > Oracle SQL query it would be like: > > Select /*+ my_index*/ * from my_table where my_name="rhaoni"; > > So it would use the index my_index to execute the query. How can I make this > in a PostgreSQL SQL query. There isn't a way to force specific indexes to be used. You can raise the cost of sequential scans so that index scans will almost always be used if they are possible. Use: set enable_seqscan = false; In general it is best to use this only to find out why an index scan isn't being used and then potentially change some cost functions so that the proper plan is chosen.