]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix CLUSTER tuplesorts on abbreviated expressions.
authorPeter Geoghegan <pg@bowt.ie>
Thu, 21 Apr 2022 00:17:37 +0000 (17:17 -0700)
committerPeter Geoghegan <pg@bowt.ie>
Thu, 21 Apr 2022 00:17:37 +0000 (17:17 -0700)
commit5487585e376dd25d2cabc8a63a33c0286b3a199c
treef37052f62b64077459b5a623e64c672d1aedaecf
parent33fe55c06b83ea428429f5d522e474fbbe4ab655
Fix CLUSTER tuplesorts on abbreviated expressions.

CLUSTER sort won't use the datum1 SortTuple field when clustering
against an index whose leading key is an expression.  This makes it
unsafe to use the abbreviated keys optimization, which was missed by the
logic that sets up SortSupport state.  Affected tuplesorts output tuples
in a completely bogus order as a result (the wrong SortSupport based
comparator was used for the leading attribute).

This issue is similar to the bug fixed on the master branch by recent
commit cc58eecc5d.  But it's a far older issue, that dates back to the
introduction of the abbreviated keys optimization by commit 4ea51cdfe8.

Backpatch to all supported versions.

Author: Peter Geoghegan <pg@bowt.ie>
Author: Thomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/CA+hUKG+bA+bmwD36_oDxAoLrCwZjVtST2fqe=b4=qZcmU7u89A@mail.gmail.com
Backpatch: 10-
src/backend/utils/sort/tuplesort.c
src/test/regress/expected/cluster.out
src/test/regress/sql/cluster.sql