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

[YSQL] INSERT ... ON CONFLICT feature is not working for TEMP tables. #2061

Closed
nocaway opened this issue Aug 14, 2019 · 1 comment
Closed
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@nocaway
Copy link
Contributor

nocaway commented Aug 14, 2019

Jira Link: DB-1400
Test cases

Two rows instead of one was inserted in the following test.

postgres=# create temporary table selfconflict (f1 int primary key, f2 int);
CREATE TABLE
postgres=# begin transaction isolation level read committed;
BEGIN
postgres=# insert into selfconflict values (1,1), (1,2) on conflict do nothing;
INSERT 0 2
postgres=# commit;
COMMIT

The CORRECT behavior for TEMP table should have been the following.

test=# create temp table selfconflict (f1 int primary key, f2 int);
CREATE TABLE
test=# begin transaction isolation level read committed;
BEGIN
test=# insert into selfconflict values (1,1), (1,2) on conflict do nothing;
INSERT 0 1
test=# commit;
COMMIT
test=# 
test=# begin transaction isolation level repeatable read;
BEGIN
test=# insert into selfconflict values (2,1), (2,2) on conflict do nothing;
INSERT 0 1
test=# commit;
COMMIT
test=# 
test=# begin transaction isolation level serializable;
BEGIN
test=# insert into selfconflict values (3,1), (3,2) on conflict do nothing;
INSERT 0 1
test=# commit;
COMMIT
test=# 
test=# begin transaction isolation level read committed;
BEGIN
test=# insert into selfconflict values (4,1), (4,2) on conflict(f1) do update set f2 = 0;
ERROR:  ON CONFLICT DO UPDATE command cannot affect row a second time
HINT:  Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
test=# commit;
ROLLBACK
test=# 
test=# begin transaction isolation level repeatable read;
BEGIN
test=# insert into selfconflict values (5,1), (5,2) on conflict(f1) do update set f2 = 0;
ERROR:  ON CONFLICT DO UPDATE command cannot affect row a second time
HINT:  Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
test=# commit;
ROLLBACK
test=# 
test=# begin transaction isolation level serializable;
BEGIN
test=# insert into selfconflict values (6,1), (6,2) on conflict(f1) do update set f2 = 0;
ERROR:  ON CONFLICT DO UPDATE command cannot affect row a second time
HINT:  Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
test=# commit;
ROLLBACK
test=# 
test=# select * from selfconflict order by f1;
 f1 | f2 
----+----
  1 |  1
  2 |  1
  3 |  1
(3 rows)
@nocaway nocaway added kind/bug This issue is a bug area/ysql Yugabyte SQL (YSQL) labels Aug 14, 2019
@nocaway nocaway self-assigned this Aug 14, 2019
@m-iancu m-iancu added this to YQL-beta Nov 30, 2021
@yugabyte-ci yugabyte-ci added the priority/medium Medium priority issue label Jun 8, 2022
@jasonyb
Copy link
Contributor

jasonyb commented Aug 6, 2024

Appears to work on master e0629f3, fastdebug, almalinux 8, gcc11

@jasonyb jasonyb closed this as completed Aug 6, 2024
@github-project-automation github-project-automation bot moved this to Done in YQL-beta Aug 6, 2024
jasonyb pushed a commit that referenced this issue Aug 9, 2024
Summary:
INSERT ON CONFLICT for temp tables is buggy, as shown by the issue #1999
example (same as arr_pk_tbl example here).  The cause appears to be
several uses of IsYugaByteEnabled where IsYBRelation should be used.
Make those changes and find the repro is resolved.  Also change one
instance of IsYBBackedRelation to IsYBRelation.  See related pg15 commit
a87fee2.

For tests, move the yb_pg_arrays test case to yb_dml_insert_conflict,
and add the previously buggy test case to yb_pg_arrays.  Also, though
this didn't fail before, add issue #2061 test case to
yb_dml_insert_conflict.
Jira: DB-1858

Test Plan:
On Almalinux 8:

    ./yb_build.sh fastdebug --gcc11 --java-test TestPgRegressDml
    ./yb_build.sh fastdebug --gcc11 --java-test TestPgRegressArrays

Close: #1999

Reviewers: aagrawal

Reviewed By: aagrawal

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D37104
jasonyb pushed a commit that referenced this issue Aug 12, 2024
…FLICT

Summary:
Merge:
f69b08f

- nodeModifyTable.c:
  - ExecOnConflictUpdate
    - goto yb_skip_transaction_control_check: false conflict between YB
      pg15 a87fee2 and YB master
      f69b08f.  Keep pg15 version.
    - yb_skip_transaction_control_check: conflict between same commits.
      Keep pg15 version.
    - ExecQual: conflict between same commits plus upstream PG
      277cb789836b5ddf81aabb80c2058268c70e2f36.  Keep pg15 version.
    - (end of function): same.

INSERT ON CONFLICT for temp tables is buggy, as shown by the issue #1999
example (same as arr_pk_tbl example here).  The cause appears to be
several uses of IsYugaByteEnabled where IsYBRelation should be used.
Make those changes and find the repro is resolved.  Also change one
instance of IsYBBackedRelation to IsYBRelation.  See related pg15 commit
a87fee2.

For tests, move the yb_pg_arrays test case to yb_dml_insert_conflict,
and add the previously buggy test case to yb_pg_arrays.  Also, though
this didn't fail before, add issue #2061 test case to
yb_dml_insert_conflict.
Jira: DB-1858

Test Plan:
On Almalinux 8:

    ./yb_build.sh fastdebug --gcc11 --java-test TestPgRegressDml
    ./yb_build.sh fastdebug --gcc11 --java-test TestPgRegressArrays

Jenkins: rebase: pg15-cherrypicks

Reviewers: aagrawal

Reviewed By: aagrawal

Subscribers: yql

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D37220
@github-project-automation github-project-automation bot moved this to Done in YSQL Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
Status: Done
Status: Done
Development

No branches or pull requests

3 participants