X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 8EB72D1D2EA for ; Mon, 22 Mar 2004 19:00:23 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 43028-02 for ; Mon, 22 Mar 2004 15:00:30 -0400 (AST) Received: from tupari.net (node-40242ac2.lga.onnet.us.uu.net [64.36.42.194]) by svr1.postgresql.org (Postfix) with ESMTP id 326E1D1DACE for ; Mon, 22 Mar 2004 15:00:19 -0400 (AST) Received: from selectacast.net ([192.168.0.2]) by tupari.net (8.12.8/8.12.8) with ESMTP id i2MJ0UCE025470; Mon, 22 Mar 2004 14:00:31 -0500 Message-ID: <405F37CE.9070302@selectacast.net> Date: Mon, 22 Mar 2004 14:00:30 -0500 From: Joseph Shraibman User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane , pgsql-performance@postgresql.org Subject: Re: two seperate queries run faster than queries ORed together References: <200403221655.28667.dev@archonet.com> <405F2893.5090805@selectacast.net> <6875.1079979859@sss.pgh.pa.us> In-Reply-To: <6875.1079979859@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/294 X-Sequence-Number: 6150 Tom Lane wrote: > Joseph Shraibman writes: > >>No, pkey is not the primary key in this case. The number of entries in u >>that have pkey 260 and not boolfield is 344706. > > > ... and every one of those rows *must* be included in the join input, *If* you use one big join in the first place. If postgres ran the query to first get the values with status == 3 from u, then ran the query to get the entries from d, then combined them, the result would be the same but the output faster. Instead it is doing seq scans on both tables and doing an expensive join that returns only a few rows.