From: David G. Johnston <david.g.johnston@gmail.com>
To: Sebastion Calbaza <sebastian.calbaza@hgdata.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14648: counts for queries using array unnesting is incorrect
Date: Fri, 12 May 2017 08:46:04 -0700
Message-ID: <CAKFQuwbOPohNb=Ya_VsHGmL2-4t2-7F2MCMQGWQD+11O2JrgwA@mail.gmail.com> (raw)
In-Reply-To: <CAHTsN0eawXJ1XvzekGHfk7jCSX-G9-WfXKM4VpyWDTkMmAob1g@mail.gmail.com>
References: <20170512130033.1796.93117@wrigleys.postgresql.org>
<18166.1494598847@sss.pgh.pa.us>
<CAHTsN0eawXJ1XvzekGHfk7jCSX-G9-WfXKM4VpyWDTkMmAob1g@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Fri, May 12, 2017 at 7:55 AM, Sebastion Calbaza <
sebastian.calbaza@hgdata.com> wrote:
> Thanks for replying.... I know it's complicated to follow it (even if
> formatted ) , but probably I did not emphasize enough that by using
> unnest(ids) in the second query, the distinct count for company is not
> computed correctly anymore.
> Focusing on the used select clauses is important, they are just distinct
> counts, it would have been logical to stay the same for both queries,
> ignoring the unnest(ids)(the data set is in the milions of rows so you need
> to take my word that the first query return the correct values :) ).
>
In the first query the number of distinct companies is greater than the
number of matched companies. In the second the numbers are equal. If the
only difference between the two is the "unnest(ids)" then its presence is
causing every unmatched company to be discarded from the result. Since
"SELECT unnest(null::text[])" is the empty set it would remove the
corresponding row from your subquery output. You might try writing the
following which will convert the empty set to a NULL and thus not discard
records.
(SELECT unnest(ids)) AS id, F.urlx as company ...
David J.
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: david.g.johnston@gmail.com, sebastian.calbaza@hgdata.com
Subject: Re: BUG #14648: counts for queries using array unnesting is incorrect
In-Reply-To: <CAKFQuwbOPohNb=Ya_VsHGmL2-4t2-7F2MCMQGWQD+11O2JrgwA@mail.gmail.com>
References: <20170512130033.1796.93117@wrigleys.postgresql.org> <18166.1494598847@sss.pgh.pa.us> <CAHTsN0eawXJ1XvzekGHfk7jCSX-G9-WfXKM4VpyWDTkMmAob1g@mail.gmail.com> <CAKFQuwbOPohNb=Ya_VsHGmL2-4t2-7F2MCMQGWQD+11O2JrgwA@mail.gmail.com>
* 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