edgedb / edgedb

A graph-relational database with declarative schema, built-in migration system, and a next-generation query language
https://edgedb.com
Apache License 2.0
12.97k stars 399 forks source link

Multiplicity inference broken for correlated aggregates #3026

Open msullivan opened 2 years ago

msullivan commented 2 years ago

SELECT (Card, count(Card)).1 infers its multiplicity as ONE, even though it produces a set containing all repeats of 1.

Among other problems, this means that SELECT assert_distinct((Card, count(Card)).1) will succeed.

msullivan commented 2 years ago

The direct cause is that the cardinality of count(Card) gets inferred as ONE, which causes the multiplicity to get clamped to ONE. I think there's something of a question about what exactly the meaning of the cardinalities of subexpressions like count(Card) should be, maybe?

elprans commented 2 years ago

Evidently we need to take the Cartesian product into account when destructuring container multiplicity.