forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3226f47
committed
Add enable_presorted_aggregate GUC
1349d27 added query planner support to allow more efficient execution ofaggregate functions which have an ORDER BY or a DISTINCT clause. Prior tothat commit, the planner would only request that the lower planner producea plan with the order required for the GROUP BY clause and it would beleft up to nodeAgg.c to perform the final sort of records within eachgroup so that the aggregate transition functions were called in thecorrect order. Now that the planner requests the lower planner produce aplan with the GROUP BY and the ORDER BY / DISTINCT aggregates in mind,there is the possibility that the planner chooses a plan which could beless efficient than what would have been produced before1349d27.While developing1349d27, I had in mind that Incremental Sort would helpus in cases where an index exists only on the GROUP BY column(s).Incremental Sort would just replace the implicit tuplesorts which arebeing performed in nodeAgg.c. However, because the planner has theflexibility to instead choose a plan which just performs a full sort onboth the GROUP BY and ORDER BY / DISTINCT aggregate columns, there ispotential for the planner to make a bad choice. The costing forIncremental Sort is not perfect as it assumes an even distribution of rowsto sort within each sort group.Here we add an escape hatch in the form of the enable_presorted_aggregateGUC. This will allow users to get the pre-PG16 behavior in cases wherethey have no other means to convince the query planner to produce a planwhich only sorts on the GROUP BY column(s).Discussion:https://postgr.es/m/CAApHDvr1Sm+g9hbv4REOVuvQKeDWXcKUAhmbK5K+dfun0s9CvA@mail.gmail.com1 parentd21ded7 commit3226f47
File tree
9 files changed
+62
-2
lines changed- doc/src/sgml
- src
- backend
- optimizer
- path
- plan
- utils/misc
- include/optimizer
- test/regress
- expected
- sql
9 files changed
+62
-2
lines changedLines changed: 23 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5311 | 5311 |
| |
5312 | 5312 |
| |
5313 | 5313 |
| |
| 5314 | + | |
| 5315 | + | |
| 5316 | + | |
| 5317 | + | |
| 5318 | + | |
| 5319 | + | |
| 5320 | + | |
| 5321 | + | |
| 5322 | + | |
| 5323 | + | |
| 5324 | + | |
| 5325 | + | |
| 5326 | + | |
| 5327 | + | |
| 5328 | + | |
| 5329 | + | |
| 5330 | + | |
| 5331 | + | |
| 5332 | + | |
| 5333 | + | |
| 5334 | + | |
| 5335 | + | |
| 5336 | + | |
5314 | 5337 |
| |
5315 | 5338 |
| |
5316 | 5339 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
151 | 151 |
| |
152 | 152 |
| |
153 | 153 |
| |
| 154 | + | |
154 | 155 |
| |
155 | 156 |
| |
156 | 157 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3191 | 3191 |
| |
3192 | 3192 |
| |
3193 | 3193 |
| |
3194 |
| - | |
| 3194 | + | |
| 3195 | + | |
3195 | 3196 |
| |
3196 | 3197 |
| |
3197 | 3198 |
| |
|
Lines changed: 15 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
971 | 971 |
| |
972 | 972 |
| |
973 | 973 |
| |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
974 | 989 |
| |
975 | 990 |
| |
976 | 991 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
384 | 384 |
| |
385 | 385 |
| |
386 | 386 |
| |
| 387 | + | |
387 | 388 |
| |
388 | 389 |
| |
389 | 390 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
68 | 68 |
| |
69 | 69 |
| |
70 | 70 |
| |
| 71 | + | |
71 | 72 |
| |
72 | 73 |
| |
73 | 74 |
| |
|
Lines changed: 11 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1471 | 1471 |
| |
1472 | 1472 |
| |
1473 | 1473 |
| |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
1474 | 1485 |
| |
1475 | 1486 |
| |
1476 | 1487 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
128 | 128 |
| |
129 | 129 |
| |
130 | 130 |
| |
| 131 | + | |
131 | 132 |
| |
132 | 133 |
| |
133 | 134 |
| |
134 |
| - | |
| 135 | + | |
135 | 136 |
| |
136 | 137 |
| |
137 | 138 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
546 | 546 |
| |
547 | 547 |
| |
548 | 548 |
| |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
549 | 555 |
| |
550 | 556 |
| |
551 | 557 |
| |
|
0 commit comments
Comments
(0)