pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem with accessing TOAST data in stored procedures
3+ messages / 2 participants
[nested] [flat]
* Problem with accessing TOAST data in stored procedures
@ 2021-04-13 14:01 Yura Sokolov <y.sokolov@postgrespro.ru>
0 siblings, 2 replies; 3+ messages in thread
From: Yura Sokolov @ 2021-04-13 14:01 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: andres@anarezel.de
Good day.
There is reproducible bug posted 10 months ago by Konstantin Knizhnik:
https://www.postgresql.org/message-id/flat/5d335911-fb25-60cd-4aa7-a5bd0954aea0%40postgrespro.ru
I'll copy that message here.
> Stored procedure allows to commit/rollback transaction inside its body.
> Unfortunately it is not always correctly handled.
> This fragment of code reports ERROR: no known snapshots
> CREATE TABLE toasted(id serial primary key, data text);
> INSERT INTO toasted(data) VALUES((SELECT string_agg(random()::text,':')
> FROM generate_series(1, 1000)));
> INSERT INTO toasted(data) VALUES((SELECT string_agg(random()::text,':')
> FROM generate_series(1, 1000)));
> DO $$ DECLARE v_r record; BEGIN FOR v_r in SELECT data FROM toasted
> LOOP INSERT INTO toasted(data) VALUES(v_r.data);COMMIT;END LOOP;END;$$;
> I found out that code responsible for persisting portal correctly
> extracts TOAST data.
> But pl_pgsql is using prefetch and so takes records form SPI_tuptable,
> not from stored tuplestore.
> I didn't not find better solution rather than disabling prefetch when
> loop body contains COMMIT or ROLLBACK statements.
> Unfortunately there is no existed walker for plpgsql statements tree,
> so I have to add such walker.
> I hope that it will be useful not only for this case.
> But may be there are some other ways to fix this problem...
> Please notice the following bug report which may be also related:
> https://www.postgresql.org/message-id/flat/20190904105618.j5l6fhyesmprmstf%40alap3.anarazel.de#d93b5...
Original message contains patch as well.
Andres, I've mentioned you've participated in GIST case in bottom link,
and it looks like related,
because COMMIT is called there as well.
Regards,
Yura Sokolov
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Problem with accessing TOAST data in stored procedures
@ 2021-04-13 14:29 Yura Sokolov <y.sokolov@postgrespro.ru>
parent: Yura Sokolov <y.sokolov@postgrespro.ru>
1 sibling, 0 replies; 3+ messages in thread
From: Yura Sokolov @ 2021-04-13 14:29 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: andres@anarazel.de
Yura Sokolov писал 2021-04-13 17:01:
> Good day.
>
> There is reproducible bug posted 10 months ago by Konstantin Knizhnik:
> https://www.postgresql.org/message-id/flat/5d335911-fb25-60cd-4aa7-a5bd0954aea0%40postgrespro.ru
>
> I'll copy that message here.
>
>> Stored procedure allows to commit/rollback transaction inside its
>> body.
>> Unfortunately it is not always correctly handled.
>> This fragment of code reports ERROR: no known snapshots
>
>> CREATE TABLE toasted(id serial primary key, data text);
>> INSERT INTO toasted(data) VALUES((SELECT
>> string_agg(random()::text,':') FROM generate_series(1, 1000)));
>> INSERT INTO toasted(data) VALUES((SELECT
>> string_agg(random()::text,':') FROM generate_series(1, 1000)));
>> DO $$ DECLARE v_r record; BEGIN FOR v_r in SELECT data FROM toasted
>> LOOP INSERT INTO toasted(data) VALUES(v_r.data);COMMIT;END
>> LOOP;END;$$;
>
>> I found out that code responsible for persisting portal correctly
>> extracts TOAST data.
>> But pl_pgsql is using prefetch and so takes records form SPI_tuptable,
>> not from stored tuplestore.
>> I didn't not find better solution rather than disabling prefetch when
>> loop body contains COMMIT or ROLLBACK statements.
>> Unfortunately there is no existed walker for plpgsql statements tree,
>> so I have to add such walker.
>> I hope that it will be useful not only for this case.
>> But may be there are some other ways to fix this problem...
>> Please notice the following bug report which may be also related:
>> https://www.postgresql.org/message-id/flat/20190904105618.j5l6fhyesmprmstf%40alap3.anarazel.de#d93b5...
>
> Original message contains patch as well.
>
> Andres, I've mentioned you've participated in GIST case in bottom
> link, and it looks like related,
> because COMMIT is called there as well.
Remark: I've checked both with 13.2 and master branch.
Regards,
Yura Sokolov
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Problem with accessing TOAST data in stored procedures
@ 2021-04-14 06:01 Michael Paquier <michael@paquier.xyz>
parent: Yura Sokolov <y.sokolov@postgrespro.ru>
1 sibling, 0 replies; 3+ messages in thread
From: Michael Paquier @ 2021-04-14 06:01 UTC (permalink / raw)
To: Yura Sokolov <y.sokolov@postgrespro.ru>; +Cc: pgsql-bugs@lists.postgresql.org, Andres Freund <andres@anarazel.de>
On Tue, Apr 13, 2021 at 05:01:56PM +0300, Yura Sokolov wrote:
> Andres, I've mentioned you've participated in GIST case in bottom link, and
> it looks like related,
> because COMMIT is called there as well.
The address you have attempted to use for Andres here is incorrect.
Fixed that just now.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-04-14 06:01 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 14:01 Problem with accessing TOAST data in stored procedures Yura Sokolov <y.sokolov@postgrespro.ru>
2021-04-13 14:29 ` Yura Sokolov <y.sokolov@postgrespro.ru>
2021-04-14 06:01 ` Michael Paquier <michael@paquier.xyz>
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