DROP EXTENSION IF EXISTS postgres_fdw CASCADE;

CREATE EXTENSION postgres_fdw;
CREATE SERVER lb1 FOREIGN DATA WRAPPER postgres_fdw OPTIONS (async_capable 'true');
CREATE SERVER lb2 FOREIGN DATA WRAPPER postgres_fdw OPTIONS (async_capable 'true');
CREATE USER MAPPING FOR PUBLIC SERVER lb1;
CREATE USER MAPPING FOR PUBLIC SERVER lb2;

CREATE TABLE test (x int) PARTITION BY HASH (x);
CREATE TABLE test_1 (x int);
CREATE TABLE test_2 (x int);
CREATE FOREIGN TABLE ftest_1 PARTITION OF test
	FOR VALUES WITH (modulus 2, remainder 0)
	SERVER lb1 OPTIONS (table_name 'test_1');
CREATE FOREIGN TABLE ftest_2 PARTITION OF test
	FOR VALUES WITH (modulus 2, remainder 1)
	SERVER lb2 OPTIONS (table_name 'test_2');
INSERT INTO test (SELECT * FROM generate_series(1,10));

ANALYZE test,test_1,test_2;

EXPLAIN ANALYZE verbose
SELECT * FROM test WHERE x NOT IN (
	SELECT avg(x) FROM test WHERE x > 10
);