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 0C7B8D1B98D for ; Mon, 22 Mar 2004 18:24:15 +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 28397-04 for ; Mon, 22 Mar 2004 14:24:22 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id B4CB0D1B49B for ; Mon, 22 Mar 2004 14:24:11 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i2MIOJ4X006876; Mon, 22 Mar 2004 13:24:19 -0500 (EST) To: Joseph Shraibman Cc: Richard Huxton , pgsql-performance@postgresql.org Subject: Re: two seperate queries run faster than queries ORed together In-reply-to: <405F2893.5090805@selectacast.net> References: <200403221655.28667.dev@archonet.com> <405F2893.5090805@selectacast.net> Comments: In-reply-to Joseph Shraibman message dated "Mon, 22 Mar 2004 12:55:31 -0500" Date: Mon, 22 Mar 2004 13:24:19 -0500 Message-ID: <6875.1079979859@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/293 X-Sequence-Number: 6149 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, regardless of its status value, because it might join to some d row that has status=3. Conversely, every single row of d must be considered in the join because it might join to some u row with status=3. So any way you slice it, this query requires a large and expensive join operation, no matter that there are only a few rows with the right status values in the other table. I'd rewrite the query if I were you. regards, tom lane