Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize <|>: implementation of Tabulation #178

Merged
merged 1 commit into from
Jun 9, 2022

Conversation

shane-circuithub
Copy link
Contributor

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.

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

```haskell
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" `Tabulation`s.

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.
@shane-circuithub shane-circuithub enabled auto-merge (squash) June 9, 2022 13:51
@shane-circuithub shane-circuithub merged commit bdcfd29 into master Jun 9, 2022
@shane-circuithub shane-circuithub deleted the tabulation-union branch June 9, 2022 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants