diff --git a/src/query/storages/fuse/src/operations/replace_into/mutator/merge_into_mutator.rs b/src/query/storages/fuse/src/operations/replace_into/mutator/merge_into_mutator.rs index 8d428c9318bd2..25dae2c188dab 100644 --- a/src/query/storages/fuse/src/operations/replace_into/mutator/merge_into_mutator.rs +++ b/src/query/storages/fuse/src/operations/replace_into/mutator/merge_into_mutator.rs @@ -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 } } @@ -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(()) } } diff --git a/tests/sqllogictests/suites/base/09_fuse_engine/09_0024_replace_into_issue_15307.test b/tests/sqllogictests/suites/base/09_fuse_engine/09_0024_replace_into_issue_15307.test new file mode 100644 index 0000000000000..693d8eca2def1 --- /dev/null +++ b/tests/sqllogictests/suites/base/09_fuse_engine/09_0024_replace_into_issue_15307.test @@ -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