Tries¶
A relation over variables \(v_1, \dots, v_k\) is kept as a
trie: a nested dictionary from the value of \(v_1\) to a
trie over the rest, whose leaves are what each tuple stands for. Generic Join binds
the variables of a query one at a time, and the values of a variable are the intersection, over
the tries that contain it, of the values they allow below the variables already bound, found by
iterating the smallest and probing the others.
intersect is that step. Rule-body
joins, the indexed chart and the agenda all use it, so its
cost, at most the AGM bound of the query for each variable, holds for each of them.
tries
¶
Tries of relations and the intersection step of Generic Join.
A relation over variables v_1, ..., v_k is kept as a trie: a nested
dictionary from the value of v_1 to a trie over the rest, whose
leaves are what each tuple stands for (an item, or a weight). Generic
Join binds the variables of a query one at a time; the values of a
variable are the intersection, over the tries that contain it, of the
values they allow below the variables already bound, found by
iterating the smallest and probing the others (Ngo, Re and Rudra 2014).
Rule-body joins, the indexed chart and the agenda share this one step.
References
Ngo, H. Q., Re, C., and Rudra, A. (2014). Skew strikes back: new developments in the theory of join algorithms. SIGMOD Record 42(4), 5-16. doi:10.1145/2590989.2590991
TrieCounter
¶
insert
¶
insert(root: Trie[V, L], values: Sequence[V], leaf: L) -> None
Add a tuple to a trie.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The trie.
TYPE:
|
values
|
The tuple's values in the trie's variable order, at least one; a relation of no variables is kept under one key standing for the empty tuple.
TYPE:
|
leaf
|
What the tuple stands for.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If there are no values. |
Source code in src/quivers/stochastic/tries.py
descend
¶
The node of a trie below a prefix of values.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The trie.
TYPE:
|
values
|
The prefix; empty for the root.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Trie or L or None
|
The node, or |
Source code in src/quivers/stochastic/tries.py
intersect
¶
intersect(order: Sequence[str], containing: Sequence[Sequence[int]], nodes: list[Trie[V, L] | L], binding: dict[str, V], counter: TrieCounter, depth: int = 0) -> Iterator[tuple[dict[str, V], list[Trie[V, L] | L]]]
Bind the variables from depth on, one at a time, and yield each complete binding.
| PARAMETER | DESCRIPTION |
|---|---|
order
|
The free variables, in order.
TYPE:
|
containing
|
For each free variable, the tries that contain it.
TYPE:
|
nodes
|
Each trie's node below the variables bound so far; a trie whose variables are all bound is at its leaf.
TYPE:
|
binding
|
The variables bound so far; extended in place and restored.
TYPE:
|
counter
|
The counts.
TYPE:
|
depth
|
The next free variable.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
tuple of dict and list
|
A copy of each complete binding and every trie's leaf under it. |