pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: sebastian.calbaza@hgdata.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14648: counts for queries using array unnesting  is incorrect
Date: Fri, 12 May 2017 13:00:33 +0000
Message-ID: <20170512130033.1796.93117@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      14648
Logged by:          Sebastian Calbaza
Email address:      sebastian.calbaza@hgdata.com
PostgreSQL version: 9.6.2
Operating system:   Ubuntu 14.04 AWS
Description:        

Below is a query that we are using to calculate some counts: 
   * first version of the query lacks ```unnest(ids) as id,```, but second
one has it
   * ```companies``` count value is incorrect for the second one, first
query has the correct value

 
```
mydb=#           select  count(company) as available,count(distinct
matchedCompany) as matchedCompanies,count(distinct company) as companies
from
             (
                 SELECT  F.urlx as company,
CB_RDPPKLCPQDVACOMSTEFANHGDATACOM_agg.url as matchedCompany
                 from
                  (select unnest(urls) as urlx from
hg_data_discovery_2017_04_10.GroupedFirmographics
                     where 
              (
                     (TRUE
                      AND TRUE
                      AND revenueRangeMin >= 1
                      AND employeesRangeMin >= 1
                      AND revenueRangeMax <= 1783792664
                      AND employeesRangeMax <= 4999000
                     )
                     OR
                      FALSE
                   )
        ) as I
                   inner join (
                     select unnest(urls) as urlx from
hg_data_discovery_2017_04_10.GroupedInstallsWithoutDateSignalScore where
productId IN (562) and signalScoreId IN (1,2,3)
                     ) as F using(urlx)
                 left outer join CB_RDPPKLCPQDVACOMSTEFANHGDATACOM_agg on
CB_RDPPKLCPQDVACOMSTEFANHGDATACOM_agg.url=F.urlx where TRUE and TRUE
             ) as P
                 ;
 available | matchedcompanies | companies 
-----------+------------------+-----------
    496493 |            28503 |    495799
(1 row)

Time: 7974.053 ms
mydb=#              select count(id) as people, count(company) as
available,count(distinct matchedCompany) as matchedCompanies,count(distinct
company) as companies from
             (
                 SELECT unnest(ids) as id, F.urlx as company,
CB_RDPPKLCPQDVACOMSTEFANHGDATACOM_agg.url as matchedCompany
                 from
                  (select unnest(urls) as urlx from
hg_data_discovery_2017_04_10.GroupedFirmographics
                     where 
              (
                     (TRUE
                      AND TRUE
                      AND revenueRangeMin >= 1
                      AND employeesRangeMin >= 1
                      AND revenueRangeMax <= 1783792664
                      AND employeesRangeMax <= 4999000
                     )
                     OR
                      FALSE
                   )
        ) as I
                   inner join (
                     select unnest(urls) as urlx from
hg_data_discovery_2017_04_10.GroupedInstallsWithoutDateSignalScore where
productId IN (562) and signalScoreId IN (1,2,3)
                     ) as F using(urlx)
                 left outer join CB_RDPPKLCPQDVACOMSTEFANHGDATACOM_agg on
CB_RDPPKLCPQDVACOMSTEFANHGDATACOM_agg.url=F.urlx where TRUE and TRUE
             ) as P
                 ;
 people | available | matchedcompanies | companies 
--------+-----------+------------------+-----------
 689905 |    689905 |            28503 |     28503

```




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


view thread (7+ messages)  latest in thread

Message-ID: <20170512130033.1796.93117@wrigleys.postgresql.org>
Permalink:  ../20170512130033.1796.93117@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20170512130033.1796.93117@wrigleys.postgresql.org

 · 

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: sebastian.calbaza@hgdata.com
  Subject: Re: BUG #14648: counts for queries using array unnesting  is incorrect
  In-Reply-To: <20170512130033.1796.93117@wrigleys.postgresql.org>
  References: <20170512130033.1796.93117@wrigleys.postgresql.org>

* 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