|
| 1 | +-- |
| 2 | +-- ISSUE_8468_NUM_NULLS |
| 3 | +-- |
| 4 | +-- Test for GitHub issue #8468: TLP test fail on sqlancer due to |
| 5 | +-- num_nulls interpreted differently on workers. |
| 6 | +-- Root cause: when wrapping local tables into subqueries during |
| 7 | +-- recursive planning, restriction-referenced columns were projected |
| 8 | +-- as NULL in the outer subquery, causing wrong WHERE clause results. |
| 9 | +-- |
| 10 | +CREATE SCHEMA issue_8468; |
| 11 | +SET search_path TO issue_8468; |
| 12 | +SET citus.shard_count TO 4; |
| 13 | +SET citus.next_shard_id TO 9468000; |
| 14 | +CREATE TABLE t5(c0 FLOAT); |
| 15 | +SELECT create_distributed_table('t5', 'c0'); |
| 16 | + create_distributed_table |
| 17 | +--------------------------------------------------------------------- |
| 18 | + |
| 19 | +(1 row) |
| 20 | + |
| 21 | +INSERT INTO t5(c0) VALUES(0.009452163), (1.4691802E9), (0.005109378), (0.6941109), |
| 22 | + (0.7013781), (0.8670044), (-1.6739732E9), (-4.5730365E8); |
| 23 | +CREATE TABLE t1_parent(c0 FLOAT); |
| 24 | +CREATE TABLE t2_child(c0 FLOAT, c1 CHAR(20), c2 DECIMAL) INHERITS(t1_parent); |
| 25 | +NOTICE: merging column "c0" with inherited definition |
| 26 | +INSERT INTO t1_parent(c0) VALUES(-1.6739732E9), (0), (0.32921866), ('-Infinity'); |
| 27 | +INSERT INTO t2_child(c1, c2, c0) VALUES('', 0.19, 0), ('test', 0.33, 0.89), |
| 28 | + ('abc', 0.58, 0.68), ('', 0.18, 0.74), ('', 0.22, 0.71); |
| 29 | +CREATE TEMP TABLE t0(c0 FLOAT); |
| 30 | +INSERT INTO t0(c0) VALUES(-1.9619044E9), (0.18373421), (6.175733E8), (0.58579546); |
| 31 | +-- t1_parent* = 9 rows (4 from parent + 5 from child) |
| 32 | +SELECT count(*) AS parent_star_count FROM t1_parent; |
| 33 | + parent_star_count |
| 34 | +--------------------------------------------------------------------- |
| 35 | + 9 |
| 36 | +(1 row) |
| 37 | + |
| 38 | +-- Original: 9 * (4*8) = 288 |
| 39 | +SELECT count(*) AS original FROM ( |
| 40 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 41 | +) sub; |
| 42 | + original |
| 43 | +--------------------------------------------------------------------- |
| 44 | + 288 |
| 45 | +(1 row) |
| 46 | + |
| 47 | +-- TLP branches should sum to original |
| 48 | +SELECT count(*) AS branch_true FROM ( |
| 49 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 50 | + WHERE (0::double precision IS DISTINCT FROM t1_parent.c0) |
| 51 | +) sub; |
| 52 | + branch_true |
| 53 | +--------------------------------------------------------------------- |
| 54 | + 224 |
| 55 | +(1 row) |
| 56 | + |
| 57 | +SELECT count(*) AS branch_false FROM ( |
| 58 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 59 | + WHERE NOT (0::double precision IS DISTINCT FROM t1_parent.c0) |
| 60 | +) sub; |
| 61 | + branch_false |
| 62 | +--------------------------------------------------------------------- |
| 63 | + 64 |
| 64 | +(1 row) |
| 65 | + |
| 66 | +SELECT count(*) AS branch_null FROM ( |
| 67 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 68 | + WHERE (0::double precision IS DISTINCT FROM t1_parent.c0) IS NULL |
| 69 | +) sub; |
| 70 | + branch_null |
| 71 | +--------------------------------------------------------------------- |
| 72 | + 0 |
| 73 | +(1 row) |
| 74 | + |
| 75 | +-- TLP combined must equal original |
| 76 | +SELECT count(*) AS tlp_total FROM ( |
| 77 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 78 | + WHERE (0::double precision IS DISTINCT FROM t1_parent.c0) |
| 79 | + UNION ALL |
| 80 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 81 | + WHERE NOT (0::double precision IS DISTINCT FROM t1_parent.c0) |
| 82 | + UNION ALL |
| 83 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 84 | + WHERE (0::double precision IS DISTINCT FROM t1_parent.c0) IS NULL |
| 85 | +) sub; |
| 86 | + tlp_total |
| 87 | +--------------------------------------------------------------------- |
| 88 | + 288 |
| 89 | +(1 row) |
| 90 | + |
| 91 | +-- Verify with num_nulls (the original condition from the bug report) |
| 92 | +SELECT count(*) AS num_nulls_tlp FROM ( |
| 93 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 94 | + WHERE (num_nulls(t1_parent.c0) IS DISTINCT FROM t1_parent.c0) |
| 95 | + UNION ALL |
| 96 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 97 | + WHERE NOT (num_nulls(t1_parent.c0) IS DISTINCT FROM t1_parent.c0) |
| 98 | + UNION ALL |
| 99 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 100 | + WHERE (num_nulls(t1_parent.c0) IS DISTINCT FROM t1_parent.c0) IS NULL |
| 101 | +) sub; |
| 102 | + num_nulls_tlp |
| 103 | +--------------------------------------------------------------------- |
| 104 | + 288 |
| 105 | +(1 row) |
| 106 | + |
| 107 | +-- Also test the plain equality condition |
| 108 | +SELECT count(*) AS equals_zero FROM ( |
| 109 | + SELECT t5.c0 FROM t1_parent, t0 LEFT OUTER JOIN t5 ON (True) |
| 110 | + WHERE t1_parent.c0 = 0 |
| 111 | +) sub; |
| 112 | + equals_zero |
| 113 | +--------------------------------------------------------------------- |
| 114 | + 64 |
| 115 | +(1 row) |
| 116 | + |
| 117 | +-- Clean up |
| 118 | +SET client_min_messages TO ERROR; |
| 119 | +DROP SCHEMA issue_8468 CASCADE; |
0 commit comments