circuithub / rel8

Hey! Hey! Can u rel8?
https://rel8.readthedocs.io
Other
150 stars 38 forks source link

Optimize `<|>:` implementation of `Tabulation` #178

Closed shane-circuithub closed 2 years ago

shane-circuithub commented 2 years ago

Tabulation has an instance of AltTable, which is intended to uphold the following law:

fromQuery a <|>: fromQuery b = fromQuery (a <|>: b)

The previous implementation was not actually defined in terms of Query's <|>: (i.e., UNION ALL), because not every Tabulation can be safely toQuery'd. Instead it used a combination of alignWith, catNonEmptyTable and some that worked even on "magic" Tabulations.

However, using unsafePeekQuery, we can actually "statically" determine if a Tabulation is "magic" or not, which means we can selectively switch the implementation to use Query's <|>: where possible. This produces a simpler and usually faster query.