X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8772FDA6B0 for ; Mon, 17 Oct 2005 05:45:25 -0300 (ADT) 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 95750-04 for ; Mon, 17 Oct 2005 08:45:22 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id A7073D77A8 for ; Mon, 17 Oct 2005 05:45:23 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 25120407D81; Mon, 17 Oct 2005 09:45:20 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id B7F0C15ED9; Mon, 17 Oct 2005 09:45:05 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 13151-09; Mon, 17 Oct 2005 09:45:01 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 1928D15ED5; Mon, 17 Oct 2005 09:45:01 +0100 (BST) Message-ID: <4353648C.8040507@archonet.com> Date: Mon, 17 Oct 2005 09:45:00 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051010) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Martin Nickel Cc: pgsql-performance@postgresql.org Subject: Re: Sequential scan on FK join References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/250 X-Sequence-Number: 15018 Martin Nickel wrote: > EXPLAIN SELECT m.mailcode, l.lead_id > FROM mailing m > INNER JOIN lead l ON m.mailing_id = l.mailing_id > WHERE (m.maildate >= '2005-7-01'::date > AND m.maildate < '2005-8-01'::date) > > Hash Join (cost=62.13..2001702.55 rows=2711552 width=20) > Hash Cond: ("outer".mailing_id = "inner".mailing_id) > -> Seq Scan on lead l (cost=0.00..1804198.60 rows=34065260 width=8) > -> Hash (cost=61.22..61.22 rows=362 width=20) > -> Index Scan using mailing_maildate_idx on mailing m (cost=0.00..61.22 rows=362 width=20) > Index Cond: ((maildate >= '2005-07-01'::date) AND (maildate < '2005-08-01'::date)) Well the reason *why* is that the planner expects 2.71 million rows to be matched. If that was the case, then a seq-scan of 34 million rows might well make sense. The output from EXPLAIN ANALYSE would show us whether that estimate is correct - is it? -- Richard Huxton Archonet Ltd