Skip to content

Optimize <|>: implementation of Tabulation#178

Merged
shane-circuithub merged 1 commit intomasterfrom
tabulation-union
Jun 9, 2022
Merged

Optimize <|>: implementation of Tabulation#178
shane-circuithub merged 1 commit intomasterfrom
tabulation-union

Conversation

@shane-circuithub
Copy link
Copy Markdown
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