forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitd2d8a22
committed
Implement Incremental Sort
Incremental Sort is an optimized variant of multikey sort for cases whenthe input is already sorted by a prefix of the requested sort keys. Forexample when the relation is already sorted by (key1, key2) and we needto sort it by (key1, key2, key3) we can simply split the input rows intogroups having equal values in (key1, key2), and only sort/compare theremaining column key3.This has a number of benefits:- Reduced memory consumption, because only a single group (determined by values in the sorted prefix) needs to be kept in memory. This may also eliminate the need to spill to disk.- Lower startup cost, because Incremental Sort produce results after each prefix group, which is beneficial for plans where startup cost matters (like for example queries with LIMIT clause).We consider both Sort and Incremental Sort, and decide based on costing.The implemented algorithm operates in two different modes:- Fetching a minimum number of tuples without check of equality on the prefix keys, and sorting on all columns when safe.- Fetching all tuples for a single prefix group and then sorting by comparing only the remaining (non-prefix) keys.We always start in the first mode, and employ a heuristic to switch intothe second mode if we believe it's beneficial - the goal is to minimizethe number of unnecessary comparions while keeping memory consumptionbelow work_mem.This is a very old patch series. The idea was originally proposed byAlexander Korotkov back in 2013, and then revived in 2017. In 2018 thepatch was taken over by James Coleman, who wrote and rewrote most of thecurrent code.There were many reviewers/contributors since 2013 - I've done my best topick the most active ones, and listed them in this commit message.Author: James Coleman, Alexander KorotkovReviewed-by: Tomas Vondra, Andreas Karlsson, Marti Raudsepp, Peter Geoghegan, Robert Haas, Thomas Munro, Antonin Houska, Andres Freund, Alexander KuzmenkovDiscussion:https://postgr.es/m/CAPpHfdscOX5an71nHd8WSUH6GNOCf=V7wgDaTXdDd9=goN-gfA@mail.gmail.comDiscussion:https://postgr.es/m/CAPpHfds1waRZ=NOmueYq0sx1ZSCnt+5QJvizT8ndT2=etZEeAQ@mail.gmail.com1 parent3c85535 commitd2d8a22
File tree
41 files changed
+4239
-155
lines changed- doc/src/sgml
- src
- backend
- commands
- executor
- nodes
- optimizer
- path
- plan
- util
- utils
- misc
- sort
- include
- executor
- nodes
- optimizer
- utils
- test
- isolation/expected
- 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.
41 files changed
+4239
-155
lines changedLines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4573 | 4573 |
| |
4574 | 4574 |
| |
4575 | 4575 |
| |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
| 4581 | + | |
| 4582 | + | |
| 4583 | + | |
| 4584 | + | |
| 4585 | + | |
| 4586 | + | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + | |
4576 | 4590 |
| |
4577 | 4591 |
| |
4578 | 4592 |
| |
|
Lines changed: 41 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
291 | 291 |
| |
292 | 292 |
| |
293 | 293 |
| |
294 |
| - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
295 | 335 |
| |
296 | 336 |
| |
297 | 337 |
| |
|
0 commit comments
Comments
(0)