Merge 'Fix wrong count() result if the column specified contains a NULL' from lgualtieri75

Fixes #1064

Closes #1065
This commit is contained in:
Pekka Enberg
2025-02-28 16:28:08 +02:00

View File

@@ -1722,6 +1722,7 @@ impl Program {
*acc += col;
}
AggFunc::Count | AggFunc::Count0 => {
let col = state.registers[*col].clone();
if matches!(&state.registers[*acc_reg], OwnedValue::Null) {
state.registers[*acc_reg] = OwnedValue::Agg(Box::new(
AggContext::Count(OwnedValue::Integer(0)),
@@ -1734,7 +1735,12 @@ impl Program {
let AggContext::Count(count) = agg.borrow_mut() else {
unreachable!();
};
*count += 1;
if (matches!(func, AggFunc::Count) && matches!(col, OwnedValue::Null))
== false
{
*count += 1;
};
}
AggFunc::Max => {
let col = state.registers[*col].clone();