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: #7088: Fix leaks with functions in DML #7090

Closed timescale-automation closed 4 days ago

timescale-automation commented 5 days ago

This is an automated backport of #7088: Fix leaks with functions in DML. The original issue is #7053. 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 leaks with functions in DML

If plpgsql functions are used in DML queries then we were leaking 8KB for every invocation of that function. This can quickly add up.

The issue was that the "CurTransactionContext" was not getting cleaned up after every invocation. The reason was that we were inadvertantly allocating a temporary list in that context. Postgres then thought that this CurTransactionContext needs to be re-used further and kept it around. We now use a proper memory context to avoid this.

Fixes #7053