Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 511F19FB6FF for ; Thu, 29 Mar 2007 21:15:30 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 69447-03 for ; Thu, 29 Mar 2007 21:15:21 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from globalrelay.com (mail1.globalrelay.com [204.92.49.200]) by postgresql.org (Postfix) with ESMTP id 465E09FBBCC for ; Thu, 29 Mar 2007 21:15:26 -0300 (ADT) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES X-Real-To: fbsd@drivefaster.net, pgsql-performance@postgresql.org Received: from [63.226.156.118] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 134199614; Thu, 29 Mar 2007 17:15:24 -0700 From: "Dave Dutcher" To: "'Dan Harris'" , "'PostgreSQL Performance'" Subject: Re: Planner doing seqscan before indexed join Date: Thu, 29 Mar 2007 19:15:23 -0500 Message-ID: <019201c77260$82f91fa0$2e00a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6822 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 Thread-Index: AcdxqWmxekhlFV31QDmwP0bfS/UQUAAs7RGA In-Reply-To: <460B22E1.7070904@drivefaster.net> Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/426 X-Sequence-Number: 23831 > From: pgsql-performance-owner@postgresql.org=20 > [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of=20 > Dan Harris >=20 > After some digging, I've found that the planner is choosing=20 > to apply a necessary seq scan to the table. Unfortunately, > it's scanning the whole table, when it seems that it could=20 > have joined it to a smaller table first and reduce the > amount of rows it would have to scan dramatically ( 70=20 > million to about 5,000 ). >=20 Joining will reduce the amount of rows to scan for the filter, but performing the join is non-trivial. If postgres is going to join two = tables together without applying any filter first then it will have to do a = seqscan of one of the tables, and if it chooses the table with 5000 rows, then = it will have to do 5000 index scans on a table with 70 million records. I don't know which way would be faster.=20 I wonder if you could find a way to use an index to do the text filter. Maybe tsearch2? I haven't used anything like that myself, maybe someone else has more input.