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

Implement history indexes #121

Open
bruth opened this issue Apr 12, 2015 · 0 comments
Open

Implement history indexes #121

bruth opened this issue Apr 12, 2015 · 0 comments

Comments

@bruth
Copy link
Contributor

bruth commented Apr 12, 2015

History applies to the valid time. Facts can be added to the database that apply to any point in time and therefore must be sorted and merged when being evaluated. The following command:

origins history mydomain --start=1492-01-01 --duration=1y --asof=1w

translates to the following query plan:

  • Get all transactions in mydomain up to 1 week ago from now
  • For each transaction
    • Find those that have at least one fact with a valid_time greater than or equal 1492-01-01 or less than 1493-01-01
    • Sort the facts by valid_time
    • Filter out facts not in the valid_time range
  • Merge facts across transactions by valid_time

A few things to consider with this approach:

  • Determining the set of applicable transactions is an O(n) operation
  • Transaction facts contain metadata including minValidTime and maxValidTime which are used to determine if the transaction is applicable. The filter function looks like this:
func filterTx(tx *Transaction, minT, maxT, minV, maxV int64) bool {
    // Not included
    if tx.TxTime < minT || tx.TxTime > maxT {
        return false
    }

    // At least one fact is known to be within the valid range.
    return tx.minValidTime >= minV || tx.maxValidTime <= maxV
}
  • Filter and sort of each transaction can be done in parallel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant