X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9A58A9FA3A3 for ; Wed, 10 May 2006 22:53:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 68458-06 for ; Wed, 10 May 2006 22:53:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id B06E29F931E for ; Wed, 10 May 2006 22:53:51 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k4B1rn4K026130; Wed, 10 May 2006 21:53:49 -0400 (EDT) To: ogjunk-pgjedan@yahoo.com cc: pgsql-sql@postgresql.org Subject: Re: Help with a seq scan on multi-million row table In-reply-to: <20060511013410.83818.qmail@web50307.mail.yahoo.com> References: <20060511013410.83818.qmail@web50307.mail.yahoo.com> Comments: In-reply-to message dated "Wed, 10 May 2006 18:34:10 -0700" Date: Wed, 10 May 2006 21:53:49 -0400 Message-ID: <26129.1147312429@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/94 X-Sequence-Number: 25125 writes: > Aha! set hashjoin=off did the trick. > -> Index Scan using ix_user_url_tag_user_url_id on user_url_tag userurltag0_ (cost=0.00..157.34 rows=103 width=14) (actual time=1.223..1.281 rows=5 loops=1666) > Index Cond: (userurltag0_.user_url_id = "outer".id) This seems to be the problem right here: the estimate of matching rows is off by a factor of 20, and that inflates the overall cost estimate for this plan about the same, causing the planner to think the other way is cheaper. What does the pg_stats row for user_url_tag.user_url_id contain? Have you analyzed that table recently? regards, tom lane