pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: cpro29a@gmail.com
Cc: pgsql-bugs@postgresql.org
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Subject: Re: BUG #13327: Error on insert (gist index)
Date: Thu, 21 May 2015 14:57:52 -0400
Message-ID: <32487.1432234672@sss.pgh.pa.us> (raw)
In-Reply-To: <30649.1432230561@sss.pgh.pa.us>
References: <20150521071448.26511.8665@wrigleys.postgresql.org>
	<30649.1432230561@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

I wrote:
> cpro29a@gmail.com writes:
>> create table test_gist(id serial primary key, a1 int[],a2 int[], a3 int[],
>> a4 int[], a5 int[]);
>> create index test_gist_i on test_gist using gist (a1,a2,a3,a4,a5);

>> --Simple random array generator
>> create or replace function rnd_arr(p_len int) returns int[]
>> as $$
>> select array_agg(val)
>> from (select trunc(random()*1000.0)::int val
>> from generate_series(1,trunc(random()*p_len*1.0)::int+1)
>> ) v;
>> $$ language sql;

>> --##THIS FAILS:
>> insert into test_gist(a1,a2,a3,a4,a5)
>> select rnd_arr(10),rnd_arr(10),rnd_arr(10),rnd_arr(10),rnd_arr(10)
>> from generate_series(1,100000);
>> --##WITH MESSAGE:
>> --ERROR:  failed to add item to index page in "test_gist_i"

> I can reproduce this on HEAD (after installing contrib/intarray).

On closer inspection, the answer is "you should be using gist__intbig_ops".
gist__intbig_ops uses a different representation that can deal with more
distinct array entries than the default gist_int_ops opclass can.

The reason for the failure is that the index entries have gotten up to
over 4K apiece, so that splitting does not help (or maybe that GIST
thinks it should be able to put two entries in a page and it can't).

It'd be nice if the error thrown was a little clearer, but I don't think
there is anything we can or should do to make this example actually succeed.

Note that gist_int_ops' g_int_compress function does actually contain a
check that warns you once you've got more than 200 distinct values in an
index item.  Unfortunately, this example is trying to cram five arrays
into each index tuple, so the total tuple size exceeds what GIST can cope
with before that check fires for any one array value.  It doesn't look to
me like g_int_compress has any way to know how many index columns there
are, else maybe it could adjust its threshold for complaining.

It might be reasonable for the core GIST code to emit some complaint about
index tuple size rather than the very opaque "failed to add item" message.
Not sure exactly what test is appropriate though.  Should we be limiting
GIST index entries to half a page?

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (4+ messages)  latest in thread

Message-ID: <32487.1432234672@sss.pgh.pa.us>
Permalink:  ../32487.1432234672@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/32487.1432234672@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, cpro29a@gmail.com, hlinnaka@iki.fi
  Subject: Re: BUG #13327: Error on insert (gist index)
  In-Reply-To: <32487.1432234672@sss.pgh.pa.us>
  References: <20150521071448.26511.8665@wrigleys.postgresql.org> <30649.1432230561@sss.pgh.pa.us> <32487.1432234672@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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