plpgsql-detoast.sql

text/plain

Filename: plpgsql-detoast.sql
Type: text/plain
Part: 0
Message: Re: patch: fix performance problems with repated decomprimation of varlena values in plpgsql
\set datscale 1000

CREATE TABLE t (c text);
INSERT INTO t VALUES (repeat('a', 1024 * :datscale));

CREATE OR REPLACE FUNCTION f(runs int) RETURNS void LANGUAGE plpgsql AS $$
DECLARE
	foo	text;
BEGIN
	SELECT c INTO foo FROM t;
	FOR n IN 1 .. runs LOOP
		PERFORM foo < 'x';
	END LOOP;
END
$$;

-- datscale=1000: 20.4s before patch, 4.21s after patch
SELECT f(4000);

-- datscale=1: 20.8s before patch, 21.0s after patch
SELECT f(3000000);