BEGIN;

CREATE TABLE a (
	i int primary key);

CREATE TABLE b (
	j int primary key,
	parent int references a,
	v double precision);

CREATE TABLE c (
	k int primary key,
	parent int references a,
	v double precision);

INSERT INTO a(i)
SELECT n
FROM generate_series(0, 255) AS s(n);

INSERT INTO b(j, parent, v)
SELECT 1024 * i + n, i, random()
FROM generate_series(0, 1023) AS s(n), a;

INSERT INTO c(k, parent, v)
SELECT 1024 * i + n, i, random()
FROM generate_series(0, 1023) AS s(n), a;

CREATE OR REPLACE FUNCTION expensive(x double precision)
RETURNS double precision
LANGUAGE sql
AS $$
   -- CTE is there to avoid inlining.
    WITH tmp AS (SELECT x) SELECT x FROM tmp;
$$
PARALLEL SAFE
COST 10000;

COMMIT;

ANALYZE;
