rocicorp / rails

Replicache on Rails
Other
34 stars 3 forks source link

feat(zql): Implement OR #56

Closed arv closed 7 months ago

arv commented 7 months ago

This supersedes #52

OR is implemented by branching the graph when an OR expression is encountered. Each OR branch is executed "in parallel" and then merged together. The merging is done using concat and then distinct.

For example if we have:

SELECT * FROM table WHERE (a=1 OR b=1) AND (a=2 OR b=2)

We get something like:

  graph TD;
      Root-->id1;
      Root-->id2;
      id1(a=1) --> c1;
      id2(b=1) --> c1;
      c1(Concat) --> d1;
      d1(Distinct) --> id3;
      d1 --> id4;
      id3(a=2) --> c2;
      id4(b=2) --> c2;
      c2(Concat) --> d2;
      d2(Distinct)
arv commented 7 months ago

I have builder changes but that can be reviewed in isolation.

tantaman commented 7 months ago

img

Will review this tonight. Very cool :)