Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 88FF06365E1 for ; Sun, 12 Sep 2010 15:16:01 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 35600-01-6 for ; Sun, 12 Sep 2010 18:15:53 +0000 (UTC) X-Greylist: delayed 00:27:59.769616 by SQLgrey-1.7.6 Received: from wentylator.ang.com.pl (wentylator.ang.com.pl [89.174.215.202]) by mail.postgresql.org (Postfix) with ESMTP id 6B9B2636B14 for ; Sun, 12 Sep 2010 15:02:01 -0300 (ADT) Received: from Artur7 (cfidsl [83.18.105.226]) by wentylator.ang.com.pl (Postfix) with ESMTP id 26E812DD286 for ; Sun, 12 Sep 2010 19:34:01 +0200 (CEST) From: To: Subject: Problem with mergejoin performance (some bug?) Date: Sun, 12 Sep 2010 19:34:00 +0200 Message-ID: <000001cb52a0$b02682f0$107388d0$@com.pl> X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: ActSoK5NemfiZxkSQzqWVyaU3MQLCQ== Content-Language: pl x-cr-hashedpuzzle: AFHz Azli Be7s B4+p CedX D44E EoPE Gr8S HvfM IrBN I4LE JA3E JIj0 JfOh JizJ Lupg; 1; cABnAHMAcQBsAC0AcABlAHIAZgBvAHIAbQBhAG4AYwBlAEAAcABvAHMAdABnAHIAZQBzAHEAbAAuAG8AcgBnAA==; Sosha1_v1; 7; {AAE555B5-D6A3-4A58-AFC5-359D10849FC4}; YQB6AGEAagBhAGMAQABhAG4AZwAuAGMAbwBtAC4AcABsAA==; Sun, 12 Sep 2010 17:33:58 GMT; UAByAG8AYgBsAGUAbQAgAHcAaQB0AGgAIABtAGUAcgBnAGUAagBvAGkAbgAgAHAAZQByAGYAbwByAG0AYQBuAGMAZQAgACgAcwBvAG0AZQAgAGIAdQBnAD8AKQA= x-cr-puzzleid: {AAE555B5-D6A3-4A58-AFC5-359D10849FC4} X-wentylator-MailScanner-Information: Please contact the ISP for more information X-wentylator-MailScanner: Found to be clean X-wentylator-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=0, required 6, autolearn=not spam) X-wentylator-MailScanner-From: azajac@ang.com.pl 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/103 X-Sequence-Number: 40306 I have a problem with some simple query: select version(); PostgreSQL 8.3.8 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7) vacuum full bug_t1; vacuum full bug_t2; vacuum analyze bug_t1; vacuum analyze bug_t2; explain analyze SELECT ze.id ,rr.id FROM bug_t2 AS rr join bug_t1 AS ze ON (ze.id=rr.id) WHERE (ze.ids=94543); Result is: Merge Join (cost=18.90..20.85 rows=1 width=8) (actual time=614.912..614.912 rows=0 loops=1) Merge Cond: (rr.id = ze.id) -> Index Scan using bug_t2_i1 on bug_t2 rr (cost=0.00..17893.49 rows=278417 width=4) (actual time=0.023..351.945 rows=278417 loops=1) -> Sort (cost=18.88..18.89 rows=4 width=4) (actual time=0.164..0.164 rows=1 loops=1) Sort Key: ze.id Sort Method: quicksort Memory: 17kB -> Index Scan using bug_t1_i1 on bug_t1 ze (cost=0.00..18.84 rows=4 width=4) (actual time=0.059..0.141 rows=4 loops=1) Index Cond: (ids = 94543) Total runtime: 615.003 ms But after SET enable_mergejoin=off; result is: Nested Loop (cost=0.00..52.06 rows=1 width=8) (actual time=0.084..0.084 rows=0 loops=1) -> Index Scan using bug_t1_i1 on bug_t1 ze (cost=0.00..18.84 rows=4 width=4) (actual time=0.016..0.028 rows=4 loops=1) Index Cond: (ids = 94543) -> Index Scan using bug_t2_i1 on bug_t2 rr (cost=0.00..8.29 rows=1 width=4) (actual time=0.008..0.008 rows=0 loops=4) Index Cond: (rr.id = ze.id) Total runtime: 0.154 ms I think that problem is with estimation of total mergejoin time, why is it so small (18.90..20.85) while estimates of subqueries (especially first) is high (0..17893). Merging time should be high, because it needs to scan almost all bug t2 table. Am I right? Artur Zajac