Skip to content

COUNT DISTINCT for 0 matching documents return NULL #50013

Closed
@astefan

Description

@astefan

When #44745 has been introduced as a way of aggregations (SUM, MAX, AVG etc) dealing with a lack of documents matching a query and, implicitly, dealing with NULLs the case of COUNT(DISTINCT) (that uses a cardinality aggregation behind the scene) has been approached as well.

But, this introduced the issue of returning a NULL for COUNT(DISTINCT) where there are no matching documents. For example SELECT COUNT(DISTINCT languages) FROM test_emp WHERE languages > 100 returns NULL, whereas it should return 0 since there are no documents matching the condition languages > 100.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions