Re: [BUG] plpgsql RETURN QUERY with toasted fields -vs- DROP/TRUNCATE - Mailing list pgsql-bugs

From Tom Lane
Subject Re: [BUG] plpgsql RETURN QUERY with toasted fields -vs- DROP/TRUNCATE
Date
Msg-id 3568911.1598723239@sss.pgh.pa.us
Whole thread Raw
In response to [BUG] plpgsql RETURN QUERY with toasted fields -vs- DROP/TRUNCATE  (Jehan-Guillaume de Rorthais <jgdr@dalibo.com>)
Responses Re: [BUG] plpgsql RETURN QUERY with toasted fields -vs- DROP/TRUNCATE
List pgsql-bugs
Jehan-Guillaume de Rorthais <jgdr@dalibo.com> writes:
> We discovered a bug in plpgsql.
> When using RETURN QUERY on a relation with some toasted values and when this
> relaiton is later dropped or truncated, an error is raised at the end of the
> function.

This isn't particularly RETURN QUERY's fault; there are any number of ways
to produce the same sort of error.  I reproduced it with

        declare r record;
        ...
        for r in SELECT str FROM temp_rel loop
          return next r.str;
        end loop;

as well as

        declare r record;
        ...
        SELECT str INTO r FROM temp_rel LIMIT 1;
    
        DROP TABLE temp_rel;
        --TRUNCATE TABLE temp_rel;

        return r.str;

I guess we could forcibly detoast values in enough places to close all the
gaps, but the performance costs might be annoying.  I think a case can
definitely be made for saying "don't do that".

(Another idea, perhaps, might be to detoast only in volatile functions,
reasoning that a nonvolatile one can't drop the table.)

            regards, tom lane



pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #16594: DROP INDEX CONCURRENTLY fails on partitioned table with a non helpful error message.
Next
From: Alexander Korotkov
Date:
Subject: Re: BUG #16592: websearch_to_tsquery() returns queries that don't result in expected matches