Algorithmadvanced
MiniCon algorithm
Also called MiniCon.
Rewrite a conjunctive query using views: form minimal descriptions of the subgoals each view can cover, then combine sets of them that cover the query exactly once.
- Time
- O(a n k (m+1)^n (n k m+1)^n) worst
- Space
- O(a n k (m+1)^n) extra
- Where
- a = the largest arity of a predicate; k = the number of views; m = the largest number of subgoals of a view; n = the number of subgoals of the query
- Model
- Word RAM
- Properties
- deterministicexactnot in placeofflinerecursive
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Rachel Pottinger, Alon Y. Halevy, 2000
MiniCon rewrites a conjunctive query into a union of conjunctive queries over a set of views, for answering queries using views in local-as-view integration. It returns the maximally contained rewriting, as the bucket algorithm does, but it does the containment work before it combines views. The bucket algorithm puts each view in a bucket for one subgoal and then tests every combination for containment. MiniCon first finds, for each view, the smallest set of subgoals that the view must cover together, and then it only combines these sets when they do not overlap. No containment test is left at the end.
In plain words
A view stores the answers of a small query, and some of its variables are not stored. If a query subgoal uses a variable that the view hides, the view can only help if it also covers every other subgoal that uses that variable, because the hidden value cannot be joined with anything outside the view.
MiniCon starts with one subgoal and one view. Each time the view would hide a variable that some other subgoal needs, it pulls that subgoal into the same group. The result is a small group of subgoals that the view covers alone. Then it picks groups from different views so that each subgoal is in exactly one group, and each such choice gives one rewriting.
The problem
The input is a query in AHV notation and a set of views, each of the form . All terms are variables, there are no comparisons, and set semantics holds. A variable of a view is distinguished if it is in the head and existential otherwise. A rewriting is a conjunctive query over the view names. It is contained in when its expansion, the query you get by replacing each view atom by the body of the view with new existential variables, is contained in . The output is a union of contained rewritings that contains every other contained union of conjunctive queries.
A MiniCon description (MCD) for a view is a tuple . is a set of subgoals of , is a head homomorphism that may equate head variables of , and maps the variables of to variables of so that each subgoal of maps onto of some subgoal of . It must satisfy Property 1:
- C1. Each head variable of in maps to a distinguished variable of .
- C2. If is existential, then every subgoal of that holds is in .
The algorithm
MINICON(Q, Views)- 1
C <- empty - 2
for each subgoal g of Q, view V and subgoal v of V with the predicate of g do - 3
(h, phi) <- the least restrictive pair with phi(g) = h(v); skip if none exists - 4
for each (h', phi', G) in CLOSE(Q, V, h, phi, {g}) do - 5
add the MCD (V, h', phi', G) to C - 6
R <- empty - 7
for each set {M_1, ..., M_c} of MCDs in C whose sets G_i partition the subgoals of Q do - 8
EC <- the classes of the query variables, with x ~ y if phi_i(x) = phi_i(y) for some i - 9
Psi_i(y) <- a variable x with phi_i(x) = y, or a fresh variable if there is none - 10
add Q'(EC(X)) :- V_1(EC(Psi_1(h_1(Y_1)))), ..., V_c(EC(Psi_c(h_c(Y_c)))) to R - 11
return R CLOSE(Q, V, h, phi, G)- 12
if phi maps a head variable of Q to an existential variable of V then return nothing - 13
if no subgoal g' outside G holds a variable x with phi(x) existential then return {(h, phi, G)} - 14
for each subgoal v' of V with the predicate of g' do - 15
extend (h, phi) least restrictively so that phi(g') = h(v'); skip v' if impossible - 16
return also everything that CLOSE(Q, V, h, phi, G + {g'}) returns
Lines L3 and L15 unify a query subgoal with a view subgoal position by position. When two query variables meet one view variable, or one query variable meets two view variables, the two view variables must become one. That is allowed only for two distinguished variables, and then the head homomorphism equates them. An existential variable cannot be equated with anything else, because the view stores no value for it.
Line L12 is C1. Line L13 checks C2: it looks for a subgoal outside that shares a variable mapped to an existential. If there is one, lines L14 to L16 try each way to map it into the same view. A branch that fails is dropped, and if all branches fail, the seed of line L2 gives no MCD.
The combination step needs no containment test. Line L7 takes MCDs whose subgoal sets are disjoint and cover the query. Line L8 joins the query variables that one view puts in the same place. Line L9 picks the argument of each head position: the query variable mapped there, or a new variable for a position that no query variable uses.
Example
The query and views come from Pottinger and Halevy. asks for papers that cite a paper on the same topic that cites them back. The views are
- ,
- ,
- .
Call the subgoals . The table shows the seeds of line L2 and what CLOSE does with them.
| seed | after line L3 | CLOSE | MCD |
|---|---|---|---|
| with cites of | , | is existential, so add with cites; then needs sameTopic, which lacks | none |
| with cites of | line L12: head variable on an existential | none | |
| with sameTopic of | , | nothing to add | |
| with cites of | , | add with cites, which forces ; add with sameTopic | , |
| with cites of | , | the same closure | the same MCD |
The other seeds fail at line L12 or repeat an MCD. covers alone, but no MCD covers and without . So line L7 finds one partition, , and the answer is . The bucket algorithm would build 2 times 2 times 2 candidates here and test each one for containment.
A chain. For with and , there are five MCDs: on each subgoal alone, on and on . A single subgoal cannot use , since its middle variable is existential and is shared with the next or previous subgoal. Three partitions exist, and MiniCon returns , and .
Correctness
Theorem (Pottinger and Halevy). For conjunctive queries and views without comparisons, the union of the rewritings that MINICON returns is a maximally contained rewriting of among unions of conjunctive queries over the views.
The proof file proves it in full. Soundness uses C2: a variable that two MCDs share is distinguished in both, so the containment mapping of each MCD agrees with the others on it. Completeness starts from a containment mapping of into the expansion of any contained rewriting. The subgoals that map into one view atom split into pieces that share existential variables, each piece is an MCD that the search finds, and these MCDs give a rewriting that contains the given one.
By the results of Abiteboul and Duschka, the maximally contained rewriting gives the certain answers under the open world assumption when the views and the query are conjunctive.
Proof: MiniCon returns a maximally contained rewriting of a conjunctive query using conjunctive viewsfull
Setting. The query is and each view is with . All terms are variables, there are no comparisons, and set semantics holds. A variable of a view is a head variable if it is in and existential otherwise. A rewriting is a conjunctive query over the view names. Its expansion replaces each view atom , the -th atom of , by the body of under the renaming that sends the head variable at position to and each existential to a new variable used nowhere else. is contained in if . By the Chandra-Merlin theorem, for conjunctive queries if and only if there is a containment mapping from to : a map on variables that sends the head of to the head of and each body atom of to a body atom of .
An MCD is a tuple . Here is a set of subgoals of , maps the head variables of to head variables of with (the head homomorphism), and maps the variables of to variables of with values in the range of or existential, such that each has a subgoal of with . Here is the identity on existentials. Property 1 is the pair of conditions of lines L12 and L13:
- (C1) is a head variable for each head variable of in ;
- (C2) if is existential, then every subgoal of that holds is in .
Lemma 1 (unification). Let be as above and let a subgoal of and a subgoal of have the same predicate. Line L15 (and line L3, with empty and the identity) returns the least restrictive extension with that equates no existential with another variable, or fails if none exists. It returns a result if there is a map from the variables of with on head variables, one to one on existentials with values that no head variable takes, and for each position at which holds .
Proof. The procedure walks the positions of . At position with variable and view variable , it sets if is not set. If , then and must become one variable. This is possible only if both are head variables, and then the procedure merges their classes in and , keeping the head variable with the lowest position as the class name. Each merge is forced by the equation , so the result is the least restrictive one, and the choice of names makes it unique. Under the map of the second claim, . If or were existential, the conditions on would give . So the procedure never fails, and the merges keep and on old variables.
Lemma 2 (each output tuple is an MCD with Property 1). Each tuple added at line L5 is an MCD that satisfies C1 and C2.
Proof. Lemma 1 keeps for each subgoal added so far, since later merges apply to both sides. Line L12 rejects every state that breaks C1, and the state is only returned by line L13 when no subgoal outside holds a variable with an existential image, which is C2.
Lemma 3 (soundness). Each rewriting added at line L10 is contained in .
Proof. Line L7 picks MCDs , with , whose sets partition the subgoals of . Line L8 gives the classes , and line L9 gives the atom with , where is a variable with or a fresh variable. Let be the renaming of the expansion of the -th atom. For a head variable , for its position , and , since is idempotent and both give .
Define for a variable of a subgoal of . This does not depend on . If occurs in and in with , then is a head variable by C2, so , because is a variable with the same image as and so in the class of . The same holds for .
For , there is with , so , an atom of . For a head variable of , C1 gives , the head of at that position. So is a containment mapping from to , and .
Lemma 4 (completeness). Let be a conjunctive rewriting with . Then some rewriting added at line L10 has .
Proof. Take a containment mapping from to . Each is an atom of the expansion of some atom of , so for a subgoal of that view. Fix such choices. Let be the subgoals with , and write .
A variable of of the form is existential in the -th expansion and occurs only there. So if , every subgoal that holds is in . Call two subgoals of linked if they share a variable with of the form .
Start the procedure at line L2 with a subgoal , the view of the -th atom and the subgoal . At line L14, take the branch for the subgoal that line L13 picks. By Lemma 1, applied with , each unification succeeds and keeps . So is existential exactly when is of the form , because sends head variables to variables of and existentials to variables . Line L12 never fails, since a head variable of has in the head of . Line L13 picks only subgoals linked to the current set. So this branch returns an MCD whose set is the linked component of in . These components partition each , and the sets partition the subgoals of . Line L7 enumerates this partition, since it tries every disjoint cover. Let be its rewriting.
Map each variable of to a variable of . A class goes to . This is well defined, because gives . A fresh variable made at line L9 for the class of a head variable of goes to . Then the -th argument of the -th atom of goes to , the -th argument of atom of . The head goes to , the head of . This is a containment mapping from to , so .
Theorem. MINICON stops, and the union of its output is a maximally contained rewriting of using the views among unions of conjunctive queries: , and for each union of conjunctive queries over the views with .
Proof. Termination: each recursion of CLOSE adds a subgoal to , so its depth is at most , and each loop is over a finite set. Lemma 3 gives . A union has each disjunct contained in , and Lemma 4 puts each disjunct inside one member of .
Running time. Let be the number of views and the largest arity. An MCD is fixed by its view and by the view subgoal chosen for each subgoal in , because Lemma 1 makes the unifier unique. So there are at most MCDs, and the search of lines L2 to L5 has at most leaves, each reached in steps. A set of MCDs that partitions the subgoals is fixed by the partition, at most choices, and by the view and view subgoal of each subgoal, at most choices, so line L7 yields at most sets. This is the bound of Pottinger and Halevy. The enumeration visits at most partial covers and scans the MCDs at each one. The total time is in combined complexity.
Complexity
All bounds are in combined complexity, since the query and the views are the input.
- Time. An MCD is fixed by its view and by the view subgoal of each query subgoal, so there are at most MCDs. A set of MCDs that partitions the subgoals is fixed by the partition and by these choices, so line L7 yields at most sets, as Pottinger and Halevy state. With the scans of the enumeration, the total is time (a theorem, proved in the proof file).
- Space. for the MCDs, plus the output.
The exponent in cannot go away in general, since deciding whether an equivalent rewriting exists is NP-complete. In practice the number of MCDs is small, because C2 kills most seeds early.
Properties
- Exact. The output is the maximally contained rewriting, not an approximation of it.
- Deterministic. The order of the views and the subgoals fixes the order of the output.
- No final containment test. Every combination of line L7 is a contained rewriting, by the soundness lemma.
- Duplicates. Two partitions can give the same rewriting up to variable names, and a rewriting can be contained in another one. The code removes only exact copies.
Variants and improvements
- Comparison predicates. Pottinger and Halevy extend MiniCon to queries and views with arithmetic comparisons. The extension needs extra checks on the comparisons that an MCD covers. This page and its code treat only the case without comparisons.
- Equivalent rewritings. To find an equivalent rewriting, run the same combination step, then test each candidate for containment of in its expansion.
- Inverse rules. The inverse rules algorithm gets the same answers from the view instance by a Datalog program with Skolem terms, without writing out the rewriting.
When to use it
Use MiniCon when you need the rewriting itself, for example to send it to the sources or to optimize it, and the views are many. Pottinger and Levy measured (a measurement, in Java on a dual Pentium II) that MiniCon scales to more than a thousand views for chain queries, while the bucket and inverse rules algorithms are much slower. If you only need the answers on one view instance, the inverse rules program is simpler.
Pitfalls
- Skipping C2. If line L13 always returns, an MCD can cover one subgoal with a view that hides the join variable. In the chain, would cover alone with , and the combination loses the join on . Its expansion is not contained in .
- Equating an existential. Lines L3 and L15 may only merge two distinguished view variables. If the unifier also merges an existential with another variable, it produces MCDs whose rewritings claim joins that the view does not expose.
- Head variables on existentials. Without line L12, with cites of in the example sends the answer variable to , which the view does not return.
- Overlapping MCDs. Line L7 needs disjoint sets. If it allows overlaps, the rewritings are still contained, but there are many more of them, and each one is contained in a rewriting from a disjoint set, so the extra work buys nothing.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/minicon-algorithm/. The authors are listed in prov/Y3KK7E.jsonl.
"""The MiniCon algorithm for conjunctive queries and conjunctive views.
An atom is a pair (predicate, tuple of variables). A conjunctive query is a
pair (head, body): head is a tuple of variables and body is a list of atoms.
All terms are variables: there are no constants and no comparisons. A view is
a conjunctive query whose head has distinct variables, and views is a dict
from view name to view. A rewriting is a conjunctive query whose predicates
are view names. Set semantics holds throughout.
"""
def variables(atoms):
"""The variables of a list of atoms, in order of first occurrence."""
seen = {}
for _, args in atoms:
for a in args:
seen.setdefault(a, None)
return list(seen)
def _matches(atoms, index, binding):
"""Yield each extension of binding that maps every atom to a tuple of index."""
if not atoms:
yield binding
return
pred, args = atoms[0]
for tup in index.get(pred, ()):
if len(tup) != len(args):
continue
new = dict(binding)
ok = True
for a, v in zip(args, tup):
if new.setdefault(a, v) != v:
ok = False
break
if ok:
yield from _matches(atoms[1:], index, new)
def evaluate(query, instance):
"""The answers of a conjunctive query on an instance {predicate: set of tuples}."""
head, body = query
return {tuple(m[x] for x in head) for m in _matches(list(body), instance, {})}
def contained(q1, q2):
"""True if q1 is contained in q2: a containment mapping sends q2 onto the frozen q1."""
(head1, body1), (head2, body2) = q1, q2
if len(head1) != len(head2):
return False
start = {}
for a, b in zip(head2, head1):
if start.setdefault(a, b) != b:
return False
index = {}
for pred, args in body1:
index.setdefault(pred, set()).add(tuple(args))
return next(_matches(list(body2), index, start), None) is not None
def expand(rewriting, views):
"""Replace each view atom by the body of its view, with fresh existential variables."""
head, body = rewriting
out = []
for k, (name, args) in enumerate(body):
vhead, vbody = views[name]
ren = dict(zip(vhead, args))
for pred, us in vbody:
out.append((pred, tuple(ren.setdefault(u, "%s#%d" % (u, k)) for u in us)))
return (tuple(head), out)
def _unify(phi, hmap, g_args, v_args, vhead):
"""Extend (phi, hmap) so that phi(g) = hmap(v), in the least restrictive way, or None.
phi maps query variables to view variables. hmap maps each head variable of
the view to its representative: it is the head homomorphism. vhead maps each
head variable to its position, and the representative of a class is the
head variable with the lowest position. An existential view variable may
not be equated with any other view variable.
"""
phi, hmap = dict(phi), dict(hmap)
for x, a in zip(g_args, v_args):
a = hmap.get(a, a)
b = phi.get(x)
if b is None:
phi[x] = a
elif b != a:
if b not in vhead or a not in vhead:
return None
if vhead[a] < vhead[b]:
a, b = b, a
for y in hmap:
if hmap[y] == a:
hmap[y] = b
for y in phi:
if phi[y] == a:
phi[y] = b
return phi, hmap
def _close(query, view, phi, hmap, cover):
"""Yield each (phi, hmap, cover) that extends the input and satisfies Property 1."""
qhead, qbody = query
vhead, vbody = view
vheadset = {y: k for k, y in enumerate(vhead)}
if any(x in phi and phi[x] not in vheadset for x in qhead): # @line L12
return
for j, (pred, args) in enumerate(qbody): # @line L13
if j not in cover and any(x in phi and phi[x] not in vheadset for x in args):
break
else:
yield phi, hmap, cover
return
for vpred, vargs in vbody: # @line L14
if vpred == pred and len(vargs) == len(args):
ext = _unify(phi, hmap, args, vargs, vheadset) # @line L15
if ext is not None:
yield from _close(query, view, ext[0], ext[1], cover | {j}) # @line L16
def form_mcds(query, views):
"""The MiniCon descriptions: tuples (view name, hmap, phi, frozenset of subgoal indexes)."""
qhead, qbody = query
mcds = {} # @line L1
for i, (pred, args) in enumerate(qbody): # @line L2
for name in sorted(views):
vhead, vbody = views[name]
for vpred, vargs in vbody:
if vpred != pred or len(vargs) != len(args):
continue
start = _unify({}, {y: y for y in vhead}, args, vargs, {y: k for k, y in enumerate(vhead)}) # @line L3
if start is None:
continue
for phi, hmap, cover in _close(query, views[name], start[0], start[1], frozenset([i])): # @line L4
key = (name, tuple(sorted(hmap.items())), tuple(sorted(phi.items())), cover)
mcds[key] = (name, hmap, phi, cover) # @line L5
return [mcds[k] for k in sorted(mcds, key=repr)]
def _partitions(n, mcds):
"""Each list of MCDs whose subgoal sets are disjoint and cover 0..n-1 (Property 2)."""
def rec(covered, chosen):
if len(covered) == n:
yield list(chosen)
return
first = min(set(range(n)) - covered)
for m in mcds:
if first in m[3] and not (m[3] & covered):
chosen.append(m)
yield from rec(covered | m[3], chosen)
chosen.pop()
yield from rec(frozenset(), [])
def combine_mcds(query, views, mcds):
"""The conjunctive rewritings, one for each set of MCDs that partitions the subgoals."""
qhead, qbody = query
order = {x: k for k, x in enumerate(list(qhead) + variables(qbody))}
result = [] # @line L6
for combo in _partitions(len(qbody), mcds): # @line L7
parent = {x: x for x in order}
def find(x):
while parent[x] != x:
x = parent[x]
return x
for _, _, phi, _ in combo: # @line L8
first = {}
for x in sorted(phi, key=order.get):
y = phi[x]
if y in first:
rx, ry = find(x), find(first[y])
if rx != ry:
lo, hi = sorted((rx, ry), key=order.get)
parent[hi] = lo
else:
first[y] = x
fresh = 0
body = []
for name, hmap, phi, _ in combo:
inv = {}
for x in sorted(phi, key=order.get):
inv.setdefault(phi[x], x)
args = []
for y in views[name][0]:
y = hmap[y]
if y not in inv: # @line L9
fresh += 1
inv[y] = "_%d" % fresh
args.append(inv[y])
else:
args.append(find(inv[y]) if inv[y] in parent else inv[y])
body.append((name, tuple(args)))
rewriting = (tuple(find(x) for x in qhead), body)
if rewriting not in result:
result.append(rewriting) # @line L10
return result
def minicon(query, views):
"""A union of conjunctive rewritings that is the maximally contained rewriting of query."""
mcds = form_mcds(query, views)
return combine_mcds(query, views, mcds) # @line L11
def answer(rewritings, view_instance):
"""The answers of a union of rewritings on an instance of the views."""
out = set()
for r in rewritings:
out |= evaluate(r, view_instance)
return out
test_minicon_algorithm.py 181 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/minicon-algorithm/. The authors are listed in prov/Y3KK7E.jsonl.
import itertools
import random
from minicon_algorithm import answer, contained, evaluate, expand, form_mcds, minicon, variables
# The example of Pottinger and Levy (VLDB 2000), Section 3.
Q1 = (("x",), [("cites", ("x", "y")), ("cites", ("y", "x")), ("sameTopic", ("x", "y"))])
PAPER_VIEWS = {
"V4": (("a",), [("cites", ("a", "b")), ("cites", ("b", "a"))]),
"V5": (("c", "d"), [("sameTopic", ("c", "d"))]),
"V6": (("f", "h"), [("cites", ("f", "g")), ("cites", ("g", "h")), ("sameTopic", ("f", "g"))]),
}
def certain_answers(query, views, view_instance):
"""Oracle: chase the view facts into a canonical database with labeled nulls,
evaluate the query and keep the answers without nulls."""
db = {}
k = 0
for name, tuples in view_instance.items():
vhead, vbody = views[name]
for t in sorted(tuples):
k += 1
m = dict(zip(vhead, t))
for pred, args in vbody:
db.setdefault(pred, set()).add(tuple(m.setdefault(u, ("null", k, u)) for u in args))
return {t for t in evaluate(query, db) if not any(isinstance(v, tuple) for v in t)}
def view_image(views, db):
return {name: evaluate(v, db) for name, v in views.items()}
def brute_contained_rewritings(query, views, max_atoms):
"""Oracle: every contained rewriting with at most max_atoms view atoms whose
variables are query variables or fresh ones, with each possible head."""
qhead, qbody = query
qvars = variables(qbody)
atoms = []
for name in sorted(views):
arity = len(views[name][0])
for args in itertools.product(qvars + [None], repeat=arity):
atoms.append((name, args))
for size in range(1, max_atoms + 1):
for combo in itertools.combinations_with_replacement(atoms, size):
fresh = itertools.count()
body = [(n, tuple(a if a is not None else "_f%d" % next(fresh) for a in args)) for n, args in combo]
ehead, ebody = expand(((), body), views)
index = {}
for pred, args in ebody:
index.setdefault(pred, set()).add(args)
rvars = set(variables(body))
heads = set()
for h in _all_maps(qbody, index):
t = tuple(h[x] for x in qhead)
if all(v in rvars for v in t):
heads.add(t)
for t in sorted(heads):
yield (t, body)
def _all_maps(atoms, index, binding=None):
binding = {} if binding is None else binding
if not atoms:
yield binding
return
pred, args = atoms[0]
for tup in index.get(pred, ()):
new = dict(binding)
if all(new.setdefault(a, v) == v for a, v in zip(args, tup)):
yield from _all_maps(atoms[1:], index, new)
def random_case(rng):
preds = [("e", 2), ("p", 1)]
qv = ["x", "y", "z"]
body = []
for _ in range(rng.randint(1, 3)):
p, ar = rng.choice(preds)
atom = (p, tuple(rng.choice(qv) for _ in range(ar)))
if atom not in body:
body.append(atom)
used = variables(body)
head = tuple(rng.sample(used, rng.randint(0, min(2, len(used)))))
views = {}
for k in range(rng.randint(1, 3)):
vv = ["a", "b", "c"]
vbody = []
for _ in range(rng.randint(1, 2)):
p, ar = rng.choice(preds)
atom = (p, tuple(rng.choice(vv) for _ in range(ar)))
if atom not in vbody:
vbody.append(atom)
vused = variables(vbody)
vhead = tuple(rng.sample(vused, rng.randint(1, len(vused))))
views["V%d" % k] = (vhead, vbody)
return (head, body), views
def random_db(rng):
dom = ["1", "2", "3"]
db = {"e": set(), "p": set()}
for _ in range(rng.randint(0, 5)):
db["e"].add((rng.choice(dom), rng.choice(dom)))
for _ in range(rng.randint(0, 2)):
db["p"].add((rng.choice(dom),))
return db
def test_paper_example():
mcds = form_mcds(Q1, PAPER_VIEWS)
# V5 covers sameTopic(x, y) alone. V6 must cover all three subgoals, with f = h.
assert [(m[0], sorted(m[3])) for m in mcds] == [("V5", [2]), ("V6", [0, 1, 2])]
v6 = mcds[1]
assert v6[1] == {"f": "f", "h": "f"}
assert v6[2] == {"x": "f", "y": "g"}
assert minicon(Q1, PAPER_VIEWS) == [(("x",), [("V6", ("x", "x"))])]
def test_equivalent_rewriting_found():
# Q(x, z) :- e(x, y), e(y, z) with the view V(a, b) :- e(a, b).
q = (("x", "z"), [("e", ("x", "y")), ("e", ("y", "z"))])
views = {"V": (("a", "b"), [("e", ("a", "b"))])}
rs = minicon(q, views)
assert rs == [(("x", "z"), [("V", ("x", "y")), ("V", ("y", "z"))])]
assert contained(q, expand(rs[0], views)) and contained(expand(rs[0], views), q)
def test_no_rewriting_when_join_variable_is_hidden():
# The join variable y is existential in each view, so nothing can join the two halves.
q = (("x", "z"), [("e", ("x", "y")), ("e", ("y", "z"))])
views = {"L": (("a",), [("e", ("a", "b"))]), "R": (("b",), [("e", ("a", "b"))])}
assert minicon(q, views) == []
def test_sound_and_maximal_on_random_cases():
rng = random.Random(7)
checked = 0
while checked < 150:
query, views = random_case(rng)
if not query[1]:
continue
checked += 1
rs = minicon(query, views)
for r in rs:
assert set(r[0]) <= set(variables(r[1]))
assert contained(expand(r, views), query)
if len(query[1]) <= 2:
for b in brute_contained_rewritings(query, views, len(query[1])):
assert any(contained(b, r) for r in rs), (query, views, b, rs)
for _ in range(4):
db = random_db(rng)
inst = view_image(views, db)
got = answer(rs, inst)
assert got <= evaluate(query, db)
assert got == certain_answers(query, views, inst)
def test_paper_example_maximal():
rs = minicon(Q1, PAPER_VIEWS)
for b in brute_contained_rewritings(Q1, PAPER_VIEWS, 2):
assert any(contained(b, r) for r in rs)
def test_head_variables_can_be_equated():
# V(a) :- e(a, a) answers Q(x, y) :- e(x, y) only on the diagonal.
q = (("x", "y"), [("e", ("x", "y"))])
views = {"V": (("a",), [("e", ("a", "a"))])}
assert minicon(q, views) == [(("x", "x"), [("V", ("x",))])]
assert answer(minicon(q, views), {"V": {("1",)}}) == {("1", "1")}
def test_boolean_query():
q = ((), [("e", ("x", "y"))])
views = {"V": (("a",), [("e", ("a", "b"))])}
rs = minicon(q, views)
assert answer(rs, {"V": {("1",)}}) == {()}
assert answer(rs, {"V": set()}) == set()
History
Levy, Rajaraman and Ordille introduced the bucket algorithm for the Information Manifold in 1996, and Duschka and Genesereth gave the inverse rules algorithm in 1997. Pottinger and Levy (Alon Levy, now Halevy) presented MiniCon at VLDB 2000. The journal version, with comparison predicates and experiments, appeared in the VLDB Journal in 2001. Halevy's survey of the same year places MiniCon among the algorithms for data integration.
References
- Rachel Pottinger and Alon Halevy, MiniCon: a scalable algorithm for answering queries using views, The VLDB Journal 10(2), 2001, pages 182-198, MiniCon descriptions, Property 1, the combination step and the experiments
- Alon Y. Halevy, Answering queries using views: a survey, The VLDB Journal 10(4), 2001, pages 270-294, the section on algorithms for data integration
- AnHai Doan, Alon Halevy and Zachary Ives, Principles of Data Integration, Morgan Kaufmann, 2012, Chapter 2, answering queries using views, the MiniCon algorithm
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag Y3KK7E Edit this page History Report an error Markdown