Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leaks with functions in DML #7088

Merged
merged 1 commit into from
Jul 2, 2024
Merged

Conversation

nikkhils
Copy link
Contributor

@nikkhils nikkhils commented Jul 2, 2024

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

@nikkhils nikkhils requested review from mkindahl, svenklemm and akuzm July 2, 2024 07:27
@nikkhils nikkhils self-assigned this Jul 2, 2024
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 timescale#7053
Copy link

codecov bot commented Jul 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.82%. Comparing base (59f50f2) to head (73a8ff9).
Report is 235 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7088      +/-   ##
==========================================
+ Coverage   80.06%   81.82%   +1.76%     
==========================================
  Files         190      200      +10     
  Lines       37181    37323     +142     
  Branches     9450     9738     +288     
==========================================
+ Hits        29770    30541     +771     
+ Misses       2997     2873     -124     
+ Partials     4414     3909     -505     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nikkhils nikkhils added this to the TimescaleDB 2.15.3 milestone Jul 2, 2024
@nikkhils nikkhils enabled auto-merge (rebase) July 2, 2024 07:58
@nikkhils nikkhils merged commit ebbca2d into timescale:main Jul 2, 2024
40 checks passed
@nikkhils nikkhils deleted the plpgsql_leak branch July 2, 2024 08:05
@pallavisontakke pallavisontakke added auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) backported-2.15.x labels Jul 2, 2024
pallavisontakke added a commit to pallavisontakke/timescaledb that referenced this pull request Jul 2, 2024
For PRs timescale#7088 and timescale#7035
Some more edits for docs compliance.
@pallavisontakke pallavisontakke mentioned this pull request Jul 2, 2024
pallavisontakke added a commit that referenced this pull request Jul 2, 2024
This release contains bug fixes since the 2.15.2 release.
Best practice is to upgrade at the next available opportunity.

**Migrating from self-hosted TimescaleDB v2.14.x and earlier**

After you run `ALTER EXTENSION`, you must run [this SQL
script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql).
For more details, see the following pull request
[#6797](#6797).

If you are migrating from TimescaleDB v2.15.0, v2.15.1 or v2.15.2, no
changes are required.

**Bugfixes**
* #7061: Fix the handling of multiple unique indexes in a compressed
INSERT.
* #7080: Fix the `corresponding equivalence member not found` error.
* #7088: Fix the leaks in the DML functions.
* #7035: Fix the error when acquiring a tuple lock on the OSM chunks on
the replica.

**Thanks**
* @Kazmirchuk for reporting the issue about leaks with the functions in
DML.
pallavisontakke added a commit to pallavisontakke/timescaledb that referenced this pull request Jul 2, 2024
This release contains performance improvements and bug fixes since
the 2.15.2 release. Best practice is to upgrade at the next
available opportunity.

**Features**

**Bugfixes**
* timescale#7061 Fix handling of multiple unique indexes in compressed INSERT
* timescale#7080 Fix `corresponding equivalence member not found` error
* timescale#7088 Fix leaks with functions in DML

**Thanks**
* @Kazmirchuk for reporting this
@pallavisontakke pallavisontakke mentioned this pull request Jul 2, 2024
svenklemm pushed a commit to pallavisontakke/timescaledb that referenced this pull request Jul 2, 2024
This release contains performance improvements and bug fixes since
the 2.15.2 release. Best practice is to upgrade at the next
available opportunity.

**Features**

**Bugfixes**
* timescale#7061 Fix handling of multiple unique indexes in compressed INSERT
* timescale#7080 Fix `corresponding equivalence member not found` error
* timescale#7088 Fix leaks with functions in DML

**Thanks**
* @Kazmirchuk for reporting this
svenklemm added a commit that referenced this pull request Jul 2, 2024
This release contains bug fixes since the 2.15.2 release.
Best practice is to upgrade at the next available opportunity.

**Migrating from self-hosted TimescaleDB v2.14.x and earlier**

After you run `ALTER EXTENSION`, you must run [this SQL
script](https://github.com/timescale/timescaledb-extras/blob/master/utils/2.15.X-fix_hypertable_foreign_keys.sql).
For more details, see the following pull request
[#6797](#6797).

If you are migrating from TimescaleDB v2.15.0, v2.15.1 or v2.15.2, no
changes are required.

**Bugfixes**
* #7061: Fix the handling of multiple unique indexes in a compressed
INSERT.
* #7080: Fix the `corresponding equivalence member not found` error.
* #7088: Fix the leaks in the DML functions.
* #7035: Fix the error when acquiring a tuple lock on the OSM chunks on
the replica.
* #7091: Fix ORDER BY/GROUP BY expression not found in targetlist on
PG16

**Thanks**
* @Kazmirchuk for reporting the issue about leaks with the functions in
DML.

---------

Signed-off-by: Sven Klemm <31455525+svenklemm@users.noreply.github.com>
Co-authored-by: Sven Klemm <31455525+svenklemm@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) backported-2.15.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

INSERT INTO hypertable using a PL/pgSQL function results in high RAM usage
4 participants