rust-lang / datafrog

A lightweight Datalog engine in Rust
Apache License 2.0
796 stars 43 forks source link

Support joins on prefixes of arbitrary length #48

Open ecstatic-morse opened 2 years ago

ecstatic-morse commented 2 years ago

Currently, datafrog requires that all joins occur on tuples of the form (K, V). This becomes unpleasant for relations with more than two elements, as well as for joins on several elements. I found this limitation annoying when first trying to write datafrog programs.

Because datafrog is implemented on top of sorted data structures, we should be able to join on arbitrarily many tuple elements, so long as they are in order at the front of the tuple. This PR implements joins on arbitrary prefixes. As a result, you can specify all your variables and relations as a flat tuple, and wait to select what prefix you want for each individual join. For example, (A, B, C) could be joined with both (A, B, X) using (A, B) as the shared prefix and with (A, Y) using A as the shared prefix without cloning it.

Unfortunately, this is a breaking change, since we must copy prefixes and suffixes now instead of passing references to K and V.