Fair intersection of seekable iterators
Michael Arntzenius
TL;DR
We address the problem of computing fair, complete, worst-case-optimal joins in relational queries, where Leapfrog Triejoin's $k$-way intersection lacks compositionality. The authors propose bounded-work fair interleaving by extending seekable iterators with a Seek interface that propagates lower bounds between iterators, inspired by μKanren's complete disjunction. Key contributions include a formal fair-intersection design (Position, Bound, and seeking) and practical demonstrations that this approach yields large speedups over naive binary-intersection schemes, connecting to Tensor algebra and indexed streams. The work enables a compositional path to worst-case-optimal joins in functional settings and points to extensions toward full conjunctive queries, existential quantification, and potentially recursive logic programming.
Abstract
miniKanren's key semantic advance over Prolog is to implement a complete yet efficient search strategy, fairly interleaving execution between disjuncts. This fairness is accomplished by bounding how much work is done exploring one disjunct before switching to the next. We show that the same idea -- fairness via bounded work -- underlies an elegant compositional approach to implementing worst-case optimal joins using a seekable iterator interface, suitable for shallow embedding in functional languages.
