\timing on

-- Initialization.
BEGIN;
DROP MATERIALIZED VIEW IF EXISTS test_view;
CREATE TABLE test_table AS SELECT s as id, random() AS f1, random() AS f2, random() AS f3, random() AS f4, random() AS f5, random() AS f6, random() AS f7, random() AS f8, random() AS f9, random() AS f10 FROM generate_series(1,1000000) AS s;
CREATE UNIQUE INDEX test_table_id ON test_table (id);
ALTER TABLE test_table ADD PRIMARY KEY USING INDEX test_table_id;
CREATE MATERIALIZED VIEW test_view AS SELECT * FROM test_table;
CREATE UNIQUE INDEX test_view_id ON test_view (id);
END;

-- Modification.
BEGIN;
DELETE FROM test_table WHERE id % 3 = 0;
UPDATE test_table SET f1=random() WHERE id % 3 = 1;
INSERT INTO test_table VALUES (generate_series(1000001,1500000), random(), random(), random(), random(), random(), random(), random(), random(), random(), random());
END;

-- Refresh.
--REFRESH MATERIALIZED VIEW CONCURRENTLY test_view;
REFRESH MATERIALIZED VIEW test_view;
