CREATE TEMPORARY TABLE test(a int, b int, c text);

CREATE OR REPLACE FUNCTION expr(b int) RETURNS int AS $$
BEGIN
PERFORM pg_sleep(1);
RETURN b;
END
$$ LANGUAGE plpgsql IMMUTABLE;

CREATE INDEX i_test ON test (expr(b));

\timing

INSERT INTO test VALUES (1, 1, NULL);

UPDATE test SET a = 1;

UPDATE test SET a = 2;

UPDATE test SET b = 1;

UPDATE test SET b = 2;

UPDATE test SET b = 3;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;

UPDATE test SET c = repeat('x', 1000);

SELECT max(ctid) FROM test;
