Re: cardinality()

Lists: pgsql-hackers
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: cardinality()
Date: 2009-03-01 00:52:05
Message-ID: 49A9DC35.40304@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


We seem to have acquired a cardinality() function with almost no
discussion, and it has semantics that are a bit surprising to me. I
should have thought cardinality(array) would be the total number of
elements in the array. Instead, it seems it is a synonym for
array_length(array,1). Is that *really* what the standard says?

cheers

andrew


From: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cardinality()
Date: 2009-03-01 11:22:44
Message-ID: 625B8158-CCE7-4D84-ACE1-6D1964145018@pointblue.com.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 1 Mar 2009, at 00:52, Andrew Dunstan wrote:

>
> We seem to have acquired a cardinality() function with almost no
> discussion, and it has semantics that are a bit surprising to me. I
> should have thought cardinality(array) would be the total number of
> elements in the array. Instead, it seems it is a synonym for
> array_length(array,1). Is that *really* what the standard says?

any difference between array_upper(array,1), and cardinality ?
Standart just says something like:

cardinality (a collection):
- The number of elements in that collection.
- Those elements need not necessarily have distinct values.
- The objects to which this concept applies includes tables and the
values of collection types.


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cardinality()
Date: 2009-03-01 15:30:46
Message-ID: 49AAAA26.3080901@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Grzegorz Jaskiewicz wrote:
>
> On 1 Mar 2009, at 00:52, Andrew Dunstan wrote:
>
>>
>> We seem to have acquired a cardinality() function with almost no
>> discussion, and it has semantics that are a bit surprising to me. I
>> should have thought cardinality(array) would be the total number of
>> elements in the array. Instead, it seems it is a synonym for
>> array_length(array,1). Is that *really* what the standard says?
>
> any difference between array_upper(array,1), and cardinality ?
> Standart just says something like:
>
> cardinality (a collection):
> - The number of elements in that collection.
> - Those elements need not necessarily have distinct values.
> - The objects to which this concept applies includes tables and the
> values of collection types.
>

Well, I think that's a definition of the term as used in the standard,
rather than of a function. But in any case, I think it goes in the right
direction, and the semantics of our new function (as well as the docs)
are misleading.

I'm also a bit concerned that I could not find any real discussion of
this new function at all on this list, so our processes seem to have
slipped a bit.

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cardinality()
Date: 2009-03-01 16:49:20
Message-ID: 12505.1235926160@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> Grzegorz Jaskiewicz wrote:
>> On 1 Mar 2009, at 00:52, Andrew Dunstan wrote:
>>> We seem to have acquired a cardinality() function with almost no
>>> discussion, and it has semantics that are a bit surprising to me. I
>>> should have thought cardinality(array) would be the total number of
>.> elements in the array. Instead, it seems it is a synonym for
>>> array_length(array,1). Is that *really* what the standard says?

>> Standart just says something like:
>> cardinality (a collection):
>> - The number of elements in that collection.

The standard doesn't have multi-dimensional arrays, so it's entirely
possible that somewhere in it there is wording that makes cardinality()
equivalent to the length of the first dimension. But I concur with
Andrew that this is flat wrong when extended to m-d arrays.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>, Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cardinality()
Date: 2009-03-01 17:40:16
Message-ID: 13073.1235929216@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I wrote:
> The standard doesn't have multi-dimensional arrays, so it's entirely
> possible that somewhere in it there is wording that makes cardinality()
> equivalent to the length of the first dimension. But I concur with
> Andrew that this is flat wrong when extended to m-d arrays.

I poked around in the SQL:2008 draft a bit. AFAICT the most precise
statement about cardinality() is in 6.27 <numeric value function>:

<cardinality expression> ::=
CARDINALITY<left paren> <collection value expression> <right paren>

7) The result of <cardinality expression> is the number of elements of
the result of the <collection value expression>.

