Re: contrib/intarray vs empty arrays

From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: contrib/intarray vs empty arrays
Date: 2009-04-09 13:19:47
Message-ID: 49DDF5F3.8030700@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2009-04-09 13:29:33 Re: contrib/intarray vs empty arrays
Previous Message Greg Stark 2009-04-09 13:04:32 Re: Translation conventions