Re: GIN overlap vs empty arrays

Lists: pgsql-bugs
From: Jeff <threshar(at)torgo(dot)978(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: GIN overlap vs empty arrays
Date: 2010-03-25 14:54:15
Message-ID: 89D6FDB3-A100-43DA-A88E-0504C5B791C8@torgo.978.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Ran into this and I'm trying to decide if this is functioning as
designed or if this is a bug that should be fixed: (PG 8.4.2)

create table gintest
(
idList int[],
foo text
);

create index gintest_gin_idx on gintest using gin(idList gin__int_ops);

insert into gintest(idlist, foo) values (array[1,2,3], 'bar');

select * from gintest where idList && array[]::int[];

CREATE TABLE
CREATE INDEX
INSERT 0 1
psql:ginproblem.sql:11: ERROR: GIN indexes do not support whole-index
scans

I came across this in a production setting and widdled it down to
this. In a nutshell using overlap with an empty (not null) array
causes this error. Should there be a short circuit to bail on zero-
length input to overlap since you can't overlap with nothing. (if you
pass in a plain null it works fine).

In the production setting it is tickled by the array being produced by
a subselect that uses array_accum to gather a list of ids to pull up.

If this is the proper behavior I'll deal with it (in the end the
result is the same - no rows). Just a bit surprised by it.

--
Jeff Trout <jeff(at)jefftrout(dot)com>
http://www.stuarthamm.net/
http://www.dellsmartexitin.com/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff <threshar(at)threshar(dot)is-a-geek(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: GIN overlap vs empty arrays
Date: 2010-03-25 15:44:19
Message-ID: 18820.1269531859@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Jeff <threshar(at)threshar(dot)is-a-geek(dot)com> writes:
> Ran into this and I'm trying to decide if this is functioning as
> designed or if this is a bug that should be fixed: (PG 8.4.2)

> create table gintest
> (
> idList int[],
> foo text
> );

> create index gintest_gin_idx on gintest using gin(idList gin__int_ops);

> insert into gintest(idlist, foo) values (array[1,2,3], 'bar');

> select * from gintest where idList && array[]::int[];

> CREATE TABLE
> CREATE INDEX
> INSERT 0 1
> psql:ginproblem.sql:11: ERROR: GIN indexes do not support whole-index
> scans

Hmm, that case is supposed to work, in 8.3 and later ... but it doesn't
because of a stupid typo in contrib/intarray.

Index: _int_gin.c
===================================================================
RCS file: /cvsroot/pgsql/contrib/intarray/_int_gin.c,v
retrieving revision 1.10
diff -c -r1.10 _int_gin.c
*** _int_gin.c 11 Jun 2009 14:48:51 -0000 1.10
--- _int_gin.c 25 Mar 2010 15:37:56 -0000
***************
*** 65,71 ****
}
}

! if (nentries == 0)
{
switch (strategy)
{
--- 65,71 ----
}
}

! if (*nentries == 0)
{
switch (strategy)
{

Sometimes C is not the most helpful language to work in.

regards, tom lane


From: Jeff <threshar(at)torgo(dot)978(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeff <threshar(at)threshar(dot)is-a-geek(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: GIN overlap vs empty arrays
Date: 2010-03-25 16:26:39
Message-ID: A6402924-A8EB-4574-B87D-3B0121CDADE2@torgo.978.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


On Mar 25, 2010, at 11:44 AM, Tom Lane wrote:

> Hmm, that case is supposed to work, in 8.3 and later ... but it
> doesn't
> because of a stupid typo in contrib/intarray.
>

This works. -
thanks!

--
Jeff Trout <jeff(at)jefftrout(dot)com>
http://www.stuarthamm.net/
http://www.dellsmartexitin.com/