timescale / timescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
https://www.timescale.com/
Other
16.83k stars 852 forks source link

Backport to 2.15.x: #7080: Fix `corresponding equivalence member not found` #7083

Closed timescale-automation closed 5 days ago

timescale-automation commented 5 days ago

This is an automated backport of #7080: Fix corresponding equivalence member not found. This PR will be merged automatically after all the relevant CI checks pass. If this fix should not be backported, or will be backported manually, just close this PR. You can use the backport branch to add your changes, it won't be modified automatically anymore.

For more details, please see the documentation

Original description

Fix corresponding equivalence member not found

When querying compressed data we determine whether the requested ORDER can be applied to the underlying query on the compressed data itself. This happens twice. The first time we decide whether we can push down the sort and then we do a recheck when we setup the sort metadata. Unfortunately those two checks did not agree. The initial check concluded it is possible but the recheck disagreed. This was due to a bug when checking the query properties we mixed up the attnos and used attnos from uncompressed chunk and compressed chunk in the same bitmapset. If a segmentby column with equality constraint was present in the WHERE clause whose attno was identical to a compressed attno of a different column that was part of the ORDER BY the recheck would fail.

This patch removes the recheck and relies on the initial assesment when building sort metadata.