Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 288E414D378 for ; Sun, 18 Mar 2012 17:22:55 -0300 (ADT) Received: from gwmta.wicourts.gov ([165.219.244.99] helo=gw.wicourts.gov) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S9Mcu-000877-T1 for pgsql-bugs@postgresql.org; Sun, 18 Mar 2012 20:22:55 +0000 Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Sun, 18 Mar 2012 15:22:39 -0500 Message-Id: <4F65FDBE02000025000463D6@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.2 Date: Sun, 18 Mar 2012 15:22:38 -0500 From: "Kevin Grittner" To: "Aren Cambre" Cc: ,"Tom Lane" Subject: Re: BUG #6535: LEFT JOIN on large table is altering data References: <10102.1331920604@sss.pgh.pa.us> In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201203/133 X-Sequence-Number: 32694 Aren Cambre wrote: > SELECT COUNT(*) > FROM consistent.master > WHERE citation_id IS NOT NULL > UNION > SELECT COUNT(*) > FROM consistent.master > UNION > SELECT COUNT(*) > FROM consistent.master > WHERE citation_id IS NULL > > I got this result: > > 2085344 > 2085343 > 0 > > Not clear how adding a WHERE clause, whose only practical effect > is to reduce the number of rows returned, could cause *more* rows > to be returned. That seems buggy to me. Never assume that the rows will be returned in any particular order from a query unless you specify ORDER BY. Assuming, as you seem to be doing, that rows from the left side of a UNION will be output before rows from the right side is not safe. You have no way of knowing which row in a result set like that came from which of the UNIONed SELECTs. In this case your assumption is almost certainly wrong. -Kevin