Nested exclusive constraints do not get understood as singular
- EdgeDB Version: EdgeDB Version: 4.4+596d0e4 on Ubuntu 22.04.3 LTS
- EdgeDB CLI Version: EdgeDB CLI 4.1.0+a8fe4d7
type A {
url: str {
constraint exclusive;
}
}
type B {
a: A;
name: str;
constraint exclusive on ((.name, .a));
}
type C {
b: B;
index: int16;
data: str;
constraint exclusive on ((.index, .b));
}
select C {
b: { name },
data,
}
filter
.index = <int16>$index and
.b.name = <str>$b_name and
.b.a.url = <str>$a_url
This will give a set of cardinality MANY and thus fails things like Rust's query_required_single. Being able to use assert_single makes this not that high of a priority but it is annoying.
Going to guess the answer here is "postgres forces this" but fingers crossed it's an easy fix somewhere
Postgres doesn't force all that much about our cardinality inference system. If we determine something is single, we can just assume it--we don't need to convince postgres.
The limiting factor on cardinality inference is that it is more important to have predictable cardinality inference rules than it is to support everything that we could possibly do.
That said, we could maybe reasonably support this one, and I hit one definite bug while producing a workaround version for you.
A version that does work (though you need to add a constraint on url)
select C {
#b: { name },
data,
}
filter
.index = <int16>$index and
.b = (select B filter .name = <str>$b_name and
.a = (select A filter .url = <str>$a_url))
The bug here is that if there is a shape on b, it doesn't work
Interesting, thanks
I'm also hitting similar issues on even simpler queries where I would expect exclusive to kick in. It seems it doesn't handle a lot of cases around computed/multi property exclusives.