Received: from gromit.dotclick.com (ipn9-f8366.net-resource.net [216.204.83.66]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4TElhE26566 for ; Tue, 29 May 2001 10:47:43 -0400 (EDT) (envelope-from markw@mohawksoft.com) Received: from mohawksoft.com (IDENT:markw@localhost.localdomain [127.0.0.1]) by gromit.dotclick.com (8.9.3/8.9.3) with ESMTP id KAA13761; Tue, 29 May 2001 10:45:55 -0400 Message-ID: <3B13B622.41D25E5@mohawksoft.com> Date: Tue, 29 May 2001 10:45:54 -0400 From: mlw X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.4.2 i686) X-Accept-Language: en MIME-Version: 1.0 To: "Marc G. Fournier" CC: pgsql-hackers@postgresql.org Subject: Re: *really* simple select doesn't use indices ... References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200105/1166 X-Sequence-Number: 9456 This is one my top two problem with Postgres, the seemingly braindead index selection mechanism. First, of course try "VACUUM ANALYZE' Then if the fails, try set ENABLE_SEQSCAN = off; Then try your query. "Marc G. Fournier" wrote: > First, this is still a v7.1 system ... its totally possible that this is > long fixed, and I'm way overdue to get it to v7.1.2, which I'll gladly > accept as a response ... > > That said ... seems like a very painful way to arrive at 1 row ... :) > > table structure: > > globalmatch=# \d locations > Table "locations" > Attribute | Type | Modifier > -----------+---------+-------------------------------------------------------- > gid | integer | not null default nextval('locationstmp_gid_seq'::text) > city | text | > state | text | > country | text | > zip | text | > location | point | > Indices: locations_zip, > locationstmp_gid_key > > globalmatch=# \d locations_zip > Index "locations_zip" > Attribute | Type > -----------+------ > zip | text > btree > > globalmatch=# EXPLAIN SELECT count(location) from locations WHERE zip = '80012'; > NOTICE: QUERY PLAN: > > Aggregate (cost=2950.18..2950.18 rows=1 width=16) > -> Seq Scan on locations (cost=0.00..2939.64 rows=4217 width=16) > > EXPLAIN > > globalmatch=# SELECT count(location) from locations WHERE zip = '80012'; > count > ------- > 1 > (1 row) > > globalmatch=# SELECT count(location) from locations; > count > -------- > 123571 > (1 row) > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)