-- =================================================================== -- create test functions -- =================================================================== CREATE FUNCTION prune_using_no_values(regclass) RETURNS text[] AS 'pg_shard' LANGUAGE C STRICT; CREATE FUNCTION prune_using_single_value(regclass, text) RETURNS text[] AS 'pg_shard' LANGUAGE C; CREATE FUNCTION prune_using_either_value(regclass, text, text) RETURNS text[] AS 'pg_shard' LANGUAGE C STRICT; CREATE FUNCTION prune_using_both_values(regclass, text, text) RETURNS text[] AS 'pg_shard' LANGUAGE C STRICT; CREATE FUNCTION debug_equality_expression(regclass) RETURNS cstring AS 'pg_shard' LANGUAGE C STRICT; -- =================================================================== -- test shard pruning functionality -- =================================================================== -- create distributed table metadata to observe shard pruning CREATE TABLE pruning ( species text, last_pruned date, plant_id integer ); INSERT INTO pgs_distribution_metadata.partition (relation_id, partition_method, key) VALUES ('pruning'::regclass, 'h', 'species'); INSERT INTO pgs_distribution_metadata.shard (id, relation_id, storage, min_value, max_value) VALUES (10, 'pruning'::regclass, 't', '-2147483648', '-1073741826'), (11, 'pruning'::regclass, 't', '-1073741825', '-3'), (12, 'pruning'::regclass, 't', '-2', '1073741820'), (13, 'pruning'::regclass, 't', '1073741821', '2147483647'); -- with no values, expect all shards SELECT prune_using_no_values('pruning'); prune_using_no_values ----------------------- {10,11,12,13} (1 row) -- with a single value, expect a single shard SELECT prune_using_single_value('pruning', 'tomato'); prune_using_single_value -------------------------- {12} (1 row) -- the above is true even if that value is null SELECT prune_using_single_value('pruning', NULL); prune_using_single_value -------------------------- {12} (1 row) -- build an OR clause and expect more than one sahrd SELECT prune_using_either_value('pruning', 'tomato', 'petunia'); prune_using_either_value -------------------------- {11,12} (1 row) -- an AND clause with incompatible values returns no shards SELECT prune_using_both_values('pruning', 'tomato', 'petunia'); prune_using_both_values ------------------------- {} (1 row) -- but if both values are on the same shard, should get back that shard SELECT prune_using_both_values('pruning', 'tomato', 'rose'); prune_using_both_values ------------------------- {12} (1 row) -- unit test of the equality expression generation code SELECT debug_equality_expression('pruning'); debug_equality_expression -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {OPEXPR :opno 98 :opfuncid 67 :opresulttype 16 :opretset false :opcollid 0 :inputcollid 100 :args ({VAR :varno 1 :varattno 1 :vartype 25 :vartypmod -1 :varcollid 100 :varlevelsup 0 :varnoold 1 :varoattno 1 :location -1} {CONST :consttype 25 :consttypmod -1 :constcollid 100 :constlen -1 :constbyval false :constisnull true :location -1 :constvalue <>}) :location -1} (1 row)