Re: contrib/intarray vs empty arrays - Mailing list pgsql-hackers

From Teodor Sigaev
Subject Re: contrib/intarray vs empty arrays
Date
Msg-id 49DDF5F3.8030700@sigaev.ru
Whole thread Raw
In response to contrib/intarray vs empty arrays  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: contrib/intarray vs empty arrays  (Greg Stark <stark@enterprisedb.com>)
List pgsql-hackers
> While I was testing this I realized that I wasn't getting quite the same
> answers :-(.  In particular, it seems that the core operators consider
> an empty array to be contained in anything else, while intarray will
> only return true for two nonempty arrays.

Urgh. We (with Oleg) digged a bit around that.

8.1 and earlier versions (contrib/intarray) assume that empty array neither 
contained in nor overlap with any array.
_int_contains(PG_FUNCTION_ARGS)
{
....    if (ARRISVOID(a) || ARRISVOID(b))        return FALSE;

_int_overlap(PG_FUNCTION_ARGS)
{
....    if (ARRISVOID(a) || ARRISVOID(b))        return FALSE;

However, that versions have an *implementation* bug: ARRISVOID returns false for 
empty array :(. 8.2 and later versions have built-in assumption that empty array 
is contained in any array, although the bug in contrib/intarray was fixed while 
defending intarray from nulls in array: 
http://archives.postgresql.org/pgsql-committers/2005-11/msg00420.php
But I don't remember any complaints about changed behaviour of contains operator.

On other hand, geometrical containment operator guarantees that arguments will 
overlaps, whereas  this is not true for arrays - empty array is contained in any 
array but doesn't overlap.

Since results of operations with empty array are not documented and we didn't 
find definition of "contains" and  "overlap" in the documentation, we suggest
following strict definitions:
contains - all elements of second array are contained in the first one.
Empty array has no element, so it can't be contained.
overlap - there is at least one common element in both arrays. Empty array has 
no element, so it can't overlap.

Then we need to fix:
- ARRISVOID in contrib/intarray in 8.1 and later
- contains/contained in 8.2 and later

> From what I understand of GIN's internal workings, this is unfixable
Yes :(

> [ pokes around ... ]  Oh dear, it doesn't work with intarray's
> GIST opclasses either.
That's easy fixable

-- 
Teodor Sigaev                                   E-mail: teodor@sigaev.ru
  WWW: http://www.sigaev.ru/
 


pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: Translation conventions
Next
From: Greg Stark
Date:
Subject: Re: contrib/intarray vs empty arrays