Allow Incremental Sorts on GiST and SP-GiST indexes
authorDavid Rowley <drowley@postgresql.org>
Tue, 4 Jul 2023 11:08:52 +0000 (23:08 +1200)
committerDavid Rowley <drowley@postgresql.org>
Tue, 4 Jul 2023 11:08:52 +0000 (23:08 +1200)
commit625d5b3ca0968c1d8c080d5210f7209184c0d134
treea62d35b28f4aafd61a3db6a45c504ff38409d72c
parent28b5726561841556dc3e00ffe26b01a8107ee654
Allow Incremental Sorts on GiST and SP-GiST indexes

Previously an "amcanorderbyop" index would only be used when the index
could provide sorted results which satisfied all query_pathkeys.  Here
we relax this so that we also allow these indexes to be considered by the
planner when they only provide partially sorted results.  This allows the
planner to later consider making use of an Incremental Sort to satisfy the
remaining pathkeys.  This change is particularly useful for KNN-type
queries which contain a LIMIT clause and an additional ORDER BY clause for
a non-indexed column.

Author: Miroslav Bendik
Reviewed-by: Richard Guo, David Rowley
Discussion: http://postgr.es/m/CAPoEpV0QYDtzjwamwWUBqyWpaCVbJV2d6qOD7Uy09bWn47PJtw%40mail.gmail.com
src/backend/optimizer/path/indxpath.c
src/test/regress/expected/incremental_sort.out
src/test/regress/sql/incremental_sort.sql