-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[YSQL] Updating a row more than once in different parts of a wCTE fails #6782
Comments
Summary: In #6511, it was pointed out that in the following example: ``` with a as ( select 1 as k) delete from t where k in (select k from a); ``` we throw the following warning: ``` WARNING: 0A000: WITH clause not supported yet LINE 1: with a as ( ^ HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues LOCATION: raise_feature_not_supported_signal, gram.y:17327 ``` However, we do support WITH clause, and this warning notwithstanding, the delete does go through fine. As part of this change, removed this warning message, and also imported PG tests for WITH clause. The imported PG tests have the following major changes: 1) Temporary tables have been replaced by normal tables due to #6783 2) Disabled the failing for test for updating a row more than once in different parts of a wCTE, will be handled separately in #6782 Test Plan: ybd --scb --sj --java-test org.yb.pgsql.TestPgRegressWithClause Reviewers: mihnea, neil Reviewed By: neil Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D10257
Summary: In yugabyte#6511, it was pointed out that in the following example: ``` with a as ( select 1 as k) delete from t where k in (select k from a); ``` we throw the following warning: ``` WARNING: 0A000: WITH clause not supported yet LINE 1: with a as ( ^ HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues LOCATION: raise_feature_not_supported_signal, gram.y:17327 ``` However, we do support WITH clause, and this warning notwithstanding, the delete does go through fine. As part of this change, removed this warning message, and also imported PG tests for WITH clause. The imported PG tests have the following major changes: 1) Temporary tables have been replaced by normal tables due to yugabyte#6783 2) Disabled the failing for test for updating a row more than once in different parts of a wCTE, will be handled separately in yugabyte#6782 Test Plan: ybd --scb --sj --java-test org.yb.pgsql.TestPgRegressWithClause Reviewers: mihnea, neil Reviewed By: neil Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D10257
Found this existing issue after already doing a separate analysis: When studying fields in
Repro 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
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); Repro B: drop table if exists a;
create table a (i int unique);
insert into a values (1), (2);
EXPLAIN
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); Repro C: drop table if exists a;
create table a (i int unique);
insert into a values (1), (2), (3);
EXPLAIN
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); With repro A, I found the tuple it is complaining about is table
And the explain is
The logic is to first
It did not look like there is an issue of cross-contamination between on-conflict-do-update plans since the slot stored into Perhaps |
This issue is now only about the incorrect (as in different from vanilla PG) output
TupleDesc reference leak is tracked in #23429. |
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
…eDesc ref leak Summary: MERGE: efd4cb7 YB pg15 initial merge refers to 55782d5. - execIndexing.c: - function declarations: YB master efd4cb7 adds ybConflictSlot parameter; upstream PG changes indentation. - nodeModifyTable.c: - function declarations: (same). - ExecCheckIndexConstraints function call: YB master efd4cb7 adds ybConflictSlot parameter; upstream PG a04daa97a4339c38e304cd6164d37da540d665a8 adds resultRelInfo. - ExecOnConflictUpdate function call: YB master efd4cb7 adds ybConflictSlot parameter; upstream PG 25e777cf8e547d7423d2e1e9da71f98b9414d59e also touches parameters. - yb_skip_transaction_control_check: YB master efd4cb7 changes estate->yb_conflict_slot to ybConflictSlot and adds corresponding assert. YB pg15 initial merge flips if and else cases, causing merge to get confused. Carefully apply the same logic formerly in the if case now to the else case. - executor.h: - function declarations: (same as execIndexing.c). - yb_pg_with.out, yb_pg_with.sql: - Update a row more than once: YB pg15 b68a24e adds "YB" to a comment, and YB master efd4cb7 deletes that comment. Delete. 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' Jenkins: rebase: pg15-cherrypicks Reviewers: kramanathan, aagrawal Reviewed By: aagrawal Subscribers: yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D37248
Jira Link: DB-1751
While enabling Postgres regression tests for with clause, the following test fails.
Pre-test
Failing test:
The above should return 0 rows, but in YDB cluster, see the following output:
The text was updated successfully, but these errors were encountered: