Skip to content

[YSQL] Deleted row count reported is incorrect when using DELETE with USING clause #25305

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

Open
1 task done
kmuthukk opened this issue Dec 15, 2024 · 0 comments · May be fixed by #26524
Open
1 task done

[YSQL] Deleted row count reported is incorrect when using DELETE with USING clause #25305

kmuthukk opened this issue Dec 15, 2024 · 0 comments · May be fixed by #26524
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@kmuthukk
Copy link
Collaborator

kmuthukk commented Dec 15, 2024

Jira Link: DB-14503

Description

Test Case:

create extension if not exists pgcrypto;
drop table if exists funds;

-- creating a table with duplicate values for k.
create table funds(k integer, u uuid default gen_random_uuid(), v integer);

insert into funds(k, v) values (1, 1);
insert into funds(k, v) values (1, 1);
insert into funds(k, v) values (1, 1);

-- deduplicate rows with same k. Keep only the one with largest value of u.
delete from funds f1
      using funds f2
   where f1.u < f2.u and f1.k = f2.k;

select * from funds;

We would expect the DELETE to delete two rows, but it seems to be reporting an incorrect number of rows (3).

delete from funds f1
      using funds f2
   where f1.u < f2.u and f1.k = f2.k;
DELETE 3

It seems to be just a reporting mistake. Because table does seem to have 1 remaining row left and only 2 rows seem to have gotten deleted.

select * from funds;
 k |                  u                   | v
---+--------------------------------------+---
 1 | bb7e5ed3-2cf8-45be-8c3e-e568c7e8b4ba | 1

Issue Type

kind/bug

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.
@kmuthukk kmuthukk added area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Dec 15, 2024
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Dec 15, 2024
@sushantrmishra sushantrmishra removed the status/awaiting-triage Issue awaiting triage label Jan 3, 2025
Francisco-Morao added a commit to Francisco-Morao/yugabyte-db-fork that referenced this issue Mar 24, 2025
Summary:
This commit fixes an issue where the deleted row count was incorrect
when using the USING clause. The problem was caused by the
target_tuple_fetched variable always being set to true, preventing
rows_affected_count from updating correctly and skipping the break
statement. As a result,es_processed was not incremented as expected.

Changes:
1. Fixed the incorrect row count issue by ensuring target_tuple_fetched
is set correctly.
2.Added a Java test (TestPgDelete) to verify the fix.

Fixes yugabyte#25305

Test Plan:
Added a Java test (TestPgDelete), which now passes successfully.
@Francisco-Morao Francisco-Morao linked a pull request Mar 24, 2025 that will close this issue
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
None yet
Development

Successfully merging a pull request may close this issue.

3 participants