DROP TABLE IF EXISTS array_prune CASCADE;

CREATE TABLE array_prune (id int)
PARTITION BY HASH(id);

CREATE TABLE array_prune_t0
  PARTITION OF array_prune FOR VALUES WITH (modulus 2, remainder 0);
CREATE TABLE array_prune_t1
  PARTITION OF array_prune FOR VALUES WITH (modulus 2, remainder 1);
INSERT INTO array_prune (id) (VALUES (1), (2), (3));
ANALYZE array_prune;

SET plan_cache_mode TO force_generic_plan;
PREPARE test (int, int) AS
  SELECT * FROM array_prune WHERE id = ANY(ARRAY[$1,$2]);

-- There should be identical plans
EXPLAIN (COSTS OFF) EXECUTE test(1,2); -- Prune t1
EXPLAIN (COSTS OFF) EXECUTE test(1,3); -- No pruning
EXPLAIN (COSTS OFF) EXECUTE test(3,3); -- Prune t0

DEALLOCATE ALL;

/*
 Append
   Subplans Removed: 1
   ->  Seq Scan on array_prune_t0 array_prune_1
         Filter: (id = ANY (ARRAY[$1, $2]))

 Append
   ->  Seq Scan on array_prune_t0 array_prune_1
         Filter: (id = ANY (ARRAY[$1, $2]))
   ->  Seq Scan on array_prune_t1 array_prune_2
         Filter: (id = ANY (ARRAY[$1, $2]))

 Append
   Subplans Removed: 1
   ->  Seq Scan on array_prune_t1 array_prune_1
         Filter: (id = ANY (ARRAY[$1, $2]))
*/
