Skip to main content
QUICK REVIEW

[Paper Review] Expressivity and Complexity of MongoDB (Extended Version)

Elena Botoeva, Diego Calvanese|arXiv (Cornell University)|Mar 30, 2016
Advanced Database Systems and QueriesComputer Science4 references4 citations
TL;DR

This paper formally analyzes MongoDB's data model and query language (MQuery), establishing its equivalence to nested relational algebra (NRA) and precisely characterizing the computational complexity of its query fragments. It proves that full MQuery and Mmupg are complete for alternating exponential time with polynomial alternations, while minimal fragments range from LogSpace to NP-complete, offering tight complexity bounds and a foundation for optimizing and improving NoSQL query systems.

ABSTRACT

A significant number of novel database architectures and data models have been proposed during the last decade. While some of these new systems have gained in popularity, they lack a proper formalization, and a precise understanding of the expressivity and the computational properties of the associated query languages. In this paper, we aim at filling this gap, and we do so by considering MongoDB, a widely adopted document database managing complex (tree structured) values represented in a JSON-based data model, equipped with a powerful query mechanism. We provide a formalization of the MongoDB data model, and of a core fragment, called MQuery, of the MongoDB query language. We study the expressivity of MQuery, showing its equivalence with nested relational algebra. We further investigate the computational complexity of significant fragments of it, obtaining several (tight) bounds in combined complexity, which range from LOGSPACE to alternating exponential-time with a polynomial number of alternations. As a consequence, we obtain also a characterization of the combined complexity of nested relational algebra query evaluation.

Motivation & Objective

  • To formally define MongoDB's data model and a core fragment of its query language, MQuery, to enable rigorous analysis of its expressive power and computational complexity.
  • To demonstrate that MQuery is expressively equivalent to nested relational algebra (NRA), showing that MongoDB can express arbitrary joins within a single collection despite common misconceptions.
  • To investigate the combined and query complexity of various MQuery fragments, identifying tractable and intractable cases and providing tight complexity bounds.
  • To identify counter-intuitive or problematic features in MongoDB’s query language through formal analysis, offering insights for future language design and optimization.

Proposed method

  • Formalizing the MongoDB data model using JSON-based tree-structured documents and defining a core query language fragment, MQuery, with operators matching those in nested relational algebra.
  • Establishing bidirectional polynomial-time translations between MQuery and nested relational algebra (NRA), proving expressive equivalence and enabling transfer of complexity results.
  • Analyzing fragments of MQuery (e.g., Mmu, Mmupg, Mmupgl) using reductions and complexity-theoretic techniques to determine combined and query complexity.
  • Using non-deterministic and deterministic algorithms to evaluate query fragments, particularly leveraging DAG representations to compactly encode intermediate results and manage exponential blowup.
  • Applying reductions from Boolean satisfiability and Turing machine acceptance problems to prove NP-hardness and completeness results.
  • Introducing a well-typing check for queries under type constraints, proving its DP-completeness and TA[2nO(1), nO(1)]-hardness for full query typing verification.

Experimental results

Research questions

  • RQ1Is MongoDB’s query language MQuery expressively equivalent to nested relational algebra (NRA)?
  • RQ2What is the combined complexity of evaluating MQuery fragments, particularly those including unwind, group, and lookup operators?
  • RQ3Can fragments of MQuery that exclude lookup still express arbitrary joins within a single collection, contrary to common belief?
  • RQ4How does the presence of array operators like filter, map, and setUnion affect the complexity of query evaluation in MQuery?
  • RQ5What is the complexity of checking whether a MQuery is well-typed under a given set of type constraints?

Key findings

  • MQuery is expressively equivalent to nested relational algebra (NRA), with polynomial-time translations in both directions, proving that MongoDB can express arbitrary joins within a single collection.
  • The minimal fragment Mm (only match) is LogSpace-complete in combined complexity, indicating tractable evaluation.
  • Adding the unwind operator alone increases complexity to NP-complete in combined complexity, though it remains LogSpace-complete in query complexity.
  • The presence of both unwind and grouping leads to PSpace-hardness, due to the potential for doubly-exponentially large intermediate results.
  • The full MQuery language and the Mmupg fragment (excluding lookup) are complete for alternating exponential time with a polynomial number of alternations, specifically TA[2nO(1), nO(1)], matching the tightest known upper bound for Boolean NRA query evaluation.
  • The problem of checking whether a query is well-typed under a given set of type constraints is DP-complete, and verifying well-typing for all stages is TA[2nO(1), nO(1)]-hard, indicating high complexity for static type checking.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.