|
| 1 | +/* |
| 2 | + * --------------------------------------------- |
| 3 | + * NOTE: This test behaves differenly on PgPro |
| 4 | + * --------------------------------------------- |
| 5 | + * |
| 6 | + * Since 12 (608b167f9f), CTEs which are scanned once are no longer an |
| 7 | + * optimization fence, which changes practically all plans here. There is |
| 8 | + * an option to forcibly make them MATERIALIZED, but we also need to run tests |
| 9 | + * on older versions, so create pathman_only_1.out instead. |
| 10 | + * |
| 11 | + * Since 55a1954da16 and 6ef77cf46e8 (>= 13) output of EXPLAIN was changed, |
| 12 | + * now it includes aliases for inherited tables. |
| 13 | + */ |
| 14 | +\set VERBOSITY terse |
| 15 | +SET search_path = 'public'; |
| 16 | +CREATE EXTENSION pg_pathman; |
| 17 | +CREATE SCHEMA test_only; |
| 18 | +/* Test special case: ONLY statement with not-ONLY for partitioned table */ |
| 19 | +CREATE TABLE test_only.from_only_test(val INT NOT NULL); |
| 20 | +INSERT INTO test_only.from_only_test SELECT generate_series(1, 20); |
| 21 | +SELECT create_range_partitions('test_only.from_only_test', 'val', 1, 2); |
| 22 | + create_range_partitions |
| 23 | +------------------------- |
| 24 | + 10 |
| 25 | +(1 row) |
| 26 | + |
| 27 | +VACUUM ANALYZE; |
| 28 | +/* should be OK */ |
| 29 | +EXPLAIN (COSTS OFF) |
| 30 | +SELECT * FROM ONLY test_only.from_only_test |
| 31 | +UNION SELECT * FROM test_only.from_only_test; |
| 32 | + QUERY PLAN |
| 33 | +------------------------------------------------------------------- |
| 34 | + HashAggregate |
| 35 | + Group Key: from_only_test.val |
| 36 | + -> Append |
| 37 | + -> Seq Scan on from_only_test |
| 38 | + -> Append |
| 39 | + -> Seq Scan on from_only_test_1 from_only_test_2 |
| 40 | + -> Seq Scan on from_only_test_2 from_only_test_3 |
| 41 | + -> Seq Scan on from_only_test_3 from_only_test_4 |
| 42 | + -> Seq Scan on from_only_test_4 from_only_test_5 |
| 43 | + -> Seq Scan on from_only_test_5 from_only_test_6 |
| 44 | + -> Seq Scan on from_only_test_6 from_only_test_7 |
| 45 | + -> Seq Scan on from_only_test_7 from_only_test_8 |
| 46 | + -> Seq Scan on from_only_test_8 from_only_test_9 |
| 47 | + -> Seq Scan on from_only_test_9 from_only_test_10 |
| 48 | + -> Seq Scan on from_only_test_10 from_only_test_11 |
| 49 | +(15 rows) |
| 50 | + |
| 51 | +/* should be OK */ |
| 52 | +EXPLAIN (COSTS OFF) |
| 53 | +SELECT * FROM test_only.from_only_test |
| 54 | +UNION SELECT * FROM ONLY test_only.from_only_test; |
| 55 | + QUERY PLAN |
| 56 | +---------------------------------------------------------- |
| 57 | + HashAggregate |
| 58 | + Group Key: from_only_test.val |
| 59 | + -> Append |
| 60 | + -> Append |
| 61 | + -> Seq Scan on from_only_test_1 |
| 62 | + -> Seq Scan on from_only_test_2 |
| 63 | + -> Seq Scan on from_only_test_3 |
| 64 | + -> Seq Scan on from_only_test_4 |
| 65 | + -> Seq Scan on from_only_test_5 |
| 66 | + -> Seq Scan on from_only_test_6 |
| 67 | + -> Seq Scan on from_only_test_7 |
| 68 | + -> Seq Scan on from_only_test_8 |
| 69 | + -> Seq Scan on from_only_test_9 |
| 70 | + -> Seq Scan on from_only_test_10 |
| 71 | + -> Seq Scan on from_only_test from_only_test_11 |
| 72 | +(15 rows) |
| 73 | + |
| 74 | +/* should be OK */ |
| 75 | +EXPLAIN (COSTS OFF) |
| 76 | +SELECT * FROM test_only.from_only_test |
| 77 | +UNION SELECT * FROM test_only.from_only_test |
| 78 | +UNION SELECT * FROM ONLY test_only.from_only_test; |
| 79 | + QUERY PLAN |
| 80 | +------------------------------------------------------------------- |
| 81 | + HashAggregate |
| 82 | + Group Key: from_only_test.val |
| 83 | + -> Append |
| 84 | + -> Append |
| 85 | + -> Seq Scan on from_only_test_1 |
| 86 | + -> Seq Scan on from_only_test_2 |
| 87 | + -> Seq Scan on from_only_test_3 |
| 88 | + -> Seq Scan on from_only_test_4 |
| 89 | + -> Seq Scan on from_only_test_5 |
| 90 | + -> Seq Scan on from_only_test_6 |
| 91 | + -> Seq Scan on from_only_test_7 |
| 92 | + -> Seq Scan on from_only_test_8 |
| 93 | + -> Seq Scan on from_only_test_9 |
| 94 | + -> Seq Scan on from_only_test_10 |
| 95 | + -> Append |
| 96 | + -> Seq Scan on from_only_test_1 from_only_test_12 |
| 97 | + -> Seq Scan on from_only_test_2 from_only_test_13 |
| 98 | + -> Seq Scan on from_only_test_3 from_only_test_14 |
| 99 | + -> Seq Scan on from_only_test_4 from_only_test_15 |
| 100 | + -> Seq Scan on from_only_test_5 from_only_test_16 |
| 101 | + -> Seq Scan on from_only_test_6 from_only_test_17 |
| 102 | + -> Seq Scan on from_only_test_7 from_only_test_18 |
| 103 | + -> Seq Scan on from_only_test_8 from_only_test_19 |
| 104 | + -> Seq Scan on from_only_test_9 from_only_test_20 |
| 105 | + -> Seq Scan on from_only_test_10 from_only_test_21 |
| 106 | + -> Seq Scan on from_only_test from_only_test_22 |
| 107 | +(26 rows) |
| 108 | + |
| 109 | +/* should be OK */ |
| 110 | +EXPLAIN (COSTS OFF) |
| 111 | +SELECT * FROM ONLY test_only.from_only_test |
| 112 | +UNION SELECT * FROM test_only.from_only_test |
| 113 | +UNION SELECT * FROM test_only.from_only_test; |
| 114 | + QUERY PLAN |
| 115 | +------------------------------------------------------------------- |
| 116 | + HashAggregate |
| 117 | + Group Key: from_only_test.val |
| 118 | + -> Append |
| 119 | + -> Seq Scan on from_only_test |
| 120 | + -> Append |
| 121 | + -> Seq Scan on from_only_test_1 from_only_test_2 |
| 122 | + -> Seq Scan on from_only_test_2 from_only_test_3 |
| 123 | + -> Seq Scan on from_only_test_3 from_only_test_4 |
| 124 | + -> Seq Scan on from_only_test_4 from_only_test_5 |
| 125 | + -> Seq Scan on from_only_test_5 from_only_test_6 |
| 126 | + -> Seq Scan on from_only_test_6 from_only_test_7 |
| 127 | + -> Seq Scan on from_only_test_7 from_only_test_8 |
| 128 | + -> Seq Scan on from_only_test_8 from_only_test_9 |
| 129 | + -> Seq Scan on from_only_test_9 from_only_test_10 |
| 130 | + -> Seq Scan on from_only_test_10 from_only_test_11 |
| 131 | + -> Append |
| 132 | + -> Seq Scan on from_only_test_1 from_only_test_13 |
| 133 | + -> Seq Scan on from_only_test_2 from_only_test_14 |
| 134 | + -> Seq Scan on from_only_test_3 from_only_test_15 |
| 135 | + -> Seq Scan on from_only_test_4 from_only_test_16 |
| 136 | + -> Seq Scan on from_only_test_5 from_only_test_17 |
| 137 | + -> Seq Scan on from_only_test_6 from_only_test_18 |
| 138 | + -> Seq Scan on from_only_test_7 from_only_test_19 |
| 139 | + -> Seq Scan on from_only_test_8 from_only_test_20 |
| 140 | + -> Seq Scan on from_only_test_9 from_only_test_21 |
| 141 | + -> Seq Scan on from_only_test_10 from_only_test_22 |
| 142 | +(26 rows) |
| 143 | + |
| 144 | +/* not ok, ONLY|non-ONLY in one query (this is not the case for PgPro) */ |
| 145 | +EXPLAIN (COSTS OFF) |
| 146 | +SELECT * FROM test_only.from_only_test a |
| 147 | +JOIN ONLY test_only.from_only_test b USING(val); |
| 148 | + QUERY PLAN |
| 149 | +--------------------------------------------- |
| 150 | + Nested Loop |
| 151 | + -> Seq Scan on from_only_test b |
| 152 | + -> Custom Scan (RuntimeAppend) |
| 153 | + Prune by: (a.val = b.val) |
| 154 | + -> Seq Scan on from_only_test_1 a |
| 155 | + Filter: (b.val = val) |
| 156 | + -> Seq Scan on from_only_test_2 a |
| 157 | + Filter: (b.val = val) |
| 158 | + -> Seq Scan on from_only_test_3 a |
| 159 | + Filter: (b.val = val) |
| 160 | + -> Seq Scan on from_only_test_4 a |
| 161 | + Filter: (b.val = val) |
| 162 | + -> Seq Scan on from_only_test_5 a |
| 163 | + Filter: (b.val = val) |
| 164 | + -> Seq Scan on from_only_test_6 a |
| 165 | + Filter: (b.val = val) |
| 166 | + -> Seq Scan on from_only_test_7 a |
| 167 | + Filter: (b.val = val) |
| 168 | + -> Seq Scan on from_only_test_8 a |
| 169 | + Filter: (b.val = val) |
| 170 | + -> Seq Scan on from_only_test_9 a |
| 171 | + Filter: (b.val = val) |
| 172 | + -> Seq Scan on from_only_test_10 a |
| 173 | + Filter: (b.val = val) |
| 174 | +(24 rows) |
| 175 | + |
| 176 | +/* should be OK */ |
| 177 | +EXPLAIN (COSTS OFF) |
| 178 | +WITH q1 AS (SELECT * FROM test_only.from_only_test), |
| 179 | + q2 AS (SELECT * FROM ONLY test_only.from_only_test) |
| 180 | +SELECT * FROM q1 JOIN q2 USING(val); |
| 181 | + QUERY PLAN |
| 182 | +--------------------------------------------------------------- |
| 183 | + Nested Loop |
| 184 | + -> Seq Scan on from_only_test from_only_test_1 |
| 185 | + -> Custom Scan (RuntimeAppend) |
| 186 | + Prune by: (from_only_test.val = from_only_test_1.val) |
| 187 | + -> Seq Scan on from_only_test_1 from_only_test |
| 188 | + Filter: (from_only_test_1.val = val) |
| 189 | + -> Seq Scan on from_only_test_2 from_only_test |
| 190 | + Filter: (from_only_test_1.val = val) |
| 191 | + -> Seq Scan on from_only_test_3 from_only_test |
| 192 | + Filter: (from_only_test_1.val = val) |
| 193 | + -> Seq Scan on from_only_test_4 from_only_test |
| 194 | + Filter: (from_only_test_1.val = val) |
| 195 | + -> Seq Scan on from_only_test_5 from_only_test |
| 196 | + Filter: (from_only_test_1.val = val) |
| 197 | + -> Seq Scan on from_only_test_6 from_only_test |
| 198 | + Filter: (from_only_test_1.val = val) |
| 199 | + -> Seq Scan on from_only_test_7 from_only_test |
| 200 | + Filter: (from_only_test_1.val = val) |
| 201 | + -> Seq Scan on from_only_test_8 from_only_test |
| 202 | + Filter: (from_only_test_1.val = val) |
| 203 | + -> Seq Scan on from_only_test_9 from_only_test |
| 204 | + Filter: (from_only_test_1.val = val) |
| 205 | + -> Seq Scan on from_only_test_10 from_only_test |
| 206 | + Filter: (from_only_test_1.val = val) |
| 207 | +(24 rows) |
| 208 | + |
| 209 | +/* should be OK */ |
| 210 | +EXPLAIN (COSTS OFF) |
| 211 | +WITH q1 AS (SELECT * FROM ONLY test_only.from_only_test) |
| 212 | +SELECT * FROM test_only.from_only_test JOIN q1 USING(val); |
| 213 | + QUERY PLAN |
| 214 | +--------------------------------------------------------------- |
| 215 | + Nested Loop |
| 216 | + -> Seq Scan on from_only_test from_only_test_1 |
| 217 | + -> Custom Scan (RuntimeAppend) |
| 218 | + Prune by: (from_only_test.val = from_only_test_1.val) |
| 219 | + -> Seq Scan on from_only_test_1 from_only_test |
| 220 | + Filter: (from_only_test_1.val = val) |
| 221 | + -> Seq Scan on from_only_test_2 from_only_test |
| 222 | + Filter: (from_only_test_1.val = val) |
| 223 | + -> Seq Scan on from_only_test_3 from_only_test |
| 224 | + Filter: (from_only_test_1.val = val) |
| 225 | + -> Seq Scan on from_only_test_4 from_only_test |
| 226 | + Filter: (from_only_test_1.val = val) |
| 227 | + -> Seq Scan on from_only_test_5 from_only_test |
| 228 | + Filter: (from_only_test_1.val = val) |
| 229 | + -> Seq Scan on from_only_test_6 from_only_test |
| 230 | + Filter: (from_only_test_1.val = val) |
| 231 | + -> Seq Scan on from_only_test_7 from_only_test |
| 232 | + Filter: (from_only_test_1.val = val) |
| 233 | + -> Seq Scan on from_only_test_8 from_only_test |
| 234 | + Filter: (from_only_test_1.val = val) |
| 235 | + -> Seq Scan on from_only_test_9 from_only_test |
| 236 | + Filter: (from_only_test_1.val = val) |
| 237 | + -> Seq Scan on from_only_test_10 from_only_test |
| 238 | + Filter: (from_only_test_1.val = val) |
| 239 | +(24 rows) |
| 240 | + |
| 241 | +/* should be OK */ |
| 242 | +EXPLAIN (COSTS OFF) |
| 243 | +SELECT * FROM test_only.from_only_test |
| 244 | +WHERE val = (SELECT val FROM ONLY test_only.from_only_test |
| 245 | + ORDER BY val ASC |
| 246 | + LIMIT 1); |
| 247 | + QUERY PLAN |
| 248 | +----------------------------------------------------------------- |
| 249 | + Custom Scan (RuntimeAppend) |
| 250 | + Prune by: (from_only_test.val = (InitPlan 1).col1) |
| 251 | + InitPlan 1 |
| 252 | + -> Limit |
| 253 | + -> Sort |
| 254 | + Sort Key: from_only_test_1.val |
| 255 | + -> Seq Scan on from_only_test from_only_test_1 |
| 256 | + -> Seq Scan on from_only_test_1 from_only_test |
| 257 | + Filter: (val = (InitPlan 1).col1) |
| 258 | + -> Seq Scan on from_only_test_2 from_only_test |
| 259 | + Filter: (val = (InitPlan 1).col1) |
| 260 | + -> Seq Scan on from_only_test_3 from_only_test |
| 261 | + Filter: (val = (InitPlan 1).col1) |
| 262 | + -> Seq Scan on from_only_test_4 from_only_test |
| 263 | + Filter: (val = (InitPlan 1).col1) |
| 264 | + -> Seq Scan on from_only_test_5 from_only_test |
| 265 | + Filter: (val = (InitPlan 1).col1) |
| 266 | + -> Seq Scan on from_only_test_6 from_only_test |
| 267 | + Filter: (val = (InitPlan 1).col1) |
| 268 | + -> Seq Scan on from_only_test_7 from_only_test |
| 269 | + Filter: (val = (InitPlan 1).col1) |
| 270 | + -> Seq Scan on from_only_test_8 from_only_test |
| 271 | + Filter: (val = (InitPlan 1).col1) |
| 272 | + -> Seq Scan on from_only_test_9 from_only_test |
| 273 | + Filter: (val = (InitPlan 1).col1) |
| 274 | + -> Seq Scan on from_only_test_10 from_only_test |
| 275 | + Filter: (val = (InitPlan 1).col1) |
| 276 | +(27 rows) |
| 277 | + |
| 278 | +DROP TABLE test_only.from_only_test CASCADE; |
| 279 | +NOTICE: drop cascades to 11 other objects |
| 280 | +DROP SCHEMA test_only; |
| 281 | +DROP EXTENSION pg_pathman; |
0 commit comments