Problem with accessing OTAST data in stored procedures
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t70067_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t70067_1 && git checkout t70067_1Patchset v1 (message #1) is on t70067_1
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:
/messages/by-id/20190904105618.j5l6fhyesmprmstf@alap3.anarazel.de