-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#23429] YSQL: fix INSERT ON CONFLICT TupleDesc ref leak
Summary: Nested INSERT ON CONFLICT causes TupleDesc reference leak warning. The cause is obvious: both the outer and inner INSERT ON CONFLICT use the same estate->yb_conflict_slot: 1. outer: set estate->yb_conflict_slot 2. inner: set estate->yb_conflict_slot 3. inner: free estate->yb_conflict_slot 4. outer: free estate->yb_conflict_slot The slot allocated in (1) is not freed. Fix by removing yb_conflict_slot and using local variable ybConflictSlot and passing it through functions like PG's conflictTid. In future PG versions, resultRelInfo is local to the node, so maybe this can be put into resultRelInfo to reduce modifications to the functions signatures and make future merges easier. Add test coverage using examples from issue #6782. Jira: DB-12350 Test Plan: On Almalinux 8: ./yb_build.sh fastdebug --gcc11 --java-test TestPgRegressPgMisc ./yb_build.sh fastdebug --gcc11 --java-test 'TestPgRegressMisc#testPgRegressMiscSerial4' Close: #23429 Depends on D37104 Reviewers: kramanathan, aagrawal Reviewed By: aagrawal Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D37151
- Loading branch information
Showing
10 changed files
with
189 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* Test A */ | ||
drop table if exists a; | ||
NOTICE: table "a" does not exist, skipping | ||
drop table if exists b; | ||
NOTICE: table "b" does not exist, skipping | ||
create table a (i int unique); | ||
create table b (i int unique); | ||
insert into a values (1); | ||
insert into b values (2); | ||
EXPLAIN (costs off) | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
) insert into b values (2) on conflict on constraint b_i_key do update set i = (select 20 from w); | ||
QUERY PLAN | ||
--------------------------------------------- | ||
Insert on b | ||
Conflict Resolution: UPDATE | ||
Conflict Arbiter Indexes: b_i_key | ||
CTE w | ||
-> Insert on a | ||
Conflict Resolution: UPDATE | ||
Conflict Arbiter Indexes: a_i_key | ||
-> Result | ||
InitPlan 2 (returns $2) | ||
-> CTE Scan on w | ||
-> Result | ||
(11 rows) | ||
|
||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
) insert into b values (2) on conflict on constraint b_i_key do update set i = (select 20 from w); | ||
/* Test B */ | ||
drop table if exists a; | ||
create table a (i int unique); | ||
insert into a values (1), (2); | ||
EXPLAIN (costs off) | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
) insert into a values (2) on conflict on constraint a_i_key do update set i = (select 20 from w); | ||
QUERY PLAN | ||
--------------------------------------------- | ||
Insert on a | ||
Conflict Resolution: UPDATE | ||
Conflict Arbiter Indexes: a_i_key | ||
CTE w | ||
-> Insert on a a_1 | ||
Conflict Resolution: UPDATE | ||
Conflict Arbiter Indexes: a_i_key | ||
-> Result | ||
InitPlan 2 (returns $2) | ||
-> CTE Scan on w | ||
-> Result | ||
(11 rows) | ||
|
||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
) insert into a values (2) on conflict on constraint a_i_key do update set i = (select 20 from w); | ||
/* Test C */ | ||
drop table if exists a; | ||
create table a (i int unique); | ||
insert into a values (1), (2), (3); | ||
EXPLAIN (costs off) | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
), x(i) as ( | ||
insert into a values (2) on conflict on constraint a_i_key do update set i = 20 returning i | ||
) insert into a values (3) on conflict on constraint a_i_key do update set i = (select 30 from w); | ||
QUERY PLAN | ||
--------------------------------------------- | ||
Insert on a | ||
Conflict Resolution: UPDATE | ||
Conflict Arbiter Indexes: a_i_key | ||
CTE w | ||
-> Insert on a a_1 | ||
Conflict Resolution: UPDATE | ||
Conflict Arbiter Indexes: a_i_key | ||
-> Result | ||
CTE x | ||
-> Insert on a a_2 | ||
Conflict Resolution: UPDATE | ||
Conflict Arbiter Indexes: a_i_key | ||
-> Result | ||
InitPlan 3 (returns $4) | ||
-> CTE Scan on w | ||
-> Result | ||
(16 rows) | ||
|
||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
), x(i) as ( | ||
insert into a values (2) on conflict on constraint a_i_key do update set i = 20 returning i | ||
) insert into a values (3) on conflict on constraint a_i_key do update set i = (select 30 from w); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* Test A */ | ||
drop table if exists a; | ||
drop table if exists b; | ||
create table a (i int unique); | ||
create table b (i int unique); | ||
insert into a values (1); | ||
insert into b values (2); | ||
|
||
EXPLAIN (costs off) | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
) insert into b values (2) on conflict on constraint b_i_key do update set i = (select 20 from w); | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
) insert into b values (2) on conflict on constraint b_i_key do update set i = (select 20 from w); | ||
|
||
/* Test B */ | ||
drop table if exists a; | ||
create table a (i int unique); | ||
insert into a values (1), (2); | ||
|
||
EXPLAIN (costs off) | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
) insert into a values (2) on conflict on constraint a_i_key do update set i = (select 20 from w); | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
) insert into a values (2) on conflict on constraint a_i_key do update set i = (select 20 from w); | ||
|
||
/* Test C */ | ||
drop table if exists a; | ||
create table a (i int unique); | ||
insert into a values (1), (2), (3); | ||
|
||
EXPLAIN (costs off) | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
), x(i) as ( | ||
insert into a values (2) on conflict on constraint a_i_key do update set i = 20 returning i | ||
) insert into a values (3) on conflict on constraint a_i_key do update set i = (select 30 from w); | ||
with w(i) as ( | ||
insert into a values (1) on conflict on constraint a_i_key do update set i = 10 returning i | ||
), x(i) as ( | ||
insert into a values (2) on conflict on constraint a_i_key do update set i = 20 returning i | ||
) insert into a values (3) on conflict on constraint a_i_key do update set i = (select 30 from w); |
Oops, something went wrong.