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
17.61k stars 883 forks source link

Backport to 2.15.x: #6931: Do not decompress batches for COPY with potentially invalid slot #6946

Closed timescale-automation closed 4 months ago

timescale-automation commented 4 months ago

This is an automated backport of #6931: Do not decompress batches for COPY with potentially invalid slot. The original issue is #6540. 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

Do not decompress batches for COPY with potentially invalid slot

We don't have to decompress anything more when we re-lookup the chunk insert state on COPY buffer flush. Moreover, ChunkInsertState.slots[0] is incorrect slot type for decompress_batches_for_insert(), because it is a chunk slot, not a hypertable slot. This can lead to rare errors when the chunk insert states go out of cache.

Just don't do this unnecessary lookup, and move decompression to a separate function for clarity. Add an assertion and test that detect the slot type mismatch on main.

There was a related fix that improved the situation for empty copy buffers, but not for wrong slot type https://github.com/timescale/timescaledb/pull/6117

Fixes https://github.com/timescale/timescaledb/issues/6540