Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 4591F6323E3 for ; Mon, 13 Sep 2010 12:16:53 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 04457-04 for ; Mon, 13 Sep 2010 15:16:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id ECCE862DBEC for ; Mon, 13 Sep 2010 12:16:42 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o8DFGeFB012712; Mon, 13 Sep 2010 11:16:40 -0400 (EDT) To: azajac@ang.com.pl cc: pgsql-performance@postgreSQL.org Subject: Re: Problem with mergejoin performance In-reply-to: <005301cb5354$f0797100$d16c5300$@com.pl> References: <000001cb5307$78955480$69bffd80$@com.pl> <11777.1284387988@sss.pgh.pa.us> <005301cb5354$f0797100$d16c5300$@com.pl> Comments: In-reply-to message dated "Mon, 13 Sep 2010 17:04:17 +0200" Date: Mon, 13 Sep 2010 11:16:40 -0400 Message-ID: <12711.1284391000@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/56 X-Sequence-Number: 40259 [ Please keep the list cc'd ] writes: >> What exactly are those join key values, and what are the min/max values >> in bug_t2? > min of Bug_t1.id = 42, > max of Bug_t1.id = 393065, > min of Bug_t2.id = 352448, > max of Bug_t2.id = 388715, > select count(id) from bug_t2 > 29 > select count(*) from bug_t2 > 278417 > And because there is only 29 not null records in bug_t2: Oh, that's the real problem: thousands of nulls in bug_t2. The planner is thinking those don't have to be scanned, but the executor wasn't on the same page until very recently: http://archives.postgresql.org/pgsql-committers/2010-05/msg00334.php That patch will be in the next 8.3 update. regards, tom lane