penberg / limbo

Limbo is a work-in-progress, in-process OLTP database management system, compatible with SQLite.
MIT License
896 stars 49 forks source link

Aggregate function discrepancies on empty or null datasets #118

Closed Ramkarthik closed 1 month ago

Ramkarthik commented 1 month ago

The following aggregate functions have discrepancies when applied on empty datasets or only-null values.

Steps to reproduce (create empty table since limbo doesn't support where clause yet): create table empty_table (id INT PRIMARY KEY);

AVG

SQLite:

> select avg(id) from empty_table;

Limbo:

> select avg(id) from empty_table;
thread 'main' panicked at core/vdbe.rs:609:33:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

COUNT

SQLite:

> select count(id) from empty_table;
0

Limbo:

> select count(id) from empty_table;
NULL

The ones below have differences, but I don't know if we want to change or not.

SUM

SQLite:

> select sum(id) from empty_table;

Limbo:

> select sum(id) from empty_table;
NULL

MIN

SQLite:

> select min(id) from empty_table;

Limbo:

> select min(id) from empty_table;
NULL

MAX

SQLite:

> select max(id) from empty_table;

Limbo:

> select max(id) from empty_table;
NULL
benclmnt commented 1 month ago

SUM, MIN, MAX looks like a display issue. I will take a look at AVG and COUNT