X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BB8C332A52D for ; Fri, 22 Oct 2004 13:59:22 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08194-05 for ; Fri, 22 Oct 2004 12:59:14 +0000 (GMT) Received: from lakermmtao11.cox.net (lakermmtao11.cox.net [68.230.240.28]) by svr1.postgresql.org (Postfix) with ESMTP id 2CAE232A484 for ; Fri, 22 Oct 2004 13:59:20 +0100 (BST) Received: from [192.168.0.9] (really [24.250.237.182]) by lakermmtao11.cox.net (InterMail vM.6.01.03.04 201-2131-111-106-20040729) with ESMTP id <20041022125650.ILSW16111.lakermmtao11.cox.net@[192.168.0.9]>; Fri, 22 Oct 2004 08:56:50 -0400 From: Robert Treat To: Anshaj Subject: Re: indexes are not working for Date: Fri, 22 Oct 2004 08:54:28 -0400 User-Agent: KMail/1.6.2 Cc: pgsql-admin@postgresql.org References: In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200410220854.28954.xzilla@users.sourceforge.net> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/303 X-Sequence-Number: 15296 Please do not post new topic as reply's to unrelated threads!! On Friday 22 October 2004 02:10, Anshaj wrote: > Dear group, > > I have a table foo > anshajdb=# \d foo > Table "public.foo" > Column | Type | Modifiers > ---------+-------------------+----------- > snumber | numeric(18,0) | > test | character varying | > Indexes: > "snum_idx" btree (snumber) > > when I try to do a query like > explain analyze select * from foo where snumber > 1000; > > Seq Scan on foo (cost=0.00..69.00 rows=320 width=391) (actual > time=0.011..0.721 rows=323 loops=1) > Filter: (snumber > 1000::numeric) > Total runtime: 0.979 ms > (3 rows) > It do a sequence scan on table. Why it is not using the snum_idx in this > query. Do I need to change some setting or indexes don't work on this > types of query. > You query is not selective enough for the database to use an index. ie. your retrieving 323 rows from at best 1323 rows in the table, so the database figures it can grab all of the records much faster by just doing a seq scan on the table. Try adding some more data to the table and/or selecting a specific value and you'll see your index get used. -- Robert Treat Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL