count_nulls(VARIADIC "any")

Lists: pgsql-hackers
From: Marko Tiikkaja <marko(at)joh(dot)to>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:18:41
Message-ID: 55CB7FF1.70506@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

I'd like to suggest $SUBJECT for inclusion in Postgres 9.6. I'm sure
everyone would've found it useful at some point in their lives, and the
fact that it can't be properly implemented in any language other than C
I think speaks for the fact that we as a project should provide it.

A quick and dirty proof of concept (patch attached):

=# select count_nulls(null::int, null::text, 17, 'bar');
count_nulls
-------------
2
(1 row)

Its natural habitat would be CHECK constraints, e.g:

CHECK (count_nulls(a,b,c) IN (0, 3))

Will finish this up for the next CF, unless someone wants to tell me how
stupid this idea is before that.

.m

Attachment Content-Type Size
count_nulls.patch text/plain 3.2 KB

From: Greg Stark <stark(at)mit(dot)edu>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:23:50
Message-ID: CAM-w4HPgGVM2owoYE9gBc-h+-C=e_RL26QsEon2sAngkxmyznQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 12, 2015 at 6:18 PM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> Will finish this up for the next CF, unless someone wants to tell me how
> stupid this idea is before that.

I'm kind of puzzled what kind of schema would need this.

--
greg


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:30:38
Message-ID: 20150812173038.GI3040@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Greg Stark wrote:
> On Wed, Aug 12, 2015 at 6:18 PM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> > Will finish this up for the next CF, unless someone wants to tell me how
> > stupid this idea is before that.
>
> I'm kind of puzzled what kind of schema would need this.

I've seen cases where you want some entity to be of either of some
number of types. In those cases you have nullable FKs in separate
columns, and only one of them can be non null.

The name count_nulls() suggest an aggregate function to me, though.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:31:27
Message-ID: CAFj8pRDW18xhTrVDTDKdomHEcAjmFZrojkAGgpvyjbw8gyoB_w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

2015-08-12 19:18 GMT+02:00 Marko Tiikkaja <marko(at)joh(dot)to>:

> Hi,
>
> I'd like to suggest $SUBJECT for inclusion in Postgres 9.6. I'm sure
> everyone would've found it useful at some point in their lives, and the
> fact that it can't be properly implemented in any language other than C I
> think speaks for the fact that we as a project should provide it.
>
> A quick and dirty proof of concept (patch attached):
>
> =# select count_nulls(null::int, null::text, 17, 'bar');
> count_nulls
> -------------
> 2
> (1 row)
>
> Its natural habitat would be CHECK constraints, e.g:
>
> CHECK (count_nulls(a,b,c) IN (0, 3))
>
> Will finish this up for the next CF, unless someone wants to tell me how
> stupid this idea is before that.
>

It is not bad idea

+1

Pavel

>
> .m
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>


From: Peter Geoghegan <pg(at)heroku(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Greg Stark <stark(at)mit(dot)edu>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:32:45
Message-ID: CAM3SWZRwfiQOmFVJDZVOn==wqTWKfXquhaus=Q5Wka9LbUw8xA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 12, 2015 at 10:30 AM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
> The name count_nulls() suggest an aggregate function to me, though.

I thought the same.

--
Peter Geoghegan


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:33:22
Message-ID: 55CB8362.8030204@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-08-12 7:23 PM, Greg Stark wrote:
> On Wed, Aug 12, 2015 at 6:18 PM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
>> Will finish this up for the next CF, unless someone wants to tell me how
>> stupid this idea is before that.
>
> I'm kind of puzzled what kind of schema would need this.

The first example I could find from our schema was specifying the URL
for a Remote Procedure Call. You can either specify a single request
URI, or you can specify the pieces: protocol, host, port, path. So the
constraints look roughly like this:

CHECK ((fulluri IS NULL) <> (protocol IS NULL)),
CHECK ((protocol IS NULL) = ALL(ARRAY[host IS NULL, port IS NULL,
path IS NULL]))

Obviously the second one would be much prettier with count_nulls().

The other example is an OOP inheritance-like schema where an object
could be one of any X number of types. You could write that:

CHECK ((a IS NULL)::int + (b IS NULL)::int + (c IS NULL)::int) = 1)

or just:

CHECK (count_nulls(a,b,c) = 1)

The first example could be redesigned with three tables, but that seems
like a cure worse than the disease.

.m


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Peter Geoghegan <pg(at)heroku(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:35:23
Message-ID: CAFj8pRAuxg1HLJMpmdEqcKjhDtC6CJ4Kf+qoe9af=+73L9Ci6g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

2015-08-12 19:32 GMT+02:00 Peter Geoghegan <pg(at)heroku(dot)com>:

> On Wed, Aug 12, 2015 at 10:30 AM, Alvaro Herrera
> <alvherre(at)2ndquadrant(dot)com> wrote:
> > The name count_nulls() suggest an aggregate function to me, though.
>
> I thought the same.
>

maybe nulls_count ?

we have regr_count already

Regards

Pavel

>
>
> --
> Peter Geoghegan
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Peter Geoghegan <pg(at)heroku(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:37:01
Message-ID: 55CB843D.7090604@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-08-12 7:35 PM, Pavel Stehule wrote:
> maybe nulls_count ?
>
> we have regr_count already

But that's an aggregate as well..

.m


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Peter Geoghegan <pg(at)heroku(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 17:44:23
Message-ID: CAFj8pRBvVquuBCHutU6mYi6q+dpa--dSu68oWL51qUDZ2wd3Jw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

2015-08-12 19:37 GMT+02:00 Marko Tiikkaja <marko(at)joh(dot)to>:

> On 2015-08-12 7:35 PM, Pavel Stehule wrote:
>
>> maybe nulls_count ?
>>
>> we have regr_count already
>>
>
> But that's an aggregate as well..
>

my mistake

Pavel

>
>
> .m
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Geoghegan <pg(at)heroku(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-12 23:11:36
Message-ID: 29938.1439421096@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Peter Geoghegan <pg(at)heroku(dot)com> writes:
> On Wed, Aug 12, 2015 at 10:30 AM, Alvaro Herrera
> <alvherre(at)2ndquadrant(dot)com> wrote:
>> The name count_nulls() suggest an aggregate function to me, though.

> I thought the same.

Ditto. I'd be fine with this if we can come up with a name that
doesn't sound like an aggregate. The best I can do offhand is
"number_of_nulls()", which doesn't seem very pretty.

regards, tom lane


From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Geoghegan <pg(at)heroku(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-13 00:19:01
Message-ID: CAKFQuwawJq1Sf3jLFeJAE24MmvsAdieLrxkboJU9OaTJojk3YA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 12, 2015 at 4:11 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Peter Geoghegan <pg(at)heroku(dot)com> writes:
> > On Wed, Aug 12, 2015 at 10:30 AM, Alvaro Herrera
> > <alvherre(at)2ndquadrant(dot)com> wrote:
> >> The name count_nulls() suggest an aggregate function to me, though.
>
> > I thought the same.
>
> Ditto. I'd be fine with this if we can come up with a name that
> doesn't sound like an aggregate. The best I can do offhand is
> "number_of_nulls()", which doesn't seem very pretty.
>
>
nulls_in(a, b, c) IN (0, 3) - yes the repetition is not great...

David J.


From: "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Geoghegan <pg(at)heroku(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-13 07:18:41
Message-ID: CACACo5SBcJnX5bSFOCKCsKvCXR2_vLeLyZk-5+E2=+3H=ae1MA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Aug 13, 2015 at 2:19 AM, David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> On Wed, Aug 12, 2015 at 4:11 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
>> Peter Geoghegan <pg(at)heroku(dot)com> writes:
>> > On Wed, Aug 12, 2015 at 10:30 AM, Alvaro Herrera
>> > <alvherre(at)2ndquadrant(dot)com> wrote:
>> >> The name count_nulls() suggest an aggregate function to me, though.
>>
>> > I thought the same.
>>
>> Ditto. I'd be fine with this if we can come up with a name that
>> doesn't sound like an aggregate. The best I can do offhand is
>> "number_of_nulls()", which doesn't seem very pretty.
>>
>>
> nulls_in(a, b, c) IN (0, 3) - yes the repetition is not great...
>

How about these:

nulls_rank() (the analogy being 0 <= "rank" <= "set size")
nnulls()

or just

nulls() (this one might be a bit confusing due to existing NULLS LAST/FIRST
syntax, though)

--
Alex


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Geoghegan <pg(at)heroku(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-13 07:21:16
Message-ID: 55CC456C.8060808@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 8/13/15 9:18 AM, Shulgin, Oleksandr wrote:
> nnulls()

I think I'd prefer num_nulls() over that.

.m


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Geoghegan <pg(at)heroku(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-13 07:25:15
Message-ID: CAFj8pRAmeHsq6Q4sc_uC+USS97dALoqO5NK1cuWDUfPqWe6SOA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

2015-08-13 9:21 GMT+02:00 Marko Tiikkaja <marko(at)joh(dot)to>:

> On 8/13/15 9:18 AM, Shulgin, Oleksandr wrote:
>
>> nnulls()
>>
>
> I think I'd prefer num_nulls() over that.
>

can be

what about similar twin function num_nonulls()?

Pavel

>
>
> .m
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Atri Sharma <atri(dot)jiit(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Geoghegan <pg(at)heroku(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-13 07:28:56
Message-ID: CAOeZVifuN56vRk=_4ZEGeQwyubvnGVvyr_JSiVoJkBGvHLnaog@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Aug 13, 2015 at 12:55 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

>
>
> 2015-08-13 9:21 GMT+02:00 Marko Tiikkaja <marko(at)joh(dot)to>:
>
>> On 8/13/15 9:18 AM, Shulgin, Oleksandr wrote:
>>
>>> nnulls()
>>>
>>
>> I think I'd prefer num_nulls() over that.
>>
>
> can be
>
> what about similar twin function num_nonulls()?
>
>
+1


From: "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Geoghegan <pg(at)heroku(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-13 07:47:09
Message-ID: CACACo5TAE4WX3=pMFXOxofa4QtSrnpXz_EROH822n+YbZU6Naw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Aug 13, 2015 at 9:25 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

>
>
> 2015-08-13 9:21 GMT+02:00 Marko Tiikkaja <marko(at)joh(dot)to>:
>
>> On 8/13/15 9:18 AM, Shulgin, Oleksandr wrote:
>>
>>> nnulls()
>>>
>>
>> I think I'd prefer num_nulls() over that.
>>
>
> can be
>
> what about similar twin function num_nonulls()?
>

Yes. But I'm can't see any precedent for naming it like num_*... And if
anything, should it be num_nonnulls() then?


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Geoghegan <pg(at)heroku(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-08-13 08:01:53
Message-ID: CAFj8pRB1iUTeOv8Gpy1jn2+1r3-2U70DHi2ygtO46otrF2rwKg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

2015-08-13 9:47 GMT+02:00 Shulgin, Oleksandr <oleksandr(dot)shulgin(at)zalando(dot)de>:

> On Thu, Aug 13, 2015 at 9:25 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>>
>>
>> 2015-08-13 9:21 GMT+02:00 Marko Tiikkaja <marko(at)joh(dot)to>:
>>
>>> On 8/13/15 9:18 AM, Shulgin, Oleksandr wrote:
>>>
>>>> nnulls()
>>>>
>>>
>>> I think I'd prefer num_nulls() over that.
>>>
>>
>> can be
>>
>> what about similar twin function num_nonulls()?
>>
>
> Yes. But I'm can't see any precedent for naming it like num_*... And if
> anything, should it be num_nonnulls() then?
>

it is detail - depends on final naming convention.


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-21 05:02:11
Message-ID: 564FFAD3.7050806@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hello,

Here's a patch implementing this under the name num_nulls(). For
January's CF, of course.

.m

Attachment Content-Type Size
num_nulls_v2.patch text/x-patch 7.9 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-21 05:06:25
Message-ID: 15336.1448082385@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Marko Tiikkaja <marko(at)joh(dot)to> writes:
> Here's a patch implementing this under the name num_nulls(). For
> January's CF, of course.

What's this do that "count(*) - count(x)" doesn't?

regards, tom lane


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-21 05:11:30
Message-ID: 564FFD02.6010600@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-11-21 06:06, Tom Lane wrote:
> Marko Tiikkaja <marko(at)joh(dot)to> writes:
>> Here's a patch implementing this under the name num_nulls(). For
>> January's CF, of course.
>
> What's this do that "count(*) - count(x)" doesn't?

This is sort of a lateral version of count(x); the input is a list of
expressions rather than an expression executed over a bunch of input rows.

.m


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-21 05:12:36
Message-ID: 564FFD44.2090302@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-11-21 06:02, I wrote:
> Here's a patch implementing this under the name num_nulls(). For
> January's CF, of course.

I forgot to update the some references in the documentation. Fixed in
v3, attached.

.m

Attachment Content-Type Size
num_nulls_v3.patch text/x-patch 8.7 KB

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-21 05:52:55
Message-ID: 565006B7.3050404@BlueTreble.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 11/20/15 11:12 PM, Marko Tiikkaja wrote:
> On 2015-11-21 06:02, I wrote:
>> Here's a patch implementing this under the name num_nulls(). For
>> January's CF, of course.
>
> I forgot to update the some references in the documentation. Fixed in
> v3, attached.

I thought there was going to be a not-null equivalent as well? I've
definitely wanted both variations in the past.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-21 05:55:23
Message-ID: 5650074B.20700@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-11-21 06:52, Jim Nasby wrote:
> On 11/20/15 11:12 PM, Marko Tiikkaja wrote:
>> On 2015-11-21 06:02, I wrote:
>>> Here's a patch implementing this under the name num_nulls(). For
>>> January's CF, of course.
>>
>> I forgot to update the some references in the documentation. Fixed in
>> v3, attached.
>
> I thought there was going to be a not-null equivalent as well? I've
> definitely wanted both variations in the past.

I'm not sure that's necessary. It's quite simple to implement yourself
using the int - int operator.

.m


From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-22 17:29:20
Message-ID: 5651FB70.9090202@BlueTreble.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 11/20/15 11:55 PM, Marko Tiikkaja wrote:
> On 2015-11-21 06:52, Jim Nasby wrote:
>> On 11/20/15 11:12 PM, Marko Tiikkaja wrote:
>>> On 2015-11-21 06:02, I wrote:
>>>> Here's a patch implementing this under the name num_nulls(). For
>>>> January's CF, of course.
>>>
>>> I forgot to update the some references in the documentation. Fixed in
>>> v3, attached.
>>
>> I thought there was going to be a not-null equivalent as well? I've
>> definitely wanted both variations in the past.
>
> I'm not sure that's necessary. It's quite simple to implement yourself
> using the int - int operator.

Only if you know how many columns there already are.

Or does this not work if you hand it a row?
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-22 17:34:24
Message-ID: 5651FCA0.1020501@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-11-22 18:29, Jim Nasby wrote:
> Only if you know how many columns there already are.
>
> Or does this not work if you hand it a row?

It "works" in the sense that it tells you whether the row is NULL or
not. I.e. the answer will always be 0 or 1.

.m


From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-22 20:17:34
Message-ID: 565222DE.1000109@BlueTreble.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 11/22/15 11:34 AM, Marko Tiikkaja wrote:
> On 2015-11-22 18:29, Jim Nasby wrote:
>> Only if you know how many columns there already are.
>>
>> Or does this not work if you hand it a row?
>
> It "works" in the sense that it tells you whether the row is NULL or
> not. I.e. the answer will always be 0 or 1.

Hrm, I was hoping something like count_nulls(complex_type.*) would work.

I guess one could always create a wrapper function that does
count_not_nulls() anyway.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2015-11-22 20:25:21
Message-ID: 565224B1.60901@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-11-22 21:17, Jim Nasby wrote:
> On 11/22/15 11:34 AM, Marko Tiikkaja wrote:
>> On 2015-11-22 18:29, Jim Nasby wrote:
>>> Only if you know how many columns there already are.
>>>
>>> Or does this not work if you hand it a row?
>>
>> It "works" in the sense that it tells you whether the row is NULL or
>> not. I.e. the answer will always be 0 or 1.
>
> Hrm, I was hoping something like count_nulls(complex_type.*) would work.

Nope:

=# select num_nulls((f).*) from (select '(1,2,3)'::foo) ss(f);
ERROR: row expansion via "*" is not supported here

.m


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-03 20:37:15
Message-ID: CAFj8pRCH2W=oq-FiwA4-LT_0bB6n9AaVK2QOr+_quLm2UdWJyQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

2015-08-12 19:18 GMT+02:00 Marko Tiikkaja <marko(at)joh(dot)to>:

> Hi,
>
> I'd like to suggest $SUBJECT for inclusion in Postgres 9.6. I'm sure
> everyone would've found it useful at some point in their lives, and the
> fact that it can't be properly implemented in any language other than C I
> think speaks for the fact that we as a project should provide it.
>
> A quick and dirty proof of concept (patch attached):
>
> =# select count_nulls(null::int, null::text, 17, 'bar');
> count_nulls
> -------------
> 2
> (1 row)
>
> Its natural habitat would be CHECK constraints, e.g:
>
> CHECK (count_nulls(a,b,c) IN (0, 3))
>
> Will finish this up for the next CF, unless someone wants to tell me how
> stupid this idea is before that.
>
>
> .m
>

I am sending updated version - support num_nulls and num_notnulls

Regards

Pavel


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-03 20:37:41
Message-ID: CAFj8pRCHT9XX1Ab=3wZwqv0uaFT5eorCjtL5Rc906ZoBs_TBdw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

2016-01-03 21:37 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

> Hi
>
>
> 2015-08-12 19:18 GMT+02:00 Marko Tiikkaja <marko(at)joh(dot)to>:
>
>> Hi,
>>
>> I'd like to suggest $SUBJECT for inclusion in Postgres 9.6. I'm sure
>> everyone would've found it useful at some point in their lives, and the
>> fact that it can't be properly implemented in any language other than C I
>> think speaks for the fact that we as a project should provide it.
>>
>> A quick and dirty proof of concept (patch attached):
>>
>> =# select count_nulls(null::int, null::text, 17, 'bar');
>> count_nulls
>> -------------
>> 2
>> (1 row)
>>
>> Its natural habitat would be CHECK constraints, e.g:
>>
>> CHECK (count_nulls(a,b,c) IN (0, 3))
>>
>> Will finish this up for the next CF, unless someone wants to tell me how
>> stupid this idea is before that.
>>
>>
>> .m
>>
>
> I am sending updated version - support num_nulls and num_notnulls
>

and patch

>
> Regards
>
> Pavel
>

Attachment Content-Type Size
num_nulls_v4.patch text/x-patch 12.8 KB

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-03 21:49:14
Message-ID: 5689975A.101@BlueTreble.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 1/3/16 2:37 PM, Pavel Stehule wrote:
> + /* num_nulls(VARIADIC NULL) is defined as NULL */
> + if (PG_ARGISNULL(0))
> + return false;

Could you add to the comment explaining why that's the desired behavior?

> + /*
> + * Non-null argument had better be an array. We assume that any call
> + * context that could let get_fn_expr_variadic return true will have
> + * checked that a VARIADIC-labeled parameter actually is an array. So
> + * it should be okay to just Assert that it's an array rather than
> + * doing a full-fledged error check.
> + */
> + Assert(OidIsValid(get_base_element_type(get_fn_expr_argtype(fcinfo->flinfo, 0))));

Erm... is that really the way to verify that what you have is an array?
ISTM there should be a macro for that somewhere...

> + /* OK, safe to fetch the array value */
> + arr = PG_GETARG_ARRAYTYPE_P(0);
> +
> + ndims = ARR_NDIM(arr);
> + dims = ARR_DIMS(arr);
> + nitems = ArrayGetNItems(ndims, dims);
> +
> + bitmap = ARR_NULLBITMAP(arr);
> + if (bitmap)
> + {
> + bitmask = 1;
> +
> + for (i = 0; i < nitems; i++)
> + {
> + if ((*bitmap & bitmask) == 0)
> + count++;
> +
> + bitmask <<= 1;
> + if (bitmask == 0x100)
> + {
> + bitmap++;
> + bitmask = 1;

For brevity and example sake it'd probably be better to just use the
normal iterator, unless there's a serious speed difference?

In the unit test, I'd personally prefer just building a table with the
test cases and the expected NULL/NOT NULL results, at least for all the
calls that would fit that paradigm. That should significantly reduce the
size of the test. Not a huge deal though...

Also, I don't think anything is testing multiples of whatever value...
how 'bout change the generate_series CASE statement to >40 instead of <>40?
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-04 04:23:56
Message-ID: CAFj8pRBkMU=DNdBamyeKqVeydJMhGOmL0N1q-aEfHqbd_JPkwA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

2016-01-03 22:49 GMT+01:00 Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>:

> On 1/3/16 2:37 PM, Pavel Stehule wrote:
>
>> + /* num_nulls(VARIADIC NULL) is defined as NULL */
>> + if (PG_ARGISNULL(0))
>> + return false;
>>
>
> Could you add to the comment explaining why that's the desired behavior?
>

This case should be different than num_nulls(VARIADIC ARRAY[..]) - this
situation is really equivalent of missing data and NULL is correct answer.
It should not be too clean in num_nulls, but when it is cleaner for
num_notnulls. And more, it is consistent with other variadic functions in
Postgres: see concat_internal and text_format.

>
> + /*
>> + * Non-null argument had better be an array. We assume
>> that any call
>> + * context that could let get_fn_expr_variadic return
>> true will have
>> + * checked that a VARIADIC-labeled parameter actually is
>> an array. So
>> + * it should be okay to just Assert that it's an array
>> rather than
>> + * doing a full-fledged error check.
>> + */
>> +
>> Assert(OidIsValid(get_base_element_type(get_fn_expr_argtype(fcinfo->flinfo,
>> 0))));
>>
>
> Erm... is that really the way to verify that what you have is an array?
> ISTM there should be a macro for that somewhere...
>

really, it is. It is used more time. Although I am not against some macro,
I don't think so it is necessary. The macro should not be too shorter than
this text.

>
> + /* OK, safe to fetch the array value */
>> + arr = PG_GETARG_ARRAYTYPE_P(0);
>> +
>> + ndims = ARR_NDIM(arr);
>> + dims = ARR_DIMS(arr);
>> + nitems = ArrayGetNItems(ndims, dims);
>> +
>> + bitmap = ARR_NULLBITMAP(arr);
>> + if (bitmap)
>> + {
>> + bitmask = 1;
>> +
>> + for (i = 0; i < nitems; i++)
>> + {
>> + if ((*bitmap & bitmask) == 0)
>> + count++;
>> +
>> + bitmask <<= 1;
>> + if (bitmask == 0x100)
>> + {
>> + bitmap++;
>> + bitmask = 1;
>>
>
> For brevity and example sake it'd probably be better to just use the
> normal iterator, unless there's a serious speed difference?
>

The iterator does some memory allocations and some access to type cache.
Almost all work of iterator is useless for this case. This code is
developed by Marko, but I agree with this design. Using the iterator is big
gun for this case. I didn't any performance checks, but it should be
measurable for any varlena arrays.

Regards

Pavel

> In the unit test, I'd personally prefer just building a table with the
> test cases and the expected NULL/NOT NULL results, at least for all the
> calls that would fit that paradigm. That should significantly reduce the
> size of the test. Not a huge deal though...
>
> Also, I don't think anything is testing multiples of whatever value... how
> 'bout change the generate_series CASE statement to >40 instead of <>40?
> --
> Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
> Experts in Analytics, Data Architecture and PostgreSQL
> Data in Trouble? Get it in Treble! http://BlueTreble.com
>


From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-04 04:49:23
Message-ID: 5689F9D3.9020703@BlueTreble.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 1/3/16 10:23 PM, Pavel Stehule wrote:
> Hi
>
> 2016-01-03 22:49 GMT+01:00 Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com
> <mailto:Jim(dot)Nasby(at)bluetreble(dot)com>>:
>
> On 1/3/16 2:37 PM, Pavel Stehule wrote:
>
> + /* num_nulls(VARIADIC NULL) is defined as NULL */
> + if (PG_ARGISNULL(0))
> + return false;
>
>
> Could you add to the comment explaining why that's the desired behavior?
>
>
> This case should be different than num_nulls(VARIADIC ARRAY[..]) - this
> situation is really equivalent of missing data and NULL is correct
> answer. It should not be too clean in num_nulls, but when it is cleaner
> for num_notnulls. And more, it is consistent with other variadic
> functions in Postgres: see concat_internal and text_format.

Makes sense, now that you explain it. Which is why I'm thinking it'd be
good to add that explanation to the comment... ;)

> Assert(OidIsValid(get_base_element_type(get_fn_expr_argtype(fcinfo->flinfo, 0))));
>
>
> Erm... is that really the way to verify that what you have is an
> array? ISTM there should be a macro for that somewhere...
>
>
> really, it is. It is used more time. Although I am not against some
> macro, I don't think so it is necessary. The macro should not be too
> shorter than this text.

Well, if there's other stuff doing that... would be nice to refactor
that though.

> For brevity and example sake it'd probably be better to just use the
> normal iterator, unless there's a serious speed difference?
>
>
> The iterator does some memory allocations and some access to type cache.
> Almost all work of iterator is useless for this case. This code is
> developed by Marko, but I agree with this design. Using the iterator is
> big gun for this case. I didn't any performance checks, but it should be
> measurable for any varlena arrays.

Makes sense then.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-04 08:24:46
Message-ID: CAFj8pRCXeymm+xfgfCcyfx+zPypxJ1nxxcRuaAL=NetYD3v3xg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

2016-01-04 5:49 GMT+01:00 Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>:

> On 1/3/16 10:23 PM, Pavel Stehule wrote:
>
>> Hi
>>
>> 2016-01-03 22:49 GMT+01:00 Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com
>> <mailto:Jim(dot)Nasby(at)bluetreble(dot)com>>:
>>
>> On 1/3/16 2:37 PM, Pavel Stehule wrote:
>>
>> + /* num_nulls(VARIADIC NULL) is defined as NULL */
>> + if (PG_ARGISNULL(0))
>> + return false;
>>
>>
>> Could you add to the comment explaining why that's the desired
>> behavior?
>>
>>
>> This case should be different than num_nulls(VARIADIC ARRAY[..]) - this
>> situation is really equivalent of missing data and NULL is correct
>> answer. It should not be too clean in num_nulls, but when it is cleaner
>> for num_notnulls. And more, it is consistent with other variadic
>> functions in Postgres: see concat_internal and text_format.
>>
>
> Makes sense, now that you explain it. Which is why I'm thinking it'd be
> good to add that explanation to the comment... ;)
>
>
>> Assert(OidIsValid(get_base_element_type(get_fn_expr_argtype(fcinfo->flinfo,
>> 0))));
>>
>>
>> Erm... is that really the way to verify that what you have is an
>> array? ISTM there should be a macro for that somewhere...
>>
>>
>> really, it is. It is used more time. Although I am not against some
>> macro, I don't think so it is necessary. The macro should not be too
>> shorter than this text.
>>
>
> Well, if there's other stuff doing that... would be nice to refactor that
> though.
>
> For brevity and example sake it'd probably be better to just use the
>> normal iterator, unless there's a serious speed difference?
>>
>>
>> The iterator does some memory allocations and some access to type cache.
>> Almost all work of iterator is useless for this case. This code is
>> developed by Marko, but I agree with this design. Using the iterator is
>> big gun for this case. I didn't any performance checks, but it should be
>> measurable for any varlena arrays.
>>
>
> Makes sense then.
>
>
+ enhanced comment
+ rewritten regress tests

Regards

Pavel

> --
> Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
> Experts in Analytics, Data Architecture and PostgreSQL
> Data in Trouble? Get it in Treble! http://BlueTreble.com
>

Attachment Content-Type Size
num_nulls_v5.patch text/x-patch 12.9 KB

From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-12 16:27:07
Message-ID: 5695295B.1030905@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 03/01/16 22:49, Jim Nasby wrote:
> In the unit test, I'd personally prefer just building a table with the
> test cases and the expected NULL/NOT NULL results, at least for all the
> calls that would fit that paradigm. That should significantly reduce the
> size of the test. Not a huge deal though...

I don't really see the point. "The size of the test" doesn't seem like
a worthwhile optimization target, unless the test scripts are somehow
really unnecessarily large.

Further, if you were developing code related to this, previously you
could just copy-paste the defective test case in order to easily
reproduce a problem. But now suddenly you need a ton of different setup.

I don't expect to really have a say in this, but I think the tests are
now worse than they were before.

.m


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-17 07:43:56
Message-ID: CAFj8pRCvng_QriZyrOC4i5P-LXGRW22XQJB0=Ee8XmaeLgQdxQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

2016-01-12 17:27 GMT+01:00 Marko Tiikkaja <marko(at)joh(dot)to>:

> On 03/01/16 22:49, Jim Nasby wrote:
>
>> In the unit test, I'd personally prefer just building a table with the
>> test cases and the expected NULL/NOT NULL results, at least for all the
>> calls that would fit that paradigm. That should significantly reduce the
>> size of the test. Not a huge deal though...
>>
>
> I don't really see the point. "The size of the test" doesn't seem like a
> worthwhile optimization target, unless the test scripts are somehow really
> unnecessarily large.
>
> Further, if you were developing code related to this, previously you could
> just copy-paste the defective test case in order to easily reproduce a
> problem. But now suddenly you need a ton of different setup.
>
> I don't expect to really have a say in this, but I think the tests are now
> worse than they were before.
>

the form of regress tests is not pretty significant issue. Jim's design is
little bit transparent, Marko's is maybe little bit practical. Both has
sense from my opinion, and any hasn't significant advantage against other.

Regards

Pavel

>
>
> .m
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-21 19:48:28
Message-ID: CAFj8pRAwqta232s-WjMT636Zm8ZdxOJqPxKQZKUJayfdXCeUog@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

2016-01-17 8:43 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

>
>
> 2016-01-12 17:27 GMT+01:00 Marko Tiikkaja <marko(at)joh(dot)to>:
>
>> On 03/01/16 22:49, Jim Nasby wrote:
>>
>>> In the unit test, I'd personally prefer just building a table with the
>>> test cases and the expected NULL/NOT NULL results, at least for all the
>>> calls that would fit that paradigm. That should significantly reduce the
>>> size of the test. Not a huge deal though...
>>>
>>
>> I don't really see the point. "The size of the test" doesn't seem like a
>> worthwhile optimization target, unless the test scripts are somehow really
>> unnecessarily large.
>>
>> Further, if you were developing code related to this, previously you
>> could just copy-paste the defective test case in order to easily reproduce
>> a problem. But now suddenly you need a ton of different setup.
>>
>> I don't expect to really have a say in this, but I think the tests are
>> now worse than they were before.
>>
>
> the form of regress tests is not pretty significant issue. Jim's design is
> little bit transparent, Marko's is maybe little bit practical. Both has
> sense from my opinion, and any hasn't significant advantage against other.
>

any possible agreement, how these tests should be designed?

simple patch, simple regress tests, so there are no reason for long waiting.

Regards

Pavel

> Regards
>
> Pavel
>
>
>>
>>
>> .m
>>
>
>


From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-22 12:34:48
Message-ID: 56A221E8.4000602@BlueTreble.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 1/21/16 1:48 PM, Pavel Stehule wrote:
> the form of regress tests is not pretty significant issue. Jim's
> design is little bit transparent, Marko's is maybe little bit
> practical. Both has sense from my opinion, and any hasn't
> significant advantage against other.
>
>
> any possible agreement, how these tests should be designed?
>
> simple patch, simple regress tests, so there are no reason for long waiting.

I don't really see how individual tests are more practical (you can
still cut and paste a table...), but since there's no strong consensus
either way I'd say it's up to you as author.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-25 18:57:21
Message-ID: CAFj8pRA1pUSYOE+Nrcixw6PJ8Gss7cvWhh84pcwHnRafdXGoAg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

2016-01-22 13:34 GMT+01:00 Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>:

> On 1/21/16 1:48 PM, Pavel Stehule wrote:
>
>> the form of regress tests is not pretty significant issue. Jim's
>> design is little bit transparent, Marko's is maybe little bit
>> practical. Both has sense from my opinion, and any hasn't
>> significant advantage against other.
>>
>>
>> any possible agreement, how these tests should be designed?
>>
>> simple patch, simple regress tests, so there are no reason for long
>> waiting.
>>
>
> I don't really see how individual tests are more practical (you can still
> cut and paste a table...), but since there's no strong consensus either way
> I'd say it's up to you as author.

Marco is a author of this patch, so - Marco, please, send final version of
this patch

Regards

Pavel

>
> --
> Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
> Experts in Analytics, Data Architecture and PostgreSQL
> Data in Trouble? Get it in Treble! http://BlueTreble.com
>


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-26 10:42:33
Message-ID: 56A74D99.3030905@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 25/01/16 19:57, Pavel Stehule wrote:
> Marco is a author of this patch, so - Marco, please, send final version of
> this patch

I don't really care about the tests. Can we not use the v5 patch
already in the thread? As far as I could tell there were no reviewer's
comments on it anymore.

.m


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-01-26 11:20:11
Message-ID: CAFj8pRDg2YKY++cPNYDRdUgt4ppJ7d=WFJ_uPHYw5DbxzEPK=g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

2016-01-26 11:42 GMT+01:00 Marko Tiikkaja <marko(at)joh(dot)to>:

> On 25/01/16 19:57, Pavel Stehule wrote:
>
>> Marco is a author of this patch, so - Marco, please, send final version of
>> this patch
>>
>
> I don't really care about the tests. Can we not use the v5 patch already
> in the thread? As far as I could tell there were no reviewer's comments on
> it anymore.
>

It was not my request, but I counted Jim as second reviewer.

So, I'll return back original regress tests. If I remember well, there are
no any other objection, so I'll mark this version as ready for commiter.

1. the patch is rebased against master
2. now warning or errors due compilation
3. all tests are passed
4. the code is simple without side effects and possible negative
performance impacts
6. there was not objections against the design
7. the iteration over null bitmap is used more times in our code, but this
is new special case. We don't need iterate over array elements, so we
should not to use existing array iterators.

I'll mark this patch as ready for commiter

Regards

Pavel

>
> .m
>

Attachment Content-Type Size
num_nulls_v6.patch text/x-patch 13.2 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-02-04 22:33:08
Message-ID: 5364.1454625188@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> [ num_nulls_v6.patch ]

I started looking through this. It seems generally okay, but I'm not
very pleased with the function name "num_notnulls". I think it would
be better as "num_nonnulls", as I see Oleksandr suggested already.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-02-05 04:06:35
Message-ID: 19265.1454645195@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

I wrote:
> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
>> [ num_nulls_v6.patch ]

> I started looking through this. It seems generally okay, but I'm not
> very pleased with the function name "num_notnulls". I think it would
> be better as "num_nonnulls", as I see Oleksandr suggested already.

Not hearing any complaints, I pushed it with that change and some other
cosmetic adjustments.

regards, tom lane


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-02-05 04:08:38
Message-ID: CAFj8pRDEZ=gW0gVi2pmZwtbo_Ld4QOjCRKRr0ZMuRjHD9wHy2A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Dne 5. 2. 2016 1:33 napsal uživatel "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>
> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> > [ num_nulls_v6.patch ]
>
> I started looking through this. It seems generally okay, but I'm not
> very pleased with the function name "num_notnulls". I think it would
> be better as "num_nonnulls", as I see Oleksandr suggested already.

I have no problem with it.

Regards

Pavel
>
> regards, tom lane


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-02-05 10:12:50
Message-ID: 56B475A2.4020606@joh.to
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 2016-02-05 05:06, Tom Lane wrote:
> I wrote:
>> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
>>> [ num_nulls_v6.patch ]
>
>> I started looking through this. It seems generally okay, but I'm not
>> very pleased with the function name "num_notnulls". I think it would
>> be better as "num_nonnulls", as I see Oleksandr suggested already.
>
> Not hearing any complaints, I pushed it with that change and some other
> cosmetic adjustments.

Thanks Tom and Pavel and everyone who provided feedback.

.m


From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-02-08 20:22:51
Message-ID: CAEepm=1FArDLof+Btsq+PAgUaAo_j1fmpaCX7reZ4yBshHQqFQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Feb 5, 2016 at 5:06 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> I wrote:
>> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
>>> [ num_nulls_v6.patch ]
>
>> I started looking through this. It seems generally okay, but I'm not
>> very pleased with the function name "num_notnulls". I think it would
>> be better as "num_nonnulls", as I see Oleksandr suggested already.
>
> Not hearing any complaints, I pushed it with that change and some other
> cosmetic adjustments.

Would num_values be a better name than num_nonnulls?

--
Thomas Munro
http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-02-08 20:26:19
Message-ID: 22514.1454963179@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> writes:
> Would num_values be a better name than num_nonnulls?

If "value" is a term that excludes null values, it's news to me.

regards, tom lane


From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count_nulls(VARIADIC "any")
Date: 2016-02-08 21:25:37
Message-ID: CAEepm=0uhc+oJSZ7g_WdvcCfDxv4MzLKM2cK=N8E1amLowzD4Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 9, 2016 at 9:26 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> writes:
>> Would num_values be a better name than num_nonnulls?
>
> If "value" is a term that excludes null values, it's news to me.

Ah, right, I was thinking of null as the absence of a value. But in
fact it is a special value that indicates the absence of a "data
value". And num_data_values doesn't sound great.

--
Thomas Munro
http://www.enterprisedb.com