pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Aren Cambre <aren@arencambre.com>
Cc: pgsql-bugs@postgresql.org
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: BUG #6535: LEFT JOIN on large table is altering data
Date: Sun, 18 Mar 2012 15:22:38 -0500
Message-ID: <4F65FDBE02000025000463D6@gw.wicourts.gov> (raw)
In-Reply-To: <CAA1mBrpZRhjRgCqPvMoj=p2-J-S4OsNnMhKX3-GTXdhpmDs=LA@mail.gmail.com>
References: <E1S8YgG-0002hJ-SR@wrigleys.postgresql.org>
	<10102.1331920604@sss.pgh.pa.us>
	<CAA1mBrpZRhjRgCqPvMoj=p2-J-S4OsNnMhKX3-GTXdhpmDs=LA@mail.gmail.com>

Aren Cambre <aren@arencambre.com> 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



view thread (11+ messages)  latest in thread

Message-ID: <4F65FDBE02000025000463D6@gw.wicourts.gov>
Permalink:  ../4F65FDBE02000025000463D6@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4F65FDBE02000025000463D6@gw.wicourts.gov

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: Kevin.Grittner@wicourts.gov, aren@arencambre.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #6535: LEFT JOIN on large table is altering data
  In-Reply-To: <4F65FDBE02000025000463D6@gw.wicourts.gov>
  References: <E1S8YgG-0002hJ-SR@wrigleys.postgresql.org> <10102.1331920604@sss.pgh.pa.us> <CAA1mBrpZRhjRgCqPvMoj=p2-J-S4OsNnMhKX3-GTXdhpmDs=LA@mail.gmail.com> <4F65FDBE02000025000463D6@gw.wicourts.gov>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox