Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 6D9569FA5E2 for ; Mon, 23 Jul 2007 09:02:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 01670-05 for ; Mon, 23 Jul 2007 09:02:26 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from oxford.xeocode.com (unknown [62.232.55.118]) by postgresql.org (Postfix) with ESMTP id 3365A9FA5D8 for ; Mon, 23 Jul 2007 09:02:31 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1ICwcO-00010t-Mg; Mon, 23 Jul 2007 13:02:28 +0100 From: Gregory Stark To: Nis =?iso-8859-1?Q?J=F8rgensen?= Cc: Subject: Re: The nested view from hell - Restricting a subquerry In-Reply-To: <87d4yjmkiw.fsf@oxford.xeocode.com> (Gregory Stark's message of "Mon, 23 Jul 2007 12:23:03 +0100") Organization: EnterpriseDB References: <46A2CABF.3080108@obviously.com> <2385.1185127507@sss.pgh.pa.us> <87y7h74un7.fsf@oxford.xeocode.com> <87d4yjmkiw.fsf@oxford.xeocode.com> X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.sql" 633) Date: Mon, 23 Jul 2007 13:02:28 +0100 Message-ID: <878x97mip7.fsf@oxford.xeocode.com> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/135 X-Sequence-Number: 28870 "Gregory Stark" writes: > Nis J=F8rgensen writes: > >> 1. Look up all order_ids for which (order_id,my_invoice_id) appear in >> eg_orders >> >> 2. Find all rows (in both branches of the UNION) with these id_s Oh, did you mean look up the order_ids for which there was at least one rec= ord with the invoice_id specified, then look up all records with those order_ids regardless of invoice_id?=20 That would work but as you say it would be hard to tell whether it will be = any faster than just processing all the order_ids. --=20 Gregory Stark EnterpriseDB http://www.enterprisedb.com