pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
unexpected query failure: ERROR: GIN indexes do not support whole-index scans
3+ messages / 2 participants
[nested] [flat]

* unexpected query failure: ERROR: GIN indexes do not support whole-index scans
@ 2010-10-18 20:59  Jon Nelson <jnelson+pgsql@jamponi.net>
  0 siblings, 1 reply; 3+ messages in thread

From: Jon Nelson @ 2010-10-18 20:59 UTC (permalink / raw)
  To: pgsql-performance

I have a table with an array column.
I added a GIN index to the array:

CREATE INDEX foo_idx ON t USING GIN (alternatecodes) WHERE
alternatecodes IS NOT NULL;

That's all well and good.
However, some queries started failing and I was able to reproduce the
behavior in psql!

SELECT * FROM t WHERE alternatecodes IS NOT NULL;
returns:
ERROR:  GIN indexes do not support whole-index scans

Whaaa?  Adding an *index* makes my /queries/ stop working? How can this be?
This really violated my principle of least surprise. If GIN indexes
don't support whole-index scans, fine, don't use them, but don't make
a perfectly valid query fail because of it.

This seems like a bug. Is it?

PostgreSQL version:

 PostgreSQL 8.4.5 on x86_64-redhat-linux-gnu, compiled by GCC gcc
(GCC) 4.1.2 20080704 (Red Hat 4.1.2-48), 64-bit


-- 
Jon



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: unexpected query failure: ERROR: GIN indexes do not support whole-index scans
@ 2010-10-18 23:01  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Jon Nelson <jnelson+pgsql@jamponi.net>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2010-10-18 23:01 UTC (permalink / raw)
  To: Jon Nelson <jnelson+pgsql@jamponi.net>; +Cc: pgsql-performance

Jon Nelson <jnelson+pgsql@jamponi.net> writes:
> CREATE INDEX foo_idx ON t USING GIN (alternatecodes) WHERE
> alternatecodes IS NOT NULL;
> SELECT * FROM t WHERE alternatecodes IS NOT NULL;
> ERROR:  GIN indexes do not support whole-index scans

Yep, this is a known issue.  It's going to take major surgery on GIN to
fix it, so don't hold your breath.  In the particular case, what good do
you think the WHERE clause is doing anyway?  GIN won't index nulls at
all ... which indeed is an aspect of the underlying issue --- see recent
discussions, eg here:
http://archives.postgresql.org/pgsql-hackers/2010-10/msg00521.php

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: unexpected query failure: ERROR: GIN indexes do not support whole-index scans
@ 2010-10-19 02:47  Jon Nelson <jnelson+pgsql@jamponi.net>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Jon Nelson @ 2010-10-19 02:47 UTC (permalink / raw)
  To: ; +Cc: pgsql-performance

On Mon, Oct 18, 2010 at 6:01 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Jon Nelson <jnelson+pgsql@jamponi.net> writes:
>> CREATE INDEX foo_idx ON t USING GIN (alternatecodes) WHERE
>> alternatecodes IS NOT NULL;
>> SELECT * FROM t WHERE alternatecodes IS NOT NULL;
>> ERROR:  GIN indexes do not support whole-index scans
>
> Yep, this is a known issue.  It's going to take major surgery on GIN to
> fix it, so don't hold your breath.  In the particular case, what good do
> you think the WHERE clause is doing anyway?  GIN won't index nulls at
> all ... which indeed is an aspect of the underlying issue --- see recent
> discussions, eg here:
> http://archives.postgresql.org/pgsql-hackers/2010-10/msg00521.php

OK, so GIN doesn't index NULLs. I guess the "IS NOT NULL" part comes
about as a habit - that particular column is fairly sparse. However,
I'm honestly quite surprised at two things:

1. if GIN indexes ignore NULLs, then either it should grump when one
specifics "WHERE ... IS NOT NULL" or it should be treated as a no-op

2. (and this is by far the more surprising) that the /presence/ of an
INDEX can *break* a SELECT. It's not that the engine ignores the index
- that would be reasonable - but that I can't issue a SELECT with a
WHERE statement that matches the same as the index.

However, I see that this also surprised Josh Berkus, and not that long
ago (11 days!), so I'll just shush.

Thanks!



-- 
Jon



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2010-10-19 02:47 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-10-18 20:59 unexpected query failure: ERROR: GIN indexes do not support whole-index scans Jon Nelson <jnelson+pgsql@jamponi.net>
2010-10-18 23:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2010-10-19 02:47   ` Jon Nelson <jnelson+pgsql@jamponi.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox