Skip to content

Commit

Permalink
fix: deletion with sub query (#11834)
Browse files Browse the repository at this point in the history
* fix: deletion with subquery

remove the `row_id_col` column before performing row deletions

* fix typo

* fix typo in sqllogic test case

* fix sqllogic test case 03_0035_update
  • Loading branch information
dantengsky authored Jun 21, 2023
1 parent 8c2305b commit 282d392
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ impl Processor for MutationSource {
};

if affect_rows != 0 {
// Pop the row_id column
if self.query_row_id_col {
data_block = data_block.pop_columns(1)?;
}

let progress_values = ProgressValues {
rows: affect_rows,
bytes: 0,
Expand Down Expand Up @@ -261,10 +266,6 @@ impl Processor for MutationSource {
}
}
MutationAction::Update => {
// Pop the row_id column
if self.query_row_id_col {
data_block = data_block.pop_columns(1)?;
}
if self.remain_reader.is_none() {
data_block.add_column(BlockEntry::new(
DataType::Boolean,
Expand Down
51 changes: 50 additions & 1 deletion tests/sqllogictests/suites/mode/cluster/distributed_delete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,53 @@ select (select sum(c1) from t_origin where id % 3 != 0 or id <= 500) = (select s
query I
select (select sum(c2) from t_origin where id % 3 != 0 or id <= 500) = (select sum(c2) from t);
----
1
1

# for issue #11784 https://github.com/datafuselabs/databend/issues/11784

statement ok
drop table if exists t;

statement ok
drop table if exists del_id;

statement ok
create table t (id int, c1 int, c2 int) row_per_block=3;

statement ok
insert into t select number, number * 5, number * 7 from numbers(50);

statement ok
create table del_id (id int) as select cast(FLOOR(0 + RAND(number) * 50), int) from numbers(10);

statement ok
delete from t where id in (select id from del_id);

statement ok
create view v_after_deletion as select number as id, number * 5 as c1, number * 7 as c2 from numbers(50) where id not in (select * from del_id);

query III
select * from v_after_deletion order by id except select * from t order by id;
----

query III
select * from t order by id except select * from v_after_deletion order by id;
----

query I
select (select count() from v_after_deletion) = (select count() from t);
----
1

statement ok
drop table t;

statement ok
drop view v_after_deletion;

statement ok
drop table if exists del_id;




1 comment on commit 282d392

@vercel
Copy link

@vercel vercel bot commented on 282d392 Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-databend.vercel.app
databend.vercel.app
databend-git-main-databend.vercel.app
databend.rs

Please sign in to comment.