Skip to content

Commit

Permalink
fix: incorrect overlap checking (replace into) (#15315)
Browse files Browse the repository at this point in the history
* fix: incorrect overlap checking (replace into)

should return false if column being checked has no range index.

* revert default query node config

* add logic test

* chore: tweak code comments
  • Loading branch information
dantengsky committed Apr 24, 2024
1 parent 8c34082 commit 9c43f7c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ impl AggregationContext {
|| // coincide overlap
(max == key_max && min == key_min)
} else {
false
// if column range index does not exist, assume overlapped
true
}
}

Expand Down Expand Up @@ -949,6 +950,56 @@ mod tests {

assert!(!overlap);

// case 3: (column rang index not exist)
//
// - min/max of input block
//
// 'xx_id' : [11, 12]
// 'xx_type' : ["b", "b"]
// 'xx_time' : [100, 100]
//
// - the range index of columns are (after tweaks)
//
// 'xx_type' : ["a", "z"]
// 'xx_time' : [100, 200]
//
// - expected : overlap == true
//
// range index of column 'xx_id' does not exist (explicitly removed)
// the result should be overlapped

let input_column_min_max = [
// for xx_id column, NOT overlaps
(
Scalar::Number(NumberScalar::UInt64(11)),
Scalar::Number(NumberScalar::UInt64(12)),
),
// for xx_type column, overlaps
(
Scalar::String("b".to_string()),
Scalar::String("b".to_string()),
),
// for xx_time column, overlaps
(
Scalar::Number(NumberScalar::UInt32(100)),
Scalar::Number(NumberScalar::UInt32(100)),
),
];

let column_range_indexes = {
let mut cloned = column_range_indexes;
cloned.remove(&0); // remove range index of col xx_id
cloned
};

let overlap = super::AggregationContext::check_overlap(
&on_conflict_fields,
&column_range_indexes,
&input_column_min_max,
);

assert!(overlap);

Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
statement ok
DROP DATABASE IF EXISTS issue_15307

statement ok
CREATE DATABASE issue_15307

statement ok
USE issue_15307

# https://github.com/datafuselabs/databend/issues/15307

statement ok
create or replace table t( c1 bool);

statement ok
replace into t on(c1) values(false);

statement ok
replace into t on(c1) values(false);

# there should be only one row left there
query I
select count() from t;
----
1

# let's insert a different bool value
statement ok
replace into t on(c1) values(true);

query I
select count() from t;
----
2

statement ok
drop table t;

statement ok
DROP DATABASE issue_15307

0 comments on commit 9c43f7c

Please sign in to comment.