Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d9C1K-0001aD-Rf for pgsql-bugs@arkaria.postgresql.org; Fri, 12 May 2017 14:58:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d9C1K-0001UA-Ai for pgsql-bugs@arkaria.postgresql.org; Fri, 12 May 2017 14:58:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d9Bz7-0000FI-Vk for pgsql-bugs@postgresql.org; Fri, 12 May 2017 14:56:02 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1d9Bz4-0001GY-GD for pgsql-bugs@postgresql.org; Fri, 12 May 2017 14:56:01 +0000 Received: by mail-wm0-x235.google.com with SMTP id d127so17675115wmf.0 for ; Fri, 12 May 2017 07:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hgdata.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=8DsABXnwB91n0AVz+Vm6ZYbaKNgHEV18yre1IUSVMyI=; b=pQMJXXEFyxfaygqGHu+Ckz51sGQVpvEWJlssl6DZtyu5t8KQiXcrsJVd0sUE+GknSm gtcu0W8P8lPYni+vSGs1u7gMSCNu66B2LeZ6TeTDp1PWjxlA3Qbwc1D6wScr2zjgI3rV weA2hFG9VwX6dg/aZy7BDtTnyIjFbLKzFDxImN41NWllpQXdvVttMtJZYJOwNECA33/J /T+BcTFq0+n+KVzEyndyBPlKxZEzDkw2I9rJ7Ail5R36JNJYTVSBFrpBmDEf9T01QEOv 9H4GV2jFtRighlpXILT5GGFASxnuWGbxPABVyCZEIr/gXyCLbmBQoefi+Ksnp9T8YHTU fOBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=8DsABXnwB91n0AVz+Vm6ZYbaKNgHEV18yre1IUSVMyI=; b=VH9UpLEZIEp0jqkkOuaf0SJ3kPG/zcwBceYfLq9M5AmH5R2ISXdoM7DVVdOAarlDWn WipEY6u8UnvYkumyaMrloctqT8D8hSRRD5HmloWCE7sqrxcAMj+5iosc0H7w/XvgVVgO pfBYumoTCMA+kkQjH0XnM1Mo6kYHMW2Lds2kWqLKhJOjwo6OHtqjYi6t+N7A6KLUsTnd bGMf+skHS1Ca0cmaX0PbWophHFLEI3IThrvYVh4pjn+JpKEx7zmkJJ2tDYpuD3BH/Dr5 F9u7xJl6xXJRQpLxSUgaMm8E7EiMSm0SZWKjIXTYrvh/ZJzL6cdseaOfP0nEMnxWeoUT GCGw== X-Gm-Message-State: AODbwcD5n4+XuRGrf5wPfaEuxp/JQZB380R0oxeved5xxV/Jynv01DL1 L6QkgRKad0Ugz4r38hjZeJOhdDH8nkML X-Received: by 10.28.103.214 with SMTP id b205mr2802953wmc.122.1494600957096; Fri, 12 May 2017 07:55:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.159.17 with HTTP; Fri, 12 May 2017 07:55:56 -0700 (PDT) In-Reply-To: <18166.1494598847@sss.pgh.pa.us> References: <20170512130033.1796.93117@wrigleys.postgresql.org> <18166.1494598847@sss.pgh.pa.us> From: Sebastion Calbaza Date: Fri, 12 May 2017 17:55:56 +0300 Message-ID: Subject: Re: BUG #14648: counts for queries using array unnesting is incorrect Cc: "pgsql-bugs@postgresql.org" Content-Type: multipart/alternative; boundary="001a114b330e210af4054f54e792" X-Pg-Spam-Score: -1.7 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --001a114b330e210af4054f54e792 Content-Type: text/plain; charset="UTF-8" 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 :) ). Anyway, will try to test it with latest version, also will try to provide some sql test case for this, but again... There surely is an issue with the unnesting arrays (at least in the relase that I'm using) Seb On Fri, May 12, 2017 at 5:20 PM, Tom Lane wrote: > sebastian.calbaza@hgdata.com writes: > > 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 > > My first suggestion would be to see if updating to 9.6.3 fixes it. > If not, please try to create a self-contained test case. These > queries are unreadable, and without the underlying data, nobody > else can even tell whether the answers are wrong or not. > > https://wiki.postgresql.org/wiki/Guide_to_reporting_problems > > regards, tom lane > --001a114b330e210af4054f54e792 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for replying.... I know it's complica= ted to follow it (even if formatted ) , but probably I did not emphasize en= ough that by using unnest(ids) in the second query, the distinct count for = company is not computed correctly anymore.
Focusing on the used select c= lauses=C2=A0 is important, they are just distinct counts, it would have bee= n logical to stay the same for both queries, ignoring the unnest(ids)(the d= ata set is in the milions of rows so you need to take my word that the firs= t query return the correct values :) ).

Anyway, will try to te= st it with latest version, also will try to provide some sql test case for = this, but again... There surely is an issue with the unnesting arrays (at l= east in the relase that I'm using)

Seb

On Fri, May 12, 2017 at 5:2= 0 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
sebastian.c= albaza@hgdata.com writes:
> Below is a query that we are using to calculate some counts:
>=C2=A0 =C2=A0 * first version of the query lacks ```unnest(ids) as id,`= ``, but second
> one has it
>=C2=A0 =C2=A0 * ```companies``` count value is incorrect for the second= one, first
> query has the correct value

My first suggestion would be to see if updating to 9.6.3 fixes it.
If not, please try to create a self-contained test case.=C2=A0 These
queries are unreadable, and without the underlying data, nobody
else can even tell whether the answers are wrong or not.

https://wiki.postgresql.org/wiki/Gu= ide_to_reporting_problems

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane

--001a114b330e210af4054f54e792--