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

fix: incorrect overlap checking (replace into) #15315

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading