-- -- MULTI_NULL_MINMAX_VALUE_PRUNING -- -- This test checks that we can handle null min/max values in shard statistics -- and that we don't partition or join prune shards that have null values. ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 760000; ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 760000; SET client_min_messages TO DEBUG2; -- Change configuration to treat lineitem and orders tables as large SET citus.large_table_shard_count TO 2; SELECT shardminvalue, shardmaxvalue from pg_dist_shard WHERE shardid = 290000; shardminvalue | shardmaxvalue ---------------+--------------- 1 | 1509 (1 row) SELECT shardminvalue, shardmaxvalue from pg_dist_shard WHERE shardid = 290001; shardminvalue | shardmaxvalue ---------------+--------------- 1509 | 2951 (1 row) -- Check that partition and join pruning works when min/max values exist -- Adding l_orderkey = 1 to make the query not router executable SELECT l_orderkey, l_linenumber, l_shipdate FROM lineitem WHERE l_orderkey = 9030 or l_orderkey = 1; DEBUG: predicate pruning for shardId 290001 DEBUG: predicate pruning for shardId 290002 DEBUG: predicate pruning for shardId 290003 DEBUG: predicate pruning for shardId 290005 DEBUG: predicate pruning for shardId 290006 DEBUG: predicate pruning for shardId 290007 l_orderkey | l_linenumber | l_shipdate ------------+--------------+------------ 1 | 1 | 03-13-1996 1 | 2 | 04-12-1996 1 | 3 | 01-29-1996 1 | 4 | 04-21-1996 1 | 5 | 03-30-1996 1 | 6 | 01-30-1996 9030 | 1 | 09-02-1998 9030 | 2 | 08-19-1998 9030 | 3 | 08-27-1998 9030 | 4 | 07-20-1998 9030 | 5 | 09-29-1998 9030 | 6 | 09-03-1998 (12 rows) SELECT sum(l_linenumber), avg(l_linenumber) FROM lineitem, orders WHERE l_orderkey = o_orderkey; DEBUG: join prunable for intervals [1,1509] and [8997,14946] DEBUG: join prunable for intervals [1509,2951] and [8997,14946] DEBUG: join prunable for intervals [2951,4455] and [8997,14946] DEBUG: join prunable for intervals [4480,5986] and [8997,14946] DEBUG: join prunable for intervals [8997,10560] and [1,5986] DEBUG: join prunable for intervals [10560,12036] and [1,5986] DEBUG: join prunable for intervals [12036,13473] and [1,5986] DEBUG: join prunable for intervals [13473,14947] and [1,5986] sum | avg -------+-------------------- 36086 | 3.0076679446574429 (1 row) -- Now set the minimum value for a shard to null. Then check that we don't apply -- partition or join pruning for the shard with null min value. UPDATE pg_dist_shard SET shardminvalue = NULL WHERE shardid = 290000; SELECT l_orderkey, l_linenumber, l_shipdate FROM lineitem WHERE l_orderkey = 9030; DEBUG: predicate pruning for shardId 290001 DEBUG: predicate pruning for shardId 290002 DEBUG: predicate pruning for shardId 290003 DEBUG: predicate pruning for shardId 290005 DEBUG: predicate pruning for shardId 290006 DEBUG: predicate pruning for shardId 290007 l_orderkey | l_linenumber | l_shipdate ------------+--------------+------------ 9030 | 1 | 09-02-1998 9030 | 2 | 08-19-1998 9030 | 3 | 08-27-1998 9030 | 4 | 07-20-1998 9030 | 5 | 09-29-1998 9030 | 6 | 09-03-1998 (6 rows) SELECT sum(l_linenumber), avg(l_linenumber) FROM lineitem, orders WHERE l_orderkey = o_orderkey; DEBUG: join prunable for intervals [1509,2951] and [8997,14946] DEBUG: join prunable for intervals [2951,4455] and [8997,14946] DEBUG: join prunable for intervals [4480,5986] and [8997,14946] DEBUG: join prunable for intervals [8997,10560] and [1,5986] DEBUG: join prunable for intervals [10560,12036] and [1,5986] DEBUG: join prunable for intervals [12036,13473] and [1,5986] DEBUG: join prunable for intervals [13473,14947] and [1,5986] sum | avg -------+-------------------- 36086 | 3.0076679446574429 (1 row) -- Next, set the maximum value for another shard to null. Then check that we -- don't apply partition or join pruning for this other shard either. UPDATE pg_dist_shard SET shardmaxvalue = NULL WHERE shardid = 290001; SELECT l_orderkey, l_linenumber, l_shipdate FROM lineitem WHERE l_orderkey = 9030; DEBUG: predicate pruning for shardId 290002 DEBUG: predicate pruning for shardId 290003 DEBUG: predicate pruning for shardId 290005 DEBUG: predicate pruning for shardId 290006 DEBUG: predicate pruning for shardId 290007 l_orderkey | l_linenumber | l_shipdate ------------+--------------+------------ 9030 | 1 | 09-02-1998 9030 | 2 | 08-19-1998 9030 | 3 | 08-27-1998 9030 | 4 | 07-20-1998 9030 | 5 | 09-29-1998 9030 | 6 | 09-03-1998 (6 rows) SELECT sum(l_linenumber), avg(l_linenumber) FROM lineitem, orders WHERE l_orderkey = o_orderkey; DEBUG: join prunable for intervals [2951,4455] and [8997,14946] DEBUG: join prunable for intervals [4480,5986] and [8997,14946] DEBUG: join prunable for intervals [8997,10560] and [1,5986] DEBUG: join prunable for intervals [10560,12036] and [1,5986] DEBUG: join prunable for intervals [12036,13473] and [1,5986] DEBUG: join prunable for intervals [13473,14947] and [1,5986] sum | avg -------+-------------------- 36086 | 3.0076679446574429 (1 row) -- Last, set the minimum value to 0 and check that we don't treat it as null. We -- should apply partition and join pruning for this shard now. UPDATE pg_dist_shard SET shardminvalue = '0' WHERE shardid = 290000; SELECT l_orderkey, l_linenumber, l_shipdate FROM lineitem WHERE l_orderkey = 9030; DEBUG: predicate pruning for shardId 290000 DEBUG: predicate pruning for shardId 290002 DEBUG: predicate pruning for shardId 290003 DEBUG: predicate pruning for shardId 290005 DEBUG: predicate pruning for shardId 290006 DEBUG: predicate pruning for shardId 290007 l_orderkey | l_linenumber | l_shipdate ------------+--------------+------------ 9030 | 1 | 09-02-1998 9030 | 2 | 08-19-1998 9030 | 3 | 08-27-1998 9030 | 4 | 07-20-1998 9030 | 5 | 09-29-1998 9030 | 6 | 09-03-1998 (6 rows) SELECT sum(l_linenumber), avg(l_linenumber) FROM lineitem, orders WHERE l_orderkey = o_orderkey; DEBUG: join prunable for intervals [0,1509] and [8997,14946] DEBUG: join prunable for intervals [2951,4455] and [8997,14946] DEBUG: join prunable for intervals [4480,5986] and [8997,14946] DEBUG: join prunable for intervals [8997,10560] and [1,5986] DEBUG: join prunable for intervals [10560,12036] and [1,5986] DEBUG: join prunable for intervals [12036,13473] and [1,5986] DEBUG: join prunable for intervals [13473,14947] and [1,5986] sum | avg -------+-------------------- 36086 | 3.0076679446574429 (1 row) -- Set minimum and maximum values for two shards back to their original values UPDATE pg_dist_shard SET shardminvalue = '1' WHERE shardid = 290000; UPDATE pg_dist_shard SET shardmaxvalue = '4964' WHERE shardid = 290001; SET client_min_messages TO NOTICE;