I am trying to play around with the features of LogicBlox as a Datalog solver. I have performance issues and I think I am using LB wrong because it behaves as if it is materializing all relations (which a Datalog solver with e.g. magic sets would not do).
As I said, I have probably not used LB as it is supposed to, but here is my test. I want to create the transitive closure c(x,y) of some binary relation e(x,y). For the purpose of testing, I am playing with e created as a simple loop, i.e. I added e(i,(i+1)%1000) to LB for 0 ≤ i < 1000.
When I am only interested in from0(x) <- c(0,x) then there is no need to actually materialize c and the magic set method will create a predicate c_{bound,free}(x,y) and compute from0(0) then derive from0(1), etc. the whole operation taking roughly 1000 steps.
If I do my example with the program:
e(x,y) -> int(x), int(y).
// fill e with data
c(x,y) -> int(x), int(y).
c(x,y) <- e(x,y) ; c(x,z),e(z,y).
from0(x) <- c(0,x).
Then, obviously, I am producing a materialized version of c and c will contain all pairs of elements; therefore the total operation takes a time roughly of 1000^2 (and when I run the query, I see that it actually takes some time to compute).
From the documentation, LogicBlox allows predicates to be defined as "Derived" but for c it does not seem to be possible as c recurse on itself.
Now, I have also tried to define this transitive closure with a "local predicate" in a query or an exec block, but without success. Example of what I tried:
query '
_c(x,y)->int(x),int(y).
_c(x,y) <- e(x,y) ; e(x,z),_c(z,y).
_(x) <- _c(0,x).'
Obviously on this example I could manually optimize the query and define a block :
f0(x)->int(x).
f0(y)<- e(0,y) ; f0(x),e(x,y).
but if I understand LB correctly there should be a way to leave the optimization to LB.