Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 56A1F2E004B for ; Wed, 23 Apr 2008 10:31:47 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 38609-05 for ; Wed, 23 Apr 2008 10:31:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from oxford.xeocode.com (206-248-161-178.dsl.teksavvy.com [206.248.161.178]) by developer.postgresql.org (Postfix) with ESMTP id A55892E0048 for ; Wed, 23 Apr 2008 10:31:43 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.69) (envelope-from ) id 1Jof4V-0005QD-B2; Wed, 23 Apr 2008 09:31:39 -0400 To: "Hans Ekbrand" Cc: Subject: Re: mysterious difference in speed when combining two queries with OR In-Reply-To: <20080423092205.GI11886@amin> (Hans Ekbrand's message of "Wed\, 23 Apr 2008 11\:22\:09 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.performance" 5333) References: <20080423072303.GF11886@amin> <20080423075810.GB8401@a-kretschmer.de> <20080423085704.GG8401@a-kretschmer.de> <20080423092205.GI11886@amin> From: Gregory Stark Organization: EnterpriseDB Date: Wed, 23 Apr 2008 09:31:39 -0400 Message-ID: <873apcu284.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.498 tagged_above=0 required=5 tests=AWL=-1.217, RCVD_IN_SORBS_DUL=1.615, RDNS_DYNAMIC=0.1 X-Spam-Level: X-Archive-Number: 200804/349 X-Sequence-Number: 29842 "Hans Ekbrand" writes: > No, I just wanted to show the time differences, I haven't used join > before. Now that you have adviced me to, I have tried your suggestion > to rewrite B as a union and it works good! Just as fast as the A Query! You can even do better. If you know the two sets of mid are disjoint you can use UNION ALL. If not you could remove the two DISTINCTs as the UNION will take care of removing duplicates. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's On-Demand Production Tuning