|
| 1 | +# description: Tests for printout of various aggregation operators. |
| 2 | +# Plan around these operators may change in whatever way, |
| 3 | +# the only thing that must be held is an invariant described |
| 4 | +# in comments to every test case. |
| 5 | +# group: [explain] |
| 6 | + |
| 7 | +# simple group colocated hash aggregate |
| 8 | +plan |
| 9 | +SELECT sum(c2) |
| 10 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 11 | + GROUP BY c1; |
| 12 | +---- |
| 13 | +Project |
| 14 | + fieldNames: [EXPR$0] |
| 15 | + projection: [EXPR$0] |
| 16 | + est: (rows=20) |
| 17 | + ColocatedHashAggregate |
| 18 | + fieldNames: [C1, EXPR$0] |
| 19 | + group: [C1] |
| 20 | + aggregation: [SUM(C2)] |
| 21 | + est: (rows=20) |
| 22 | + Project |
| 23 | + fieldNames: [C1, C2] |
| 24 | + projection: [X, X] |
| 25 | + est: (rows=100) |
| 26 | + TableFunctionScan |
| 27 | + fieldNames: [X] |
| 28 | + invocation: SYSTEM_RANGE(1, 10) |
| 29 | + est: (rows=100) |
| 30 | + |
| 31 | +# simple group colocated sort aggregate |
| 32 | +plan |
| 33 | +SELECT /*+ DISABLE_RULE('ColocatedHashAggregateConverterRule', |
| 34 | + 'MapReduceHashAggregateConverterRule') */ sum(c2) |
| 35 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 36 | + GROUP BY c1; |
| 37 | +---- |
| 38 | +Project |
| 39 | + fieldNames: [EXPR$0] |
| 40 | + projection: [EXPR$0] |
| 41 | + est: (rows=20) |
| 42 | + ColocatedSortAggregate |
| 43 | + fieldNames: [C1, EXPR$0] |
| 44 | + collation: [C1 ASC] |
| 45 | + group: [C1] |
| 46 | + aggregation: [SUM(C2)] |
| 47 | + est: (rows=20) |
| 48 | + Project |
| 49 | + fieldNames: [C1, C2] |
| 50 | + projection: [X, X] |
| 51 | + est: (rows=100) |
| 52 | + Sort |
| 53 | + collation: [X ASC] |
| 54 | + est: (rows=100) |
| 55 | + TableFunctionScan |
| 56 | + fieldNames: [X] |
| 57 | + invocation: SYSTEM_RANGE(1, 10) |
| 58 | + est: (rows=100) |
| 59 | + |
| 60 | +# simple group map-reduce hash aggregate |
| 61 | +plan |
| 62 | +SELECT /*+ DISABLE_RULE('ColocatedHashAggregateConverterRule') */ sum(c2) |
| 63 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 64 | + GROUP BY c1; |
| 65 | +---- |
| 66 | +Project |
| 67 | + fieldNames: [EXPR$0] |
| 68 | + projection: [EXPR$0] |
| 69 | + est: (rows=20) |
| 70 | + ReduceHashAggregate |
| 71 | + fieldNames: [C1, EXPR$0] |
| 72 | + group: [C1] |
| 73 | + aggregation: [SUM(_ACC0)] |
| 74 | + est: (rows=20) |
| 75 | + MapHashAggregate |
| 76 | + fieldNames: [C1, _ACC0, _GROUP_ID] |
| 77 | + group: [C1] |
| 78 | + aggregation: [SUM(C2)] |
| 79 | + est: (rows=20) |
| 80 | + Project |
| 81 | + fieldNames: [C1, C2] |
| 82 | + projection: [X, X] |
| 83 | + est: (rows=100) |
| 84 | + TableFunctionScan |
| 85 | + fieldNames: [X] |
| 86 | + invocation: SYSTEM_RANGE(1, 10) |
| 87 | + est: (rows=100) |
| 88 | + |
| 89 | +# simple group map-reduce sort aggregate |
| 90 | +plan |
| 91 | +SELECT /*+ DISABLE_RULE('ColocatedHashAggregateConverterRule', |
| 92 | + 'ColocatedHashAggregateConverterRule', |
| 93 | + 'ColocatedSortAggregateConverterRule', |
| 94 | + 'MapReduceHashAggregateConverterRule') */ sum(c2) |
| 95 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 96 | + GROUP BY c1; |
| 97 | +---- |
| 98 | +Project |
| 99 | + fieldNames: [EXPR$0] |
| 100 | + projection: [EXPR$0] |
| 101 | + est: (rows=20) |
| 102 | + ReduceSortAggregate |
| 103 | + fieldNames: [C1, EXPR$0] |
| 104 | + collation: [C1 ASC] |
| 105 | + group: [C1] |
| 106 | + aggregation: [SUM(_ACC0)] |
| 107 | + est: (rows=20) |
| 108 | + MapSortAggregate |
| 109 | + fieldNames: [C1, _ACC0] |
| 110 | + collation: [C1 ASC] |
| 111 | + group: [C1] |
| 112 | + aggregation: [SUM(C2)] |
| 113 | + est: (rows=20) |
| 114 | + Project |
| 115 | + fieldNames: [C1, C2] |
| 116 | + projection: [X, X] |
| 117 | + est: (rows=100) |
| 118 | + Sort |
| 119 | + collation: [X ASC] |
| 120 | + est: (rows=100) |
| 121 | + TableFunctionScan |
| 122 | + fieldNames: [X] |
| 123 | + invocation: SYSTEM_RANGE(1, 10) |
| 124 | + est: (rows=100) |
| 125 | + |
| 126 | +# aggregation by group set colocated hash aggregate |
| 127 | +plan |
| 128 | +SELECT sum(c2) |
| 129 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 130 | + GROUP BY ROLLUP (c1, c3); |
| 131 | +---- |
| 132 | +Project |
| 133 | + fieldNames: [EXPR$0] |
| 134 | + projection: [EXPR$0] |
| 135 | + est: (rows=36) |
| 136 | + ColocatedHashAggregate |
| 137 | + fieldNames: [C1, C3, EXPR$0] |
| 138 | + group: [C1, C3] |
| 139 | + groupSets: [[C1, C3], [C1], []] |
| 140 | + aggregation: [SUM(C2)] |
| 141 | + est: (rows=36) |
| 142 | + Project |
| 143 | + fieldNames: [C1, C3, C2] |
| 144 | + projection: [X, X, X] |
| 145 | + est: (rows=100) |
| 146 | + TableFunctionScan |
| 147 | + fieldNames: [X] |
| 148 | + invocation: SYSTEM_RANGE(1, 10) |
| 149 | + est: (rows=100) |
| 150 | + |
| 151 | +# aggregation by group set map-reduce hash aggregate |
| 152 | +plan |
| 153 | +SELECT /*+ DISABLE_RULE('ColocatedHashAggregateConverterRule') */ sum(c2) |
| 154 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 155 | + GROUP BY ROLLUP (c1, c3); |
| 156 | +---- |
| 157 | +Project |
| 158 | + fieldNames: [EXPR$0] |
| 159 | + projection: [EXPR$0] |
| 160 | + est: (rows=36) |
| 161 | + ReduceHashAggregate |
| 162 | + fieldNames: [C1, C3, EXPR$0] |
| 163 | + group: [C1, C3] |
| 164 | + groupSets: [[C1, C3], [C1], []] |
| 165 | + aggregation: [SUM(_ACC0)] |
| 166 | + est: (rows=36) |
| 167 | + MapHashAggregate |
| 168 | + fieldNames: [C1, C3, _ACC0, _GROUP_ID] |
| 169 | + group: [C1, C3] |
| 170 | + groupSets: [[C1, C3], [C1], []] |
| 171 | + aggregation: [SUM(C2)] |
| 172 | + est: (rows=36) |
| 173 | + Project |
| 174 | + fieldNames: [C1, C3, C2] |
| 175 | + projection: [X, X, X] |
| 176 | + est: (rows=100) |
| 177 | + TableFunctionScan |
| 178 | + fieldNames: [X] |
| 179 | + invocation: SYSTEM_RANGE(1, 10) |
| 180 | + est: (rows=100) |
| 181 | + |
| 182 | +# distinct aggregate |
| 183 | +plan |
| 184 | +SELECT sum(DISTINCT c2) |
| 185 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 186 | + GROUP BY c1; |
| 187 | +---- |
| 188 | +Project |
| 189 | + fieldNames: [EXPR$0] |
| 190 | + projection: [EXPR$0] |
| 191 | + est: (rows=20) |
| 192 | + ColocatedHashAggregate |
| 193 | + fieldNames: [C1, EXPR$0] |
| 194 | + group: [C1] |
| 195 | + aggregation: [SUM(DISTINCT C2)] |
| 196 | + est: (rows=20) |
| 197 | + Project |
| 198 | + fieldNames: [C1, C2] |
| 199 | + projection: [X, X] |
| 200 | + est: (rows=100) |
| 201 | + TableFunctionScan |
| 202 | + fieldNames: [X] |
| 203 | + invocation: SYSTEM_RANGE(1, 10) |
| 204 | + est: (rows=100) |
| 205 | + |
| 206 | +# aggregate within distinct |
| 207 | +plan |
| 208 | +SELECT sum(c2) WITHIN DISTINCT (c2 / 2) |
| 209 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 210 | + GROUP BY c1; |
| 211 | +---- |
| 212 | +Project |
| 213 | + fieldNames: [EXPR$0] |
| 214 | + projection: [EXPR$0] |
| 215 | + est: (rows=20) |
| 216 | + ColocatedHashAggregate |
| 217 | + fieldNames: [C1, EXPR$0] |
| 218 | + group: [C1] |
| 219 | + aggregation: [SUM(C2) WITHIN DISTINCT ($f2)] |
| 220 | + est: (rows=20) |
| 221 | + Project |
| 222 | + fieldNames: [C1, C2, $f2] |
| 223 | + projection: [X, X, /(X, 2)] |
| 224 | + est: (rows=100) |
| 225 | + TableFunctionScan |
| 226 | + fieldNames: [X] |
| 227 | + invocation: SYSTEM_RANGE(1, 10) |
| 228 | + est: (rows=100) |
| 229 | + |
| 230 | +# aggregate with additional filtration |
| 231 | +plan |
| 232 | +SELECT sum(c2) FILTER (WHERE c2 % 2 = 1) |
| 233 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 234 | + GROUP BY c1; |
| 235 | +---- |
| 236 | +Project |
| 237 | + fieldNames: [EXPR$0] |
| 238 | + projection: [EXPR$0] |
| 239 | + est: (rows=20) |
| 240 | + ColocatedHashAggregate |
| 241 | + fieldNames: [C1, EXPR$0] |
| 242 | + group: [C1] |
| 243 | + aggregation: [SUM(C2) FILTER $f2] |
| 244 | + est: (rows=20) |
| 245 | + Project |
| 246 | + fieldNames: [C1, C2, $f2] |
| 247 | + projection: [X, X, =(MOD(X, 2), 1)] |
| 248 | + est: (rows=100) |
| 249 | + TableFunctionScan |
| 250 | + fieldNames: [X] |
| 251 | + invocation: SYSTEM_RANGE(1, 10) |
| 252 | + est: (rows=100) |
| 253 | + |
| 254 | +# aggregate with all modification |
| 255 | +plan |
| 256 | +SELECT count(DISTINCT c2) WITHIN DISTINCT (c2 / 2) FILTER (WHERE c2 % 2 = 1) |
| 257 | + FROM (SELECT x AS c1, x AS c2, x AS c3 FROM system_range(1, 10)) |
| 258 | + GROUP BY c1; |
| 259 | +---- |
| 260 | +Project |
| 261 | + fieldNames: [EXPR$0] |
| 262 | + projection: [EXPR$0] |
| 263 | + est: (rows=20) |
| 264 | + ColocatedHashAggregate |
| 265 | + fieldNames: [C1, EXPR$0] |
| 266 | + group: [C1] |
| 267 | + aggregation: [COUNT(DISTINCT C2) WITHIN DISTINCT ($f3) FILTER $f2] |
| 268 | + est: (rows=20) |
| 269 | + Project |
| 270 | + fieldNames: [C1, C2, $f2, $f3] |
| 271 | + projection: [X, X, =(MOD(X, 2), 1), /(X, 2)] |
| 272 | + est: (rows=100) |
| 273 | + TableFunctionScan |
| 274 | + fieldNames: [X] |
| 275 | + invocation: SYSTEM_RANGE(1, 10) |
| 276 | + est: (rows=100) |
0 commit comments