|
| 1 | +statement ok |
| 2 | +create or replace database d_subquery; |
| 3 | + |
| 4 | +statement ok |
| 5 | +use d_subquery; |
| 6 | + |
| 7 | +statement ok |
| 8 | +CREATE OR REPLACE TABLE t1 (a int); |
| 9 | + |
| 10 | +statement ok |
| 11 | +CREATE OR REPLACE TABLE t2 (a int); |
| 12 | + |
| 13 | +statement ok |
| 14 | +INSERT INTO t1 VALUES (1), (2), (NULL); |
| 15 | + |
| 16 | +statement ok |
| 17 | +INSERT INTO t2 VALUES (2), (NULL); |
| 18 | + |
| 19 | + |
| 20 | +query T |
| 21 | +explain SELECT t1.a, EXISTS(SELECT 1 FROM t2 WHERE t2.a = t1.a), not EXISTS(SELECT 1 FROM t2 WHERE t2.a = t1.a) AS has_match |
| 22 | +FROM t1; |
| 23 | +---- |
| 24 | +Exchange |
| 25 | +โโโ output columns: [t1.a (#0), EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a) (#5), has_match (#6)] |
| 26 | +โโโ exchange type: Merge |
| 27 | +โโโ EvalScalar |
| 28 | + โโโ output columns: [t1.a (#0), EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a) (#5), has_match (#6)] |
| 29 | + โโโ expressions: [is_true(7 (#7)), NOT is_true(8 (#8))] |
| 30 | + โโโ estimated rows: 3.00 |
| 31 | + โโโ HashJoin |
| 32 | + โโโ output columns: [t1.a (#0), marker (#7), marker (#8)] |
| 33 | + โโโ join type: RIGHT MARK |
| 34 | + โโโ build keys: [a (#3)] |
| 35 | + โโโ probe keys: [a (#0)] |
| 36 | + โโโ keys is null equal: [true] |
| 37 | + โโโ filters: [] |
| 38 | + โโโ estimated rows: 3.00 |
| 39 | + โโโ Exchange(Build) |
| 40 | + โ โโโ output columns: [t2.a (#3)] |
| 41 | + โ โโโ exchange type: Broadcast |
| 42 | + โ โโโ Filter |
| 43 | + โ โโโ output columns: [t2.a (#3)] |
| 44 | + โ โโโ filters: [is_true(outer.a (#3) = outer.a (#3))] |
| 45 | + โ โโโ estimated rows: 0.40 |
| 46 | + โ โโโ TableScan |
| 47 | + โ โโโ table: default.d_subquery.t2 |
| 48 | + โ โโโ output columns: [a (#3)] |
| 49 | + โ โโโ read rows: 2 |
| 50 | + โ โโโ read size: < 1 KiB |
| 51 | + โ โโโ partitions total: 1 |
| 52 | + โ โโโ partitions scanned: 1 |
| 53 | + โ โโโ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>] |
| 54 | + โ โโโ push downs: [filters: [is_true(t2.a (#3) = t2.a (#3))], limit: NONE] |
| 55 | + โ โโโ estimated rows: 2.00 |
| 56 | + โโโ Exchange(Probe) |
| 57 | + โโโ output columns: [t1.a (#0), marker (#7)] |
| 58 | + โโโ exchange type: Hash(a (#0)) |
| 59 | + โโโ HashJoin |
| 60 | + โโโ output columns: [t1.a (#0), marker (#7)] |
| 61 | + โโโ join type: RIGHT MARK |
| 62 | + โโโ build keys: [a (#1)] |
| 63 | + โโโ probe keys: [a (#0)] |
| 64 | + โโโ keys is null equal: [true] |
| 65 | + โโโ filters: [] |
| 66 | + โโโ estimated rows: 3.00 |
| 67 | + โโโ Exchange(Build) |
| 68 | + โ โโโ output columns: [t2.a (#1)] |
| 69 | + โ โโโ exchange type: Broadcast |
| 70 | + โ โโโ Filter |
| 71 | + โ โโโ output columns: [t2.a (#1)] |
| 72 | + โ โโโ filters: [is_true(outer.a (#1) = outer.a (#1))] |
| 73 | + โ โโโ estimated rows: 0.40 |
| 74 | + โ โโโ TableScan |
| 75 | + โ โโโ table: default.d_subquery.t2 |
| 76 | + โ โโโ output columns: [a (#1)] |
| 77 | + โ โโโ read rows: 2 |
| 78 | + โ โโโ read size: < 1 KiB |
| 79 | + โ โโโ partitions total: 1 |
| 80 | + โ โโโ partitions scanned: 1 |
| 81 | + โ โโโ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>] |
| 82 | + โ โโโ push downs: [filters: [is_true(t2.a (#1) = t2.a (#1))], limit: NONE] |
| 83 | + โ โโโ estimated rows: 2.00 |
| 84 | + โโโ Exchange(Probe) |
| 85 | + โโโ output columns: [t1.a (#0)] |
| 86 | + โโโ exchange type: Hash(a (#0)) |
| 87 | + โโโ TableScan |
| 88 | + โโโ table: default.d_subquery.t1 |
| 89 | + โโโ output columns: [a (#0)] |
| 90 | + โโโ read rows: 3 |
| 91 | + โโโ read size: < 1 KiB |
| 92 | + โโโ partitions total: 1 |
| 93 | + โโโ partitions scanned: 1 |
| 94 | + โโโ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>] |
| 95 | + โโโ push downs: [filters: [], limit: NONE] |
| 96 | + โโโ estimated rows: 3.00 |
| 97 | + |
| 98 | +query T |
| 99 | +explain SELECT |
| 100 | + t1.a, |
| 101 | + t1.a IN (SELECT a FROM t2) AS in_match, |
| 102 | + t1.a NOT IN (SELECT a FROM t2) AS not_in_match |
| 103 | +FROM t1; |
| 104 | +---- |
| 105 | +Exchange |
| 106 | +โโโ output columns: [t1.a (#0), in_match (#3), not_in_match (#4)] |
| 107 | +โโโ exchange type: Merge |
| 108 | +โโโ EvalScalar |
| 109 | + โโโ output columns: [t1.a (#0), in_match (#3), not_in_match (#4)] |
| 110 | + โโโ expressions: [NOT 5 (#5)] |
| 111 | + โโโ estimated rows: 3.00 |
| 112 | + โโโ HashJoin |
| 113 | + โโโ output columns: [t1.a (#0), in_match (#3), marker (#5)] |
| 114 | + โโโ join type: RIGHT MARK |
| 115 | + โโโ build keys: [subquery_2 (#2)] |
| 116 | + โโโ probe keys: [t1.a (#0)] |
| 117 | + โโโ keys is null equal: [true] |
| 118 | + โโโ filters: [] |
| 119 | + โโโ estimated rows: 3.00 |
| 120 | + โโโ Exchange(Build) |
| 121 | + โ โโโ output columns: [t2.a (#2)] |
| 122 | + โ โโโ exchange type: Broadcast |
| 123 | + โ โโโ TableScan |
| 124 | + โ โโโ table: default.d_subquery.t2 |
| 125 | + โ โโโ output columns: [a (#2)] |
| 126 | + โ โโโ read rows: 2 |
| 127 | + โ โโโ read size: < 1 KiB |
| 128 | + โ โโโ partitions total: 1 |
| 129 | + โ โโโ partitions scanned: 1 |
| 130 | + โ โโโ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>] |
| 131 | + โ โโโ push downs: [filters: [], limit: NONE] |
| 132 | + โ โโโ estimated rows: 2.00 |
| 133 | + โโโ Exchange(Probe) |
| 134 | + โโโ output columns: [t1.a (#0), in_match (#3)] |
| 135 | + โโโ exchange type: Hash(t1.a (#0)) |
| 136 | + โโโ HashJoin |
| 137 | + โโโ output columns: [t1.a (#0), in_match (#3)] |
| 138 | + โโโ join type: RIGHT MARK |
| 139 | + โโโ build keys: [subquery_1 (#1)] |
| 140 | + โโโ probe keys: [t1.a (#0)] |
| 141 | + โโโ keys is null equal: [true] |
| 142 | + โโโ filters: [] |
| 143 | + โโโ estimated rows: 3.00 |
| 144 | + โโโ Exchange(Build) |
| 145 | + โ โโโ output columns: [t2.a (#1)] |
| 146 | + โ โโโ exchange type: Broadcast |
| 147 | + โ โโโ TableScan |
| 148 | + โ โโโ table: default.d_subquery.t2 |
| 149 | + โ โโโ output columns: [a (#1)] |
| 150 | + โ โโโ read rows: 2 |
| 151 | + โ โโโ read size: < 1 KiB |
| 152 | + โ โโโ partitions total: 1 |
| 153 | + โ โโโ partitions scanned: 1 |
| 154 | + โ โโโ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>] |
| 155 | + โ โโโ push downs: [filters: [], limit: NONE] |
| 156 | + โ โโโ estimated rows: 2.00 |
| 157 | + โโโ Exchange(Probe) |
| 158 | + โโโ output columns: [t1.a (#0)] |
| 159 | + โโโ exchange type: Hash(t1.a (#0)) |
| 160 | + โโโ TableScan |
| 161 | + โโโ table: default.d_subquery.t1 |
| 162 | + โโโ output columns: [a (#0)] |
| 163 | + โโโ read rows: 3 |
| 164 | + โโโ read size: < 1 KiB |
| 165 | + โโโ partitions total: 1 |
| 166 | + โโโ partitions scanned: 1 |
| 167 | + โโโ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>] |
| 168 | + โโโ push downs: [filters: [], limit: NONE] |
| 169 | + โโโ estimated rows: 3.00 |
| 170 | + |
| 171 | + |
| 172 | +statement ok |
| 173 | +drop database d_subquery |
0 commit comments