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 be a query language, such as the relational calculus (FO), the conjunctive queries (CQ) or Datalog. Its evaluation problem is the set
under set semantics; for a Boolean query, is the empty tuple and the question is whether is true on . The size is the length of a standard encoding of the instance, about the number of tuples times the arity times the length of a constant; is the length of the query. Let be a complexity class.
- Data complexity. For each fixed , consider the problem , with input size . has data complexity in if for every . It is -complete if, in addition, is -hard for some .
- Combined complexity. The problem itself, with input size .
- Expression complexity (also called query complexity). For each fixed , the problem ; has expression complexity in if this is in for every , and -complete if it is also -hard for some .
The data complexity of a language is a statement about each query separately: "polynomial" means that for each there is a polynomial , and the degree of may grow with . 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 . Evaluate it bottom up under active domain semantics: for each subformula with free variables, store the table of the valuations into the active domain that make it true. With values, the table has at most rows, and each connective or quantifier builds a table from smaller ones in time polynomial in . If is the largest number of free variables of a subformula, the time is . For a fixed , is a constant, so the time is polynomial in ; but 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 : one binary relation with the 6 pairs of distinct values from . For a graph with nodes , let be the Boolean CQ with one variable per node and one atom per edge. A valuation that makes the body true is a map from the nodes to that gives different colors to the ends of each edge. So is true on if and only if is 3-colorable. For the cycle of length 5 there are 30 such valuations and is true; for the complete graph there are none and 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 and . A quantified Boolean formula becomes the Boolean FO query , where replaces each by . 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 .
- 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 variables over values tries valuations, for example for and . 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 with independent of is unlikely.
Related definitions
- 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
- 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
- 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
- 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
- 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
- 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)
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag VKD5N6 Edit this page History Report an error Markdown