pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@commandprompt.com>
To: Matthijs Bomhoff <matthijs@quarantainenet.nl>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: Bug with plpgsql, temp tables and TOAST?
Date: Wed, 29 Jun 2011 12:03:20 -0400
Message-ID: <1309363131-sup-6268@alvh.no-ip.org> (raw)
In-Reply-To: <0C41674C-FA02-4768-9E1B-548E568875BD@quarantainenet.nl>
References: <0C41674C-FA02-4768-9E1B-548E568875BD@quarantainenet.nl>

Excerpts from Matthijs Bomhoff's message of mié jun 29 07:40:07 -0400 2011:

> CREATE OR REPLACE FUNCTION foo(size_ INTEGER) RETURNS TEXT AS $EOF$
> DECLARE
>   acc_ TEXT := '';
>   cur_rec_ RECORD;
> BEGIN
>   EXECUTE 'CREATE TEMPORARY TABLE foo_tab(blob TEXT NOT NULL)';
> 
>   -- Construct a string with random characters to prevent compression (with high probability)
>   LOOP
>     EXIT WHEN length(acc_) >= size_;
>     acc_ := acc_ || chr(ceil(random()*64)::integer + 32);
>   END LOOP;
> 
>   EXECUTE 'INSERT INTO foo_tab(blob) values (' || quote_literal(acc_) || ')';
>   EXECUTE 'SELECT * FROM foo_tab LIMIT 1' INTO cur_rec_;
>   EXECUTE 'DROP TABLE foo_tab';
>   RETURN cur_rec_.blob;
> END
> $EOF$ LANGUAGE plpgsql;

Hmm, so what's happening here, I think, is that the value is getting
assigned to the record variable without detoasting.  I guess we should
detoast the value prior to assigning it, but it seems to me that that
would have a large performance penalty for other cases in which the
toast table is not dropped; in fact, you can even imagine some cases in
which the toasted value is not even accessed, so getting to the point of
detoasting it would be a severe penalization.

-- 
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support



view thread (5+ messages)  latest in thread

Message-ID: <1309363131-sup-6268@alvh.no-ip.org>
Permalink:  ../1309363131-sup-6268@alvh.no-ip.org/
Also on:    postgresql.org/message-id/1309363131-sup-6268@alvh.no-ip.org

 · 

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: alvherre@commandprompt.com, matthijs@quarantainenet.nl
  Subject: Re: Bug with plpgsql, temp tables and TOAST?
  In-Reply-To: <1309363131-sup-6268@alvh.no-ip.org>
  References: <0C41674C-FA02-4768-9E1B-548E568875BD@quarantainenet.nl> <1309363131-sup-6268@alvh.no-ip.org>

* 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