Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWK2d-0003q1-H7 for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Apr 2021 14:29:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lWK2c-0005sC-E5 for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Apr 2021 14:29:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWK2c-0005s5-5J for pgsql-bugs@lists.postgresql.org; Tue, 13 Apr 2021 14:29:22 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lWK2Z-0005Zs-6j for pgsql-bugs@lists.postgresql.org; Tue, 13 Apr 2021 14:29:21 +0000 Received: from mail.postgrespro.ru (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 8278921C79A8; Tue, 13 Apr 2021 17:29:17 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1618324157; bh=Y5YeEv0r2dJceACtz+Rhv7WWVcIBOWfTdoSi65XvCRY=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=f2nho8LLy/gT8o/Sdag68mmFPvd5ld0+UIQ2NUEh2rqPwL8jb5bFbQFpSR0rM56Se A6OEBm23TzV4QaGXcT06Rgve9YpVVAaGPDgK29uPkRUuUA7zmKig0Hjj8rQD18BRKC QY2iRw40wuvzQcS8J25K0ufdZ22PSr/0X3CNy+mM= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 13 Apr 2021 17:29:17 +0300 From: Yura Sokolov To: pgsql-bugs@lists.postgresql.org Cc: andres@anarazel.de Subject: Re: Problem with accessing TOAST data in stored procedures In-Reply-To: <03644c0e6bb82132ac783982b6abffdf@postgrespro.ru> References: <03644c0e6bb82132ac783982b6abffdf@postgrespro.ru> User-Agent: Roundcube Webmail/1.4.0 Message-ID: <1a9932c04b41d10c1ceb1d24cc1694f5@postgrespro.ru> X-Sender: y.sokolov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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#d93b550f2f0c1eae785f666251432929 > > 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