Closed mateusvmv closed 3 months ago
This doubles up with another issue:
:create rel {x=>a,b}
::index create rel:a {a,x}
::explain { ?[a1,a2,a3] := *rel{a:a1,b:a2},*rel{a:a2,b:a3},*rel{a:a3,b:a1} }
This is supposed to bind two variables in the last query, but it only binds one. In that case, I think it should choose a prefix join on the index and a mat join on the relation, using three atoms, if that is acceptable.
I'm working on a fix for both and will come up with a PR soon.
Cozo is using the wrong fields with indexes in a specific scenario.
To reproduce, use the following schema:
:create source { x => b }
:create target { a => c, b }
::index create target:b { b, a }
And check the query plan
target:b has the format [b,a], so 2 is column a target has format [a, c, b], so 0 is column b The plan here is trying to join on two different columns
If we change the query by adding the index explicitly, it uses a correct plan, but includes b on the join. There is no need to include b, because a determines b. If b isn't right after a, it results in a matrix join, making the operation more expensive.
The optimal plan is obtained with the following query