ALTER SYSTEM SET max_parallel_workers_per_gather = 0;
SELECT pg_reload_conf();

CREATE EXTENSION postgres_fdw;
CREATE EXTENSION pg_prewarm;


DO $d$
    BEGIN
        EXECUTE $$CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw
            OPTIONS (dbname '$$||current_database()||$$',
                     port '$$||current_setting('port')||$$'
            )$$;
    END;
$d$;

CREATE USER MAPPING FOR CURRENT_USER SERVER loopback;

CREATE TABLE public.t (a INT);
INSERT INTO t SELECT x FROM generate_series(1,10000000) x;
VACUUM FREEZE ANALYZE t;
SELECT pg_prewarm('t');

CREATE FOREIGN TABLE ft (
a INT
) SERVER loopback  OPTIONS (schema_name 'public', table_name 't');

ANALYZE ft;

ALTER SERVER loopback OPTIONS (ADD fdw_tuple_cost '0.0');