Now the standard is only considering 1-D arrays, but I fail to see any
way that it could be argued that the appropriate reading of "number of
elements" for a multi-D array is the length of the first dimension.
So I think Andrew is right and we need to fix our implementation of
cardinality() while we still can.

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: Andrew Dunstan <andrew(at)dunslane(dot)net>, Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cardinality()
Date: 2009-03-01 17:44:38
Message-ID: 162867790903010944r4b410d50le92cc995203d8f23@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2009/3/1 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> I wrote:
>> The standard doesn't have multi-dimensional arrays, so it's entirely
>> possible that somewhere in it there is wording that makes cardinality()
>> equivalent to the length of the first dimension.  But I concur with
>> Andrew that this is flat wrong when extended to m-d arrays.
>
> I poked around in the SQL:2008 draft a bit.  AFAICT the most precise
> statement about cardinality() is in 6.27 <numeric value function>:
>
>  <cardinality expression> ::=
>        CARDINALITY<left paren> <collection value expression> <right paren>
>
>  7) The result of <cardinality expression> is the number of elements of
>     the result of the <collection value expression>.
>
> Now the standard is only considering 1-D arrays, but I fail to see any
> way that it could be argued that the appropriate reading of "number of
> elements" for a multi-D array is the length of the first dimension.
> So I think Andrew is right and we need to fix our implementation of
> cardinality() while we still can.

₊1

regards
Pavel Stehule

>
>                        regards, tom lane
>
> --
> 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: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cardinality()
Date: 2009-03-01 18:23:19
Message-ID: 20090301095134.X96146@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 1 Mar 2009, Tom Lane wrote:

> I wrote:
> > The standard doesn't have multi-dimensional arrays, so it's entirely
> > possible that somewhere in it there is wording that makes cardinality()
> > equivalent to the length of the first dimension. But I concur with
> > Andrew that this is flat wrong when extended to m-d arrays.
>
> I poked around in the SQL:2008 draft a bit. AFAICT the most precise
> statement about cardinality() is in 6.27 <numeric value function>:
>
> <cardinality expression> ::=
> CARDINALITY<left paren> <collection value expression> <right paren>
>
> 7) The result of <cardinality expression> is the number of elements of
> the result of the <collection value expression>.
>
> Now the standard is only considering 1-D arrays, but I fail to see any
> way that it could be argued that the appropriate reading of "number of
> elements" for a multi-D array is the length of the first dimension.

Does the standard allow you to make arrays of arrays, for example with
something like ARRAY[ARRAY[1,2], ARRAY[3,4]]? If so, it might be possible
that cardinality(<that expression>) would be returning the number of
arrays in the outer array.


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Subject: Re: cardinality()
Date: 2009-03-01 21:50:02
Message-ID: 200903012350.03474.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sunday 01 March 2009 19:40:16 Tom Lane wrote:
> I wrote:
> > The standard doesn't have multi-dimensional arrays, so it's entirely
> > possible that somewhere in it there is wording that makes cardinality()
> > equivalent to the length of the first dimension. But I concur with
> > Andrew that this is flat wrong when extended to m-d arrays.
>
> I poked around in the SQL:2008 draft a bit. AFAICT the most precise
> statement about cardinality() is in 6.27 <numeric value function>:
>
> <cardinality expression> ::=
> CARDINALITY<left paren> <collection value expression> <right paren>
>
> 7) The result of <cardinality expression> is the number of elements of
> the result of the <collection value expression>.
>
> Now the standard is only considering 1-D arrays,

The standard represents multidimensional arrays as arrays of arrays (like in
C). But the cardinality is only that of the first level array.

The real question here is how we want to consider mapping what the standard
has to what PostgreSQL has, and might have in the future. For example, will
we ever have arrays of arrays as distinct from multidimensional arrays? Will
we support things like array of multiset of array? What would the results be
there?

I think PostgreSQL multidimensional array support and SQL standard
multidimensional array support are pretty well in line leaving aside minor
syntax issues and the major syntax issue that the subscript order is
reversed. So I think there is not much of a need to do much redefining and
reinterpreting, unless someone has a larger and different plan in mind.


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Subject: Re: cardinality()
Date: 2009-03-01 23:37:24
Message-ID: 873adwstl7.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:

> The standard represents multidimensional arrays as arrays of arrays (like in
> C).

Uh, C doesn't represent multidimensional arrays as arrays of arrays so you've
lost me already.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's Slony Replication support!


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Subject: Re: cardinality()
Date: 2009-03-02 00:54:15
Message-ID: 200903020054.n220sFk26931@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Gregory Stark wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>
> > The standard represents multidimensional arrays as arrays of arrays (like in
> > C).
>
> Uh, C doesn't represent multidimensional arrays as arrays of arrays so you've
> lost me already.

I think he meant to say C _can_ represent multidimensional arrays as
arrays of arrays.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +