Algorithm Search⌘K

Definitionadvanced

Data complexity and combined complexity

Also called data complexity, combined complexity.

Vardi's measures of the cost of query evaluation: with the query fixed and only the database as input (data), with both as input (combined), or with the database fixed (expression).

Data complexity and combined complexity are two ways to measure how hard it is to evaluate the queries of a query language. Data complexity fixes the query and counts the cost as a function of the size of the database only; combined complexity counts it as a function of the sizes of both the query and the database. Vardi defined them in 1982, with a third measure, expression complexity, which fixes the database. The difference matters because queries are short and databases are large: first-order queries are cheap in data complexity (in AC0) but PSPACE-complete in combined complexity.

Definition

Let L\mathcal{L} be a query language, such as the relational calculus (FO), the conjunctive queries (CQ) or Datalog. Its evaluation problem is the set

EvalL={ (Q,I,t)∣Q∈L, I an instance, t∈Q(I) },\mathrm{Eval}_{\mathcal{L}} = \{\, (Q, I, t) \mid Q \in \mathcal{L},\ I \text{ an instance},\ t \in Q(I) \,\},

under set semantics; for a Boolean query, tt is the empty tuple and the question is whether QQ is true on II. The size ∣I∣|I| is the length of a standard encoding of the instance, about the number of tuples times the arity times the length of a constant; ∣Q∣|Q| is the length of the query. Let C\mathcal{C} be a complexity class.

  • Data complexity. For each fixed Q∈LQ \in \mathcal{L}, consider the problem EvalQ={(I,t)∣t∈Q(I)}\mathrm{Eval}_Q = \{(I, t) \mid t \in Q(I)\}, with input size ∣I∣+∣t∣|I| + |t|. L\mathcal{L} has data complexity in C\mathcal{C} if EvalQ∈C\mathrm{Eval}_Q \in \mathcal{C} for every Q∈LQ \in \mathcal{L}. It is C\mathcal{C}-complete if, in addition, EvalQ\mathrm{Eval}_Q is C\mathcal{C}-hard for some QQ.
  • Combined complexity. The problem EvalL\mathrm{Eval}_{\mathcal{L}} itself, with input size ∣Q∣+∣I∣+∣t∣|Q| + |I| + |t|.
  • Expression complexity (also called query complexity). For each fixed II, the problem {(Q,t)∣t∈Q(I)}\{(Q, t) \mid t \in Q(I)\}; L\mathcal{L} has expression complexity in C\mathcal{C} if this is in C\mathcal{C} for every II, and C\mathcal{C}-complete if it is also C\mathcal{C}-hard for some II.

The data complexity of a language is a statement about each query separately: "polynomial" means that for each QQ there is a polynomial pQp_Q, and the degree of pQp_Q may grow with QQ. Combined complexity is the worst case over all pairs. Combined complexity is always at least as high as each of the other two.

The standard bounds.

Language Data complexity Combined complexity
CQ in AC0 NP-complete (Chandra and Merlin 1977)
acyclic CQ in AC0 polynomial (Yannakakis 1981)
FO (algebra, calculus) in AC0 PSPACE-complete (Vardi 1982)
Datalog P-complete EXPTIME-complete

The AC0 bound and the PSPACE bound for FO are in Libkin (2004), Chapter 6; Vardi (1982) gave the bound LOGSPACE for the data complexity of FO, and AC0 is smaller. The Datalog bounds are in Vardi (1982) and in the survey of Dantsin, Eiter, Gottlob and Voronkov (2001). For FO and for CQ, the expression complexity is as high as the combined complexity, by the reductions below, which use a fixed database.

Examples and non-examples

  • FO is polynomial in data complexity. Fix an FO query QQ. Evaluate it bottom up under active domain semantics: for each subformula with mm free variables, store the table of the valuations into the active domain that make it true. With nn values, the table has at most nmn^m rows, and each connective or quantifier builds a table from smaller ones in time polynomial in nmn^m. If ww is the largest number of free variables of a subformula, the time is ∣Q∣⋅nO(w)|Q| \cdot n^{O(w)}. For a fixed QQ, ww is a constant, so the time is polynomial in ∣I∣|I|; but ww grows with the query, so this bound says nothing in combined complexity.
  • CQ is NP-hard in combined and in expression complexity. Take the fixed database K3K_3: one binary relation EE with the 6 pairs (a,b)(a, b) of distinct values from {1,2,3}\{1, 2, 3\}. For a graph GG with nodes v1,…,vnv_1, \ldots, v_n, let QGQ_G be the Boolean CQ with one variable per node and one atom E(xu,xv)E(x_u, x_v) per edge. A valuation that makes the body true is a map from the nodes to {1,2,3}\{1, 2, 3\} that gives different colors to the ends of each edge. So QGQ_G is true on K3K_3 if and only if GG is 3-colorable. For the cycle of length 5 there are 30 such valuations and QGQ_G is true; for the complete graph K4K_4 there are none and QGQ_G is false. The database never changes, so the expression complexity is NP-hard; membership in NP holds because a valuation is a certificate. This is the hard half of the result of Chandra and Merlin.
  • FO is PSPACE-hard in combined and in expression complexity. Take the fixed database with Bool={0,1}\mathrm{Bool} = \{0, 1\} and One={1}\mathrm{One} = \{1\}. A quantified Boolean formula ∀p1∃p2⋯θ\forall p_1 \exists p_2 \cdots \theta becomes the Boolean FO query ∀x1(Bool(x1)→∃x2(Bool(x2)∧⋯θ′))\forall x_1 (\mathrm{Bool}(x_1) \rightarrow \exists x_2 (\mathrm{Bool}(x_2) \land \cdots \theta')), where θ′\theta' replaces each pip_i by One(xi)\mathrm{One}(x_i). The query is true on the database if and only if the formula is true. Membership in PSPACE: evaluate the formula by recursion on its structure, with one value per quantified variable on the stack, in space O(∣Q∣log⁡∣I∣)O(|Q| \log |I|).
  • Datalog is P-complete in data complexity. One fixed program, the alternating path or the monotone circuit value program, is P-hard. Every fixed program reaches its least fixed point after a polynomial number of rounds, each of polynomial time; see Datalog evaluation.
  • Non-example: a bound with the wrong measure. "CQ evaluation is NP-complete" and "CQ evaluation is in AC0" are both true, under different measures. A statement of a bound that does not name its measure is incomplete. The same holds for probabilistic databases: the Dalvi-Suciu dichotomy is a statement in data complexity, so a "polynomial-time" query there may still take time exponential in the query.
  • Non-example: a constant that hides the query. A naive evaluator of a CQ with kk variables over nn values tries nkn^k valuations, for example 10610^6 for n=10n = 10 and k=6k = 6. In data complexity this is "polynomial". Papadimitriou and Yannakakis (1999) showed that CQ evaluation, with the query size as parameter, is complete for the parameterized class W[1], so a bound of the form f(k)⋅ncf(k) \cdot n^{c} with cc independent of kk is unlikely.
  • Classes. AC0, LOGSPACE, P, NP, PSPACE and EXPTIME are the classes of the table above.
  • Query containment. The complexity of query containment is a statement about pairs of queries, with no database; for CQs it equals the combined complexity of evaluation, by the canonical database of the Chandra-Merlin theorem.
  • Tractable classes in combined complexity. Acyclic CQs are evaluated by the Yannakakis algorithm in time polynomial in the query, the input and the output. Bounded hypertree width extends this.
  • Codd's theorem. The FO bounds hold for relational algebra too, by Codd's theorem, whose translations are polynomial in size.
  • Counting and probability. For a probabilistic database the question is the probability of the answer, and the class is the counting class #P (see model counting) rather than a decision class; see probabilistic database.

References

  1. Moshe Y. Vardi, The complexity of relational query languages (extended abstract), Proceedings of the 14th Annual ACM Symposium on Theory of Computing (STOC), 137 to 146 (1982), the definitions of data complexity and expression complexity, and the bounds for the calculus, its fixpoint extensions and the algebra with loops
  2. Ashok K. Chandra and Philip M. Merlin, Optimal implementation of conjunctive queries in relational data bases, Proceedings of the 9th Annual ACM Symposium on Theory of Computing (STOC), 77 to 90 (1977), the evaluation of conjunctive queries is NP-complete when the query is part of the input
  3. Leonid Libkin, Elements of Finite Model Theory, Springer (2004), Chapter 6 (complexity of first-order logic), Section 6.1 (data, expression and combined complexity) and Section 6.5 (combined complexity of FO), with the AC0 bound for data complexity
  4. Evgeny Dantsin, Thomas Eiter, Georg Gottlob and Andrei Voronkov, Complexity and expressive power of logic programming, ACM Computing Surveys 33(3), 374 to 425 (2001), data complexity P-complete and combined complexity EXPTIME-complete for Datalog
  5. Serge Abiteboul, Richard Hull and Victor Vianu, Foundations of Databases, Addison-Wesley (1995), Chapter 6 (the complexity of conjunctive query evaluation) and Part E (expressiveness and complexity of query languages)
  6. Mihalis Yannakakis, Algorithms for acyclic database schemes, Proceedings of the 7th International Conference on Very Large Data Bases (VLDB), 82 to 94 (1981), evaluation of acyclic conjunctive queries in time polynomial in the input and the output
  7. Christos H. Papadimitriou and Mihalis Yannakakis, On the complexity of database queries, Journal of Computer and System Sciences 58(3), 407 to 427 (1999), parameterized complexity of query evaluation, with the size of the query as the parameter

Where this leads

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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/VKD5N6/text.yaml