forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf3d3118
committed
Support GROUPING SETS, CUBE and ROLLUP.
This SQL standard functionality allows to aggregate data by differentGROUP BY clauses at once. Each grouping set returns rows with columnsgrouped by in other sets set to NULL.This could previously be achieved by doing each grouping as a separatequery, conjoined by UNION ALLs. Besides being considerably more concise,grouping sets will in many cases be faster, requiring only one scan overthe underlying data.The current implementation of grouping sets only supports using sortingfor input. Individual sets that share a sort order are computed in onepass. If there are sets that don't share a sort order, additional sort &aggregation steps are performed. These additional passes are sourced bythe previous sort step; thus avoiding repeated scans of the source data.The code is structured in a way that adding support for purely usinghash aggregation or a mix of hashing and sorting is possible. Sortingwas chosen to be supported first, as it is the most generic method ofimplementation.Instead of, as in an earlier versions of the patch, representing thechain of sort and aggregation steps as full blown planner and executornodes, all but the first sort are performed inside the aggregation nodeitself. This avoids the need to do some unusual gymnastics to handlehaving to return aggregated and non-aggregated tuples from underlyingnodes, as well as having to shut down underlying nodes early to limitmemory usage. The optimizer still builds Sort/Agg node to describe eachphase, but they're not part of the plan tree, but instead additionaldata for the aggregation node. They're a convenient and preexisting wayto describe aggregation and sorting. The first (and possibly only) sortstep is still performed as a separate execution step. That retainssimilarity with existing group by plans, makes rescans fairly simple,avoids very deep plans (leading to slow explains) and easily allows toavoid the sorting step if the underlying data is sorted by other means.A somewhat ugly side of this patch is having to deal with a grammarambiguity between the new CUBE keyword and the cube extension/functionsnamed cube (and rollup). To avoid breaking existing deployments of thecube extension it has not been renamed, neither has cube been made areserved keyword. Instead precedence hacking is used to make GROUP BYcube(..) refer to the CUBE grouping sets feature, and not the functioncube(). To actually group by a function cube(), unlikely as that mightbe, the function name has to be quoted.Needs a catversion bump because stored rules may change.Author: Andrew Gierth and Atri Sharma, with contributions from Andres FreundReviewed-By: Andres Freund, Noah Misch, Tom Lane, Svenne Krap, Tomas Vondra, Erik Rijkers, Marti Raudsepp, Pavel StehuleDiscussion: CAOeZVidmVRe2jU6aMk_5qkxnB7dfmPROzM7Ur8JPW5j8Y5X-Lw@mail.gmail.com1 parent6e4415c commitf3d3118
File tree
63 files changed
+5245
-608
lines changed- contrib/pg_stat_statements
- doc/src/sgml
- ref
- src
- backend
- catalog
- commands
- executor
- lib
- nodes
- optimizer
- path
- plan
- prep
- util
- parser
- rewrite
- utils/adt
- include
- catalog
- commands
- lib
- nodes
- optimizer
- parser
- utils
- test/regress
- expected
- sql
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
63 files changed
+5245
-608
lines changedLines changed: 21 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2267 | 2267 |
| |
2268 | 2268 |
| |
2269 | 2269 |
| |
| 2270 | + | |
2270 | 2271 |
| |
2271 | 2272 |
| |
2272 | 2273 |
| |
| |||
2397 | 2398 |
| |
2398 | 2399 |
| |
2399 | 2400 |
| |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
2400 | 2408 |
| |
2401 | 2409 |
| |
2402 | 2410 |
| |
| |||
2698 | 2706 |
| |
2699 | 2707 |
| |
2700 | 2708 |
| |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
2701 | 2715 |
| |
2702 | 2716 |
| |
2703 | 2717 |
| |
| |||
2708 | 2722 |
| |
2709 | 2723 |
| |
2710 | 2724 |
| |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
2711 | 2732 |
| |
2712 | 2733 |
| |
2713 | 2734 |
| |
|
Lines changed: 69 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
12228 | 12228 |
| |
12229 | 12229 |
| |
12230 | 12230 |
| |
12231 |
| - | |
| 12231 | + | |
| 12232 | + | |
| 12233 | + | |
12232 | 12234 |
| |
12233 | 12235 |
| |
12234 | 12236 |
| |
| |||
13326 | 13328 |
| |
13327 | 13329 |
| |
13328 | 13330 |
| |
| 13331 | + | |
| 13332 | + | |
| 13333 | + | |
| 13334 | + | |
| 13335 | + | |
| 13336 | + | |
| 13337 | + | |
| 13338 | + | |
| 13339 | + | |
| 13340 | + | |
| 13341 | + | |
| 13342 | + | |
| 13343 | + | |
| 13344 | + | |
| 13345 | + | |
| 13346 | + | |
| 13347 | + | |
| 13348 | + | |
| 13349 | + | |
| 13350 | + | |
| 13351 | + | |
| 13352 | + | |
| 13353 | + | |
| 13354 | + | |
| 13355 | + | |
| 13356 | + | |
| 13357 | + | |
| 13358 | + | |
| 13359 | + | |
| 13360 | + | |
| 13361 | + | |
| 13362 | + | |
| 13363 | + | |
| 13364 | + | |
| 13365 | + | |
| 13366 | + | |
| 13367 | + | |
| 13368 | + | |
| 13369 | + | |
| 13370 | + | |
| 13371 | + | |
| 13372 | + | |
| 13373 | + | |
| 13374 | + | |
| 13375 | + | |
| 13376 | + | |
| 13377 | + | |
| 13378 | + | |
| 13379 | + | |
| 13380 | + | |
| 13381 | + | |
| 13382 | + | |
| 13383 | + | |
| 13384 | + | |
| 13385 | + | |
| 13386 | + | |
| 13387 | + | |
| 13388 | + | |
| 13389 | + | |
| 13390 | + | |
| 13391 | + | |
| 13392 | + | |
| 13393 | + | |
| 13394 | + | |
| 13395 | + | |
| 13396 | + | |
13329 | 13397 |
| |
13330 | 13398 |
| |
13331 | 13399 |
| |
|
Lines changed: 175 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1183 | 1183 |
| |
1184 | 1184 |
| |
1185 | 1185 |
| |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
1186 | 1361 |
| |
1187 | 1362 |
| |
1188 | 1363 |
| |
|
Lines changed: 27 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
37 | 37 |
| |
38 | 38 |
| |
39 | 39 |
| |
40 |
| - | |
| 40 | + | |
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
| |||
60 | 60 |
| |
61 | 61 |
| |
62 | 62 |
| |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
63 | 72 |
| |
64 | 73 |
| |
65 | 74 |
| |
| |||
665 | 674 |
| |
666 | 675 |
| |
667 | 676 |
| |
668 |
| - | |
| 677 | + | |
669 | 678 |
| |
670 | 679 |
| |
671 | 680 |
| |
672 | 681 |
| |
673 | 682 |
| |
674 | 683 |
| |
675 |
| - | |
676 |
| - | |
677 |
| - | |
678 |
| - | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
679 | 689 |
| |
680 | 690 |
| |
681 | 691 |
| |
682 | 692 |
| |
683 | 693 |
| |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
684 | 705 |
| |
685 | 706 |
| |
686 | 707 |
| |
|
Lines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
467 | 467 |
| |
468 | 468 |
| |
469 | 469 |
| |
470 |
| - | |
471 |
| - | |
472 |
| - | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
473 | 473 |
| |
474 | 474 |
| |
475 | 475 |
| |
|
0 commit comments
Comments
(0)