1 Introduction

The goal of Knowledge Compilation [6, 13, 27] is to represent a Boolean expression in a language in which it can answer a range of problems, also called “online-queries”, in PTIME. Typical problems are satisfiability, validity, implication, model counting, substitution with constants, and substitution with functions. For example, the model counting problem asks for the number of satisfying assignments to a Boolean expression; the more general probability computation problem asks for the probability of that expression being true, if every variable is true/false independently with some probability. If one compiles the Boolean expression into (say) an FBDD, then the model counting problem and the probability computation problem can be solved in linear time in the size of the FBDD. Different compilation languages can solve efficiently different classes of problems, in time polynomial in the size of compiled expression [13]. This motivates the need to know if an expression can be compiled into a small-sized or compact representation in a given language.

The provenance of a query on a relational database is an expression that describes how the answer was derived from the tuples in the database [17]. In this paper, we are interested in the flavor of provenance called PosBool in [25] (see also [18]), which we will refer to as lineage. The lineage is a Boolean expression over Boolean variables corresponding to tuples in the input database. Our goal in this paper is to identify queries whose lineage admits a compact compilation. Our main motivation comes from (but is not limited to) probabilistic databases, where the problem is the following: given a query and a probabilistic database (i.e. each tuple has a given probability), compute the probability of each query answer [10]. If the lineage has been compiled into a compact format that supports the probability computation, then one can compute the output probabilities efficiently. In this paper we study queries whose lineage always admits a compact compilation, on any database instance. We are only interested in the data complexity i.e., we assume the query to be fixed (and, in particular its size is constant). Our query language is that of unions of conjunctive queries, UCQ, and, as usual, we restrict our discussion to Boolean queries.

We consider four compilation targets. For each target T, we denote by UCQ(T) the class of UCQ queries whose lineage admits a compact compilation in T for all input databases: the precise definition of the term “compact” depends on the compilation target, but usually means that the target has polynomial size. There are two different ways of defining a compact compilation: (i) Uniform: A compact compilation can be found in polynomial time, (ii) Non-Uniform: A compact compilation exists, but there are no restrictions on how to find it. The first interpretation is more strict, but makes more practical sense if one is looking for tractable algorithms for compilation; all our upper bounds are for uniform compilation. The second interpretation is more useful in complexity theory, since the results show the expressibility, and limitation of different models of compilation/computation; all our lower bounds are for non-uniform compilation. Unless stated otherwise, we always assume that the compilation is uniform, except in Sect. 7 where we focus exclusively on non-uniform compilation.

Our first target is the class of read-once expressions, denoted RO. A read-once Boolean expression is an expression consisting of ∧, ∨, ¬ operators in such a way that every input variable is used only once. A read-once Boolean formula is one that can be represented by a read-once expression. read-once formulas admit an elegant characterization due to Gurvich [19] (see [16]). Thus, UCQ(RO) is the class of queries q such that for every input database, the lineage of q on that database is a read-once formula. Our second and third targets are Ordered and Free Binary Decision Diagram. A Binary Decision Diagram Footnote 1(BDD) is a rooted DAG where each internal node is labeled with a variable and has two outgoing edges labeled 0 and 1, and each sink node is labeled either 0 or 1. A BDD represents a Boolean function, as follows. Given an assignment to the Boolean variables, the value of the function is obtained by traversing the BDD starting at the root node, and at each internal node following either the 0 or the 1 edge, according to the value of that node’s variable. The unique sink node reached at the end of the traversal gives the value (0 or 1) of the Boolean function under that assignment. A BDD is free (hence FBDD) if any path from the root to a sink node reads every variable at most once. An FBDD is ordered (hence OBDD) if there exists a total order on the Boolean variables s.t. any path from the root to a sink node reads the variables in this order (it may skip some variables). Thus, UCQ(OBDD) and UCQ(FBDD) denote the class of queries q s.t. that for any database instance D, one can construct an OBDD (FBDD) for the lineage of q on D, in time polynomial in D; in particular, the resulting OBDD or FBDD also has size polynomial in D. Finally, our fourth target is the language of deterministic-Decomposable Negation Normal Form(d-DNNF) introduced by Darwiche [12] (see also [13]), which are DAGs whose leaves are labeled with literals (Boolean variables or negated Boolean variables), and internal nodes are labeled either an independent-∧ (where the two children must have distinct sets of Boolean variables), or with disjoint-∨ (where the two children must be exclusive Boolean formulas). We also allow for one more type of internal node: not (¬). UCQ(dDNNF) represents the class of queries s.t. one can construct a d-DNNF of its lineage in PTIME for any input database.

In addition to these four classes defined by a compilation target, we also consider UCQ(P), the class of queries q with the property that, for every probabilistic database D, the probability of q on D can be computed in PTIME in the size of D. It follows from known results that these five classes form an increasing hierarchy: UCQ(RO)⊆UCQ(OBDD)⊆UCQ(FBDD)⊆UCQ(dDNNF)⊆UCQ(P).

Dalvi and Suciu [9, 10] have studied the evaluation problem over probabilistic databases for conjunctive queries without self-joins, denoted here CQ , and showed that the class of queries computable in PTIME, CQ (P), consists precisely of hierarchical queries (reviewed in Sect. 2). Olteanu and Huang [20] have shown a remarkable result: that for any hierarchical query, its lineage is a read-once formula. In other words, they explained that the reason why hierarchical queries can be computed in PTIME is because their lineage is read once. This immediately implies (assuming FP≠#P ) that the following five classes collapse: CQ (RO)=CQ (OBDD)=CQ (FBDD)=CQ (UCQ)=CQ (P).

In this paper we show that, over unions of conjunctive queries (UCQ), these classes no longer collapse. In fact they form a strict hierarchy:

$$\mathit{UCQ}(\mathit{RO}) \subsetneq \mathit{UCQ}(\mathit{OBDD}) \subsetneq \mathit{UCQ}(\mathit{FBDD}) \subsetneq \mathit{UCQ}(\mathit{dDNNF}) \subseteq \mathit{UCQ}(P)$$

This means that the reason why certain queries can be computed in PTIME over probabilistic databases is no longer their read-once-ness, or any other efficient compilation method (We were not able to separate UCQ(dDNNF) from UCQ(P) but we conjecture that they are also separated). Instead, each notion of efficiency is distinct. We refer to Table 1 to discuss our results.

Table 1 Several representative queries defined in Table 2. All queries are hierarchical, and have the additional syntactic properties shown. \(\hat{0}\) denotes the minimal element of the query’s CNF-lattice; μ its Mobius function. Queries q 2, q V , q W separate the corresponding classes. We conjecture that q 9 separates UCQ(dDNNF) from UCQ(P). : assuming FP≠#P; ?: conjectured
Table 2 Important queries used throughout the paper

Our results make use of three syntactic properties of a query, called inversion [8], separator [11], and hierarchical queries [10], reviewed in Sect. 2. The following strict implications hold: inversion-free implies existence of separators at all levels, which implies the query is hierarchical.

We give a complete characterization of UCQ(RO) and UCQ(OBDD). First, UCQ(OBDD) coincides with inversion-free queries. UCQ(RO) coincides with queries that are both inversion-free and can be written using ∧,∨,∃ such that every relation symbol occurs only once. For example, consider the query q 1 in Table 1, q 1=∃x 1.∃y 1.R(x 1),S(x 1,y 1)∨∃x 2.∃y 2.T(x 2),S(x 2,y 2); in this paper we drop existential quantifiers when they are clear from the context, and write the query as q 1=R(x 1),S(x 1,y 1)∨T(x 2),S(x 2,y 2). The query can also be written as ∃x.((R(x)∨T(x))∧∃y.(S(x,y))): here each symbol R,S,T occurs only once and, since q 1 is also inversion-free, it follows that it is in UCQ(RO). Note that our characterization of UCQ(RO) is unrelated to Gurvich’s characterization of read-once Boolean expressions [16, 19], or to algorithms for checking read-once-ness in [21, 23]: these results apply to the Boolean formula, while our results apply directly to the query.

For UCQ(FBDD) and UCQ(dDNNF), we only give sufficient conditions by making use of the CNF-lattice associated to a query (introduced in [11]), where each lattice element x is labeled by a subquery, denoted λ(x). A sufficient condition for a query to be in UCQ(FBDD) is for every lattice element to have a separator and to satisfy certain additional conditions (see Sect. 6). A sufficient condition for UCQ(dDNNF) is that every lattice element must have a separator, except those lattice elements that can be erased (a notion we define in Sect. 6). For comparison, the necessary and sufficient condition for UCQ(P) is that every lattice element must have a separator, except those lattice elements where the Mobius function is 0 (μ=0) [11]. If an element can be erased, then its Mobius function is 0, but the converse is not true, as illustrated by q 9 in Table 1. We conjecture that q 9 is not in UCQ(dDNNF).

The most difficult results in this paper are the separation results UCQ(OBDD)⊆̷UCQ(FBDD)⊆̷UCQ(dDNNF); they are separated by the queries q V and q W respectively in Table 1. In each case we prove that the query does not belong to the smaller class, but that it belongs to the larger class. The separation between UCQ(OBDD) and UCQ(FBDD) extends even to the non-uniform definition of the complexity class. More precisely, we show q V UCQ(OBDD), even if one assumes the non-uniform definition of UCQ(OBDD), and that q V UCQ(FBDD); similarly q W UCQ(FBDD), even for a non-uniform definition of this class, and q W UCQ(dDNNF). These results are significant for the following reason. All lineage expressions for queries in UCQ are very simple: they are monotone, and have a DNF expression of polynomial size. This also applies to the lineage expressions of q V and q W . Thus, our lower bounds make a contribution to the general separation problem of polynomial-size OBDD, FBDD, and d-DNNF. Early lower bounds for FBDD were for non-monotone formulas, with exponential size DNFs. The first “simple” Boolean formula shown to have exponential FBDD was given by Gál in [14], followed by a “very simple” formula given by Bollig and Wegener [1]. But it is not very surprising that the “very simple” has no polynomial size FBDDs, since computing the probability of that formula is #P-hard: the “very simple” formula is precisely the lineage of the non-hierarchical query R(x),S(x,y),T(y), for which computing the probability is #P-hard. In contrast, for both q V and q W one can compute the probability in polynomial time: hence, the fact that they do not admit polynomial size OBDDs or polynomial size FBDDs respectively is more surprising. On the other hand, we can use Bollig and Wegener’s result to prove that, for every non-hierarchical query, its lineage has no polynomial size FBDD.

The lineage of the query q V , that we use for the first major separation between UCQ(OBDD) and UCQ(FBDD) is, to the best of our knowledge, the first “simple” Boolean formula separating polynomial-size OBDD from FBDD. Previous Boolean formulas separating the two classes are non-monotone, and do not have polynomial size DNFs. The classic example is the Weighted Bit Addressing problem (WBA), defined as \(F(X_{1}, \ldots, X_{n}) =X_{\sum_{i=1,n} X_{i}}\) (where X 0=0). Bryant [5] has shown that it has no polynomial size OBDD, while Gergov and Meinel [15] and independently Sieling and Wegener [24] have shown that WBA has a polynomial sized FBDD. More examples are given in [26]. Our characterization of UCQ(OBDD) and UCQ(FBDD) allows one to give a class of simple Boolean expressions that separate polynomial-size OBDD from FBDD.

The lineage of the query q W that we use for our second major separation between UCQ(FBDD) and UCQ(dDNNF) is also, to the best of our knowledge, the first “simple” Boolean formula separating polynomial-size FBDD from d-DNNF. The previous separation relies on a result due to Bollig and Wegener [2]: they give an example of two Boolean formulas Φ 1,Φ 2 that have polynomial size OBDD, Φ 1Φ 2false, yet Φ 1Φ 2 cannot have polynomial size FBDD. Hence Φ 1Φ 2 separates d-DNNF from FBDD.

Finally, we note that no formula with exponential lower bound on d-DNNF size is presently known. In particular, we leave open the question whether UCQ(dDNNF)⊆̷UCQ(P). However, our algorithm in Sect. 6 suggests how d-DNNF may be constructed for general queries, which further suggests that this is not possible for q 9. We conjecture that q 9 is not in UCQ(dDNNF), and, hence, that its lineage has no polynomial size d-DNNF.

The paper is organized as follows. We give the basic definitions and review the relevant results in [11] in Sect. 2, then discuss read-once, OBDD, FBDD, and d-DNNF in Sect. 3, Sect. 4, Sect. 5, Sect. 6. We discuss results for non-uniform setting in Sect. 7 and conclude in Sect. 8.

2 Background and Definitions

In this paper we discuss unions of conjunctive queries (UCQ), which are expressions defined by the following grammar:

(1)

\(R(\bar{x})\) is a relational atom with variables and/or constants, whose relation symbol R is from a fixed vocabulary. We replace ∧ with comma, and drop ∃, when no confusion arises. Comma or ∧ operator takes precedence over ∨. For example we write R(x),S(x,y)∨T(y) for ∃x.(R(x)∧∃y.S(x,y))∨∃y.T(y).

A query is an expression as defined by (1), up to logical equivalence. We consider only Boolean queries in this paper. A conjunctive query (CQ) is a query that can be written without ∨. A conjunctive query admits an alternative representation, as a set of atoms, \(R_{1}(\bar{x}_{1}), \ldots, R_{m}(\bar{x}_{m})\). Given two conjunctive queries q,q′, the logical implication qq′ holds iff there exists a homomorphism q′→q between their representations as sets of atoms [7].

Let D be a database instance. Denote X t a distinct Boolean variable for each tuple tD. If tD, X t false. Let Q be a UCQ. The lineage of Q on D is the Boolean expression \(\varPhi ^{D}_{Q}\), or simply Φ Q if D is understood from the context, defined inductively as follows, where ADom(D) denotes the active domain of the database instance:

(2)
(3)

Given a probability p(X t )∈[0,1] for each Boolean variable X t , we denote \(P(\varPhi _{Q}^{D})\) the probability that the Boolean formula \(\varPhi _{Q}^{D}\) is true, when each Boolean variable X t is set to 1 independently, with probability p(X t ).

A probabilistic database is a pair (D,p) where D is a database and p(t)∈[0,1] assigns a probability to each tuple tD. Given a Boolean query Q and a probabilistic database (D,p), the query probability P(Q) is defined as \(P(Q) =P(\varPhi _{Q}^{D})\), where in the latter expression each Boolean variable X t has a probability equal to that of its corresponding tuple, p(X t )=p(t).

The query evaluation problem on probabilistic databases is the following: given a query Q and a probabilistic database (D,t), compute P(Q). Usually we are interested in the data complexity of the query evaluation problem: for a fixed Q, determine the complexity of computing P(Q) as a function of the input database (D,p).

Definition 1

UCQ(P) is the class of UCQ queries Q s.t. for any probabilistic database (D,p), the probability P(Q) can be computed in PTIME in the size of D.

A complete characterization of the class UCQ(P) was given in [11]. We review it here, since we will reuse some of the same concepts that characterize the class UCQ(P) to characterize various compilation targets.

We start by discussing connected queries. Consider a conjunctive query q given by the set of its atoms \(R_{1}(\bar{x}_{1}), \ldots,R_{m}(\bar{x}_{m})\), and assume this representation is minimal, i.e., removing any atom results in an inequivalent query; it is known that this minimal representation is unique up to isomorphism [7]. Define the following undirected graph G: there is one node for each atom, and there is an edge from atom i to atom j if \(R_{i}(\bar{x}_{i})\) and \(R_{j}(\bar{x}_{j})\) share a common variable. We say that the query q is connected if the graph G is connected.

Lemma 1

Suppose we restrict all conjunctive queries to be without constants. Let q be a conjunctive query. Then the following conditions are equivalent. (1) The query q is connected. (2) For every two conjunctive queries q 1,q 2, if q 1q 2q then either q 1q or q 2q. (3) For every two conjunctive queries q 1,q 2, if qq 1q 2 then either qq 1 or qq 2.

Proof

(1) implies (2). Assuming q 1q 2q we obtain a homomorphism qq 1q 2. Since neither q 1 nor q 2 have constants, the homomorphism must map every variable in q to a variable in q 1q 2. Since q is connected, the image of this homomorphism must be a connected graph, and, therefore, it is included either in q 1 or in q 2; this means that the homomorphism is either qq 1 or qq 2, implying either q 1q or q 2q.

(2) implies (3). Assume q 1q 2q. In particular, q 1q 2q, and by property (2) we have q 1q or q 2q. Assuming the former, we derive q 1q 1q 2, which further implies q 1q 1q 2q. The latter case is symmetric.

(3) implies (1). Suppose that q is not connected. Suppose its minimal representation has m atoms. Let G be the graph corresponding to its minimal representation. We can partition its nodes into two sets, each with strictly less than m atoms, s.t. they do not share any variables. Thus, we have written q=q 1q 2 where q 1,q 2 share no common variables and each has strictly less than m atoms. By condition (3) it follows that either q 1q or q 2q. Assuming the former, we have qq 1, contradicting the fact that the minimal representation of q has m atoms. The latter case follows similarly too. □

The restriction to conjunctive queries without constants is necessary for the lemma to hold. Otherwise, consider the connected query q=R(x,y),S(y,z), and q 1=R(x,a), q 2=S(a,z), where a is a constant and x,y,z are variables: we have q 1q 2q but neither q 1q nor q 2q holds.

We now define the key notions needed to characterize UCQ(P), and which we need throughout this paper:

  • A component, c, is a conjunctive query that is connected.

  • Every conjunctive query can be written as a conjunction of components. That is, q=c 1,c 2,…,c k , s.t. c i and c j do not share any common variables, for all ij. If q=c 1,c 2,… and \(q' = c_{1}', c_{2}', \ldots\) are two conjunctive queries given as conjunction of components, and if they do not have any constants, then the logical implication qq′ holds iff ∀j.∃i s.t. \(c_{i}\Rightarrow c_{j}'\).

  • A disjunctive query is a disjunction of components, d=c 1∨⋯∨c k . Given two disjunctive queries d=c 1c 2∨⋯ and \(d' = c_{1}' \vee c_{2}' \vee \cdots{}\), the logical implication dd′ holds iff ∀i.∃j s.t. \(c_{i} \Rightarrow c_{j}'\).

  • A UCQ in DNF is a disjunction of conjunctive queries, Q=q 1∨⋯∨q m . Given two queries in DNF, Q=q 1q 2∨⋯ and \(Q' = q_{1}' \vee q_{2}' \vee \cdots{}\), the logical implication QQ′ holds iff ∀i.∃j s.t. \(q_{i} \Rightarrow q_{j}'\).

  • A UCQ in CNF is a conjunction of disjunctive queries, Q=d 1∧⋯∧d m . Given two queries in CNF, Q=d 1d 2∧⋯ and \(Q' = d_{1}' \wedge d_{2}' \wedge \cdots{}\), if they do not have any constants, then the implication QQ′ holds iff ∀j.∃i s.t. \(d_{i}\Rightarrow d'_{j}\).

Obviously, any component is both a conjunctive query and a disjunctive query; also, every conjunctive query is a UCQ in DNF, and every disjunctive query is a UCQ in CNF.

The containment condition for DNF is due to Sagiv and Yannakakis [22]. The containment condition for CNF is from [11], and only holds if the queries have no constants. To see that this requirement is needed, consider the following three disjunctive queries: d 1=R(x,a), d 2=S(a,z), and d=R(x,y),S(y,z), where a is a constant and x,y,z are variables. Define the following two UCQ’s: Q=d 1,d 2 and Q′=d. Both are in CNF, and QQ′, yet neither d 1d nor d 2d holds.

Following [11] we first perform the following transformations on the query. They preserve the lineage of the query and hence membership in UCQ(P) and all the classes considered in this paper.

Remove constants :

Every query with constants is rewritten into an equivalent query without constants, over an extended vocabulary, by repeatedly substituting a relation R(A 1,…,A k ) with 2 relations: \(R_{1} = \sigma_{A_{i} \neq a}(R)\) and \(R_{2} = \varPi _{A_{1}\ldots A_{i-1} A_{i+1} \ldots A_{k}}(\sigma_{A_{i}=a}(R))\), for every attribute position i and every constant a that occurs in the query. For example, R(x,a),S(x)∨R(x,y),T(x) is rewritten as R 2(x),S(x)∨R 2(x),T(x)∨R 1(x,y),T(x), where R 1(x,y)=σ ya (R(x,y)), and R 2(x)=π x (σ y=a (R(x,y))).

Ranking :

Assume an ordered domain. A query is ranked if it remains consistent after adding all predicates of the form x<y, for all pairs of variables x,y that co-occur in some atom, such that x occurs before y. For example, R(x,y),R(y,z),R(x,z) is ranked because x<yy<zx<z is consistent, while R(x,y),S(y,x) is not ranked (x<yy<x is inconsistent), and R(x,x,y) is not ranked (x<xx<y is inconsistent). Every query is rewritten into an equivalent, ranked query, over an extended vocabulary, by repeatedly substituting a relation R(A 1,…,A k ) with three relations \(R_{1} = \sigma_{A_{i} < A_{j}}(R)\), \(R_{2} = \varPi _{A_{1} \ldots A_{j-1} A_{j+1} \ldots A_{k}}(\sigma_{A_{i} =A_{j}}(R))\), \(R_{3} = \varPi _{A_{1} \ldots A_{j} \ldots A_{i} \ldots A_{k}}(\sigma_{A_{i} > A_{j}}(R))\), for every two attributes A i ,A j s.t. i<j. We give here the main intuition by illustrating with q=R(x,y),R(y,x), and refer to [11] for further details. Denoting R 1(x,y)=σ x<y (R), R 2(x)=π x (σ x=y (R(x,y))), R 3(y,x)=π yx (σ x>y (R)), we rewrite the query as R 2(x)∨R 1(x,y),R 3(x,y). The new query is ranked.

The reason for the first transformation is to ensure that the implication criteria for CNF expressions hold. As a consequence, every UCQ has a unique, minimal representation in DNF, and a unique, minimal representation in CNF. The reason for the second transformation will become clear below. We will assume throughout the paper that a CNF or DNF expression of a query is minimized.

The first step in characterizing UCQ(P) is to describe a class of disjunctive queries that are hard for #P, using the notion of a separator. Consider a query, and a subexpression of the form ∃w.Q (see grammar equation (1)): the scope of the variable w is the subexpression Q.

Definition 2

A variable w is called a root variable if it occurs in all atoms in its scope.

For a simple illustration, consider ∃x.∃y.R(x)∧S(x,y). Then x is a root variable, but y is not. However, we can write the query equivalently as ∃x.R(x)∧(∃y.S(x,y)): now both x and y are root variables.

Definition 3

A disjunctive query d has a separator if it can be written as d≡∃w.Q, such that w is a root variable, and for every two atoms g,g′ using the same relational symbol R, the variable w occurs in the same position in g and in g′. In this case the variable w is called a separator variable in the expression ∃w.Q.

The hardness part of characterizing UCQ(P) consists of showing that, if a disjunctive query has no separator then it is hard for #P: hence, it cannot be in UCQ(P) unless FP=#P. Recall that we assume all queries to be without constants, ranked, and minimized.

Theorem 1

([11])

Let d be a disjunctive query s.t. each component has at least one variable. If d has no separator, then d is hard for #P.

If d has any component without variables then it trivially has no separator. For example, consider d=R()∨S(x): the first component, R(), has no variables, and clearly d has no separator, e.g. if we write it as ∃x.(R()∨S(x)) then x is not a root variable. However, it is always easy to get rid of the components without variables, then apply Theorem 1. Indeed, write the disjunctive query as d=d 0d′ where d 0 contains all components without variables and d′ contains all components with variables. Thus, d 0 is a disjunction R 1()∨R 2()∨⋯ of zero-ary relational symbols, and d′ is a disjunction of components c 1c 2∨⋯, each having at least one variable. None of the symbols R i () occurs in any component c j , otherwise c j would not be connected. Thus, d 0 and d′ are independent probabilistic events, and P(d)=1−(1−P(d 0))(1−P(d′)), in other words computing P(d) reduces to computing P(d′), and this is the reason why the theorem focuses only on the latter. Note that the theorem holds only if the query is ranked: for a counter-example, R(x,y),R(y,x) has no separator, yet is in UCQ(P) (this follows from the ranking shown above, and from Theorem 2 below); this is the reason why we rank queries.

Conversely, if d has a separator, d=∃w.Q, then its probability can be computed as P(d)=1−∏ i (1−P(Q[a i /w])), where a 1,…,a n is the active domain of the database, because no two queries among Q[a 1/w],…,Q[a n /w] have any tuple in common. Furthermore, this can be computed efficiently, provided that each query Q[a i /w] is in UCQ(P). Although we disallowed constants in queries, the expression Q[a i /w] is OK because all occurrences of a relational symbol have the constant a in the same position; we simply remove a from all atoms, renaming all relational symbols, and decreasing their arity by 1.

Example 1

Query q 1 in Table 1 has a separator, becauseFootnote 2 q 1≡∃w.(R(w),S(w,y 1)∨T(w),S(w,y 2)). We can compute its probability as P(q 1)=1−∏ i (1−P(R(a i ),S(a i ,y 1)∨T(a i ),S(a i ,y 2))). Query h 1, on the other hand, does not have a separator: if we write it as ∃w.(R(w),S(w,y 1)∨S(w,y 2),T(y 2)) then w is not a root variable, and if we write it as ∃w.(R(w),S(w,y 1)∨S(x 2,w),T(w)) then w occurs in different positions in S(w,y 1) and S(x 2,w). Therefore, h 1 is hard for #P.

Consider a UCQ in CNF: Q=d 1∧⋯∧d k . For each subset s⊆[k] denote d s =⋁ is d i . The inclusion/exclusion formula gives us P(Q)=−∑ s≠∅(−1)|s| P(d s ) and, therefore, if all d s are in UCQ(P) (in particular, they have separators), then so is Q. The formula is exponential in the size of the query, but this does not affect data complexity. However, the condition d s UCQ(P) is not necessary for all s: some terms in the inclusion/exclusion formula may cancel out, and Q may be in UCQ(P) even if some disjunctive queries d s are hard.

To characterize precisely when Q is in UCQ(P), [11] defines the CNF lattice (L,≤) for Q. Each element xL corresponds to a distinct disjunctive query, denoted λ(x)=d s , for some s⊆[k], up to logical equivalence; that is, if \(d_{s_{1}} \equiv d_{s_{2}}\) then they correspond to the same element in xL. The order relation ≤ is reversed logical implication: xy iff λ(y)⇒λ(x).

The maximal element in the lattice is denoted \(\hat{1}\), and corresponds to d false: all other elements correspond to non-trivial disjunctive queries d s . The minimal element of the lattice is denoted \(\hat{0}\), and corresponds to \(\lambda(\hat{0}) = d_{1} \vee \cdots \vee d_{k}\). Three examples are shown in Fig. 1.

Fig. 1
figure 1

CNF Lattices for the queries q V ,q W , and q 9 from Table 2. In the lattices for q W and q 9, \(\mu(\hat{0}, \hat{1}) = 0\); in all other cases, \(\mu(x, \hat{1}) \neq 0\). In q W the element \(\hat{0}\) is erasable; in q 9, the element \(\hat{0}\) is not erasable

We say x covers y if yx and there is no zL s.t. y<z<x. We call x an atom if it covers \(\hat{0}\); it is a co-atom if it is covered by \(\hat{1}\). Denote by L the set of co-atoms. The meet closure of SL is the lattice: \(\overline{S} = \{ \bigwedge T \mid T \subseteq S \}\). Note that \(\bigwedge \emptyset = \hat{1}\), the meet closure of any set S contains the maximal element \(\hat{1}\).

The Mobius function of a lattice (L,≤) is the function μ L :L×LZ defined by μ L (x,x)=1, μ L (x,y)=−∑ x<zy μ L (z,y). Note that μ L (x,y)=0 whenever \(x \not \leq y\). We will drop the L, i.e. denote μ L by simply μ, henceforth when it is clear from the context. Mobius’ inversion formula applied to P(Q) is: \(P(Q) = - \sum_{x < \hat{1}} \mu(x,\hat{1}) P(\lambda(x))\). Now it becomes obvious that we only need to compute P(d s ) for those queries for which \(\mu(x, \hat{1}) \neq 0\). This justifies:

Definition 4

(Safe queries) ([11])

(1) Let Q=d 1∧⋯∧d k , and k≥2. Then Q is safe if for every element x in its CNF lattice, if \(\mu(x,\hat{1})\neq 0\), then the disjunctive query λ(x) is safe (recursively). (2) Let d=d 0d 1, be a disjunctive query where d 0 contains all components without variables, and d 1 contains all components with at least one variable. Then d is safe if d 1 has a separator w and d 1[a/w] is safe (recursively), for a constant a.

The characterization of UCQ(P) is:

Theorem 2

([11])

Any safe query is in UCQ(P). Any unsafe query is hard for #P.

The first part of the theorem follows from our discussion so far. The second part is proven in [11] by using Theorem 1.

This completes the characterization of UCQ(P) from [11]. We still need to introduce two more notions that we use in the rest of the paper: hierarchical queries and inversion-free queries.

Hierarchical Queries

Let q be a conjunctive query, and denote Vars(q) the set of variables used in the query and at(x) the set of atoms containing a variable xVars(q). We say that q is hierarchical if for any two variables x,y, we have at(x)⊆at(y) or at(x)⊇at(y), or at(x)∩at(y)=∅. A UCQ query Q is hierarchical if it is the union of hierarchical conjunctive queries. We give an alternative definition next:

Definition 5

Let Q be a query expression given by the grammar equation (1). We say that it is a hierarchical expression if every variable is a root variable.

It is easy to check that a query is hierarchical iff it can be written as a hierarchical expression. For example, the query R(x,y),S(x,z) is hierarchical, because it can be written as ∃x.(∃y.R(x,y)∧∃z.S(x,z)). Examples of non-hierarchical queries are R(x),S(x,y),T(y) and R(x,y),R(y,z),R(x,z). The following is easy to see:

Proposition 1

If Q is safe, then it is hierarchical.

Proof

By induction on the structure of Q. If Q=d 1∧⋯∧d k , then each d i corresponds to a co-atom x in the CNF lattice, hence \(\mu(x,\hat{1}) = -1 \neq 0\), and therefore d i must be safe, hence it is hierarchical by induction, hence Q is hierarchical. If Q=d 0d 1 and d 1 has a separator, d 1=∃w.Q 1, then Q 1[a/w] is safe, hence it is hierarchical by induction, hence ∃w.Q 1 is hierarchical because w occurs in all atoms of Q 1. □

The converse is not true: for example h 1 in Table 1 is hierarchical, but unsafe. Thus, all non-hierarchical queries are #P-hard, but the converse fails in general.

Inversions

Inversions were first defined in [8]. In this paper we show how to use inversions to characterize UCQ(RO) and UCQ(OBDD). Let Q=q 1∨⋯∨q k be a query in DNF. The unification graph G has as nodes all pairs of variables (x,y) that co-occur in some atom, and has an edge between (x,y) and (x′,y′) if the following holds: x,y co-occur in some atom g , x′,y′ co-occur in some atom g′, the atoms g and g′ are over the same relation symbol and x,y appear at the same positions in g as x′,y′ in g′. In other words, g and g′ are unifiable, and the unification equates x=x′ and y=y′. Given x,yVars(q i ), denote xy if \(at(x)\not\subseteq at(y)\).

Definition 6

(Inversion) ([8])

An inversion in Q is a path of length ≥0 in G from a node (x,y) to a node (x′,y′) s.t. xy and x′≺y′. If no such path exists, we say Q is inversion-free.

If a query is non-hierarchical then it has an inversion. Indeed, let x,y be two variables occurring in the same non-hierarchical conjunctive query, such that at(x)∩at(y)≠∅ and neither of the two sets at(x), at(y) contains the other. Consider the node (x,y) in the unification graph (such a node exists because at(x)∩at(y)≠∅). Since we have both xy and xy, the empty path starting and ending at (x,y) is an inversion. The converse fails: h 1 in Table 1 is hierarchical, yet has an inversion, from (x 1,y 1) to (x 2,y 2).

We give now an alternative, syntactic characterization of an inversion-free query, which we need later. Consider a query expression Q given by the grammar equation (1). Let g be an atom in Q, over the relation symbol R of arity k; thus g contains k distinct variables. Assume the existential quantifiers of these k variables are in the following order: ∃x 1,∃x 2,…,∃x k . In other words, each variable x i+1 is within the scope of x i . Define π g to be the permutation for which \(g = R(x_{\pi_{g}(1)}, \ldots, x_{\pi_{g}(k)})\).

Definition 7

A query expression Q given by the grammar equation (1) is an inversion-free expression if it is a hierarchical expression, and for any two atoms g 1, g 2 with the same relational symbol, \(\pi_{g_{1}} =\pi_{g_{2}}\).

If Q is a hierarchical expression and R a relational symbol, then we write π R for the common permutation π g of all atoms g with symbol R. We have the following equivalence:

Proposition 2

Q is inversion free iff it can be written as an inversion-free expression.

Proof

We first show how to write an inversion-free query as an inversion-free expression. Let Q be inversion free. We will define an order relation xy on Q’s variables s.t. (a) for every atom g, ⋙ is total over the set of variables occurring in g, and (b) if g, g′ are two atoms with the same relation symbol R then the order imposed by ⋙ on the attributes of R is the same in g and g′. The order ⋙ gives us immediately the permutation π g for every atom g; since Q can be written as a union of conjunctive queries, each of which is hierarchical, it follows that Q can be written as an inversion-free expression. To define ⋙, we first define a weaker relation ≫: xy if there exists a path in the unification graph from a node (x,y) to a node (x′,y′) s.t. x′≻y′. Clearly ≫ is antisymmetric, because if we have both xy and xy then the graph has an inversion. We prove that ≫ is transitive. Indeed, suppose xy and yz. By definition there exists a unification path (y,z),(y 1,z 1),(y 2,z 2),…,(y k ,z k ) s.t. y k z k . Consider the first edge of this path: there exists two atoms g,g 1 with the same relation name, g contains y,z, and g 1 contains y 1,z 1 on the same position. Then g must contain x as well (otherwise xy contradicting xy). Denote x 1 the variable on the same position in g 1: since xy and yz we have x 1y 1 and y 1z 1. Repeating the same argument we find variables x i s.t. x i y i and y i z i , for i=1,k. Since y k z k , it also follows that x k z k (because x k y k implies at(x k )⊇at(y k ) hence \(\mathit{at}(x_{k}) \not\subseteq \mathit{at}(z_{k})\)), proving that xz. Therefore, ≫ defines a partial order on the set of variables. It is not a total order yet, because it may leave pairs of variables unordered. To make it a total order, we use the fact that the query Q is ranked, and define xy to be: xy or (\(x \not\ll y\) and there exists an atom g containing both x and y s.t. x occurs before y). It is easy to check that ⋙ is a partial order, and for any atom g it is total over its set of variables.

Now, suppose Q can be written as an inversion-free expression and still has an inversion from a node (x,y) to node (x′,y′) s.t. xy and x′≺y′. Let π be the order in which variables are introduced in the inversion-free expression. Then x,y appear in the same order in π as x′,y′. W.l.o.g., lets assume x occurs before y. Then x′ occurs before y′. But we have y′≻x′, hence x′ couldn’t have been a root variable when it was introduced which violates the fact that every inversion-free expression is also a hierarchical expression, a contradiction. This completes the proof. □

For example, consider q 1 in Table 1. On one hand we can write it as a union of conjunctive queries, q 1=R(x 1),S(x 1,y 1)∨T(x 2),S(x 2,y 2). The unification graph has four nodes, (x 1,y 1),(y 1,x 1),(x 2,y 2),(y 2,x 2), and two edges ((x 1,y 1),(x 2,y 2)) and ((y 1,x 1),(y 2,x 2)). We have both x 1y 1 (because \(\mathit{at}(x_{1}) = \{R(x_{1}),S(x_{1},y_{1})\}\not\subseteq \mathit{at}(y_{1}) = \{S(x_{1},y_{1})\}\)), and similarly x 2y 2. Hence, there is no inversion in the graph, and the query is inversion free. The proposition gives us an alternative way to see that, by writing the query as q 1=∃x 1.R(x 1),∃y 1.S(x 1,y 1)∨∃x 2.T(x 2),∃y 2.S(x 2,y 2): in both S-atoms the existential variables x i ,y i are introduced in the same order, for i=1,2.

On the other hand, consider the query h 1=R(x 1),S(x 1,y 1)∨S(x 2,y 2),T(y 2). Here x 1y 1 and x 2y 2, hence the edge ((x 1,y 1),(x 2,y 2)) forms an inversion in the unification graph. One can see that we cannot write h 1 in a way that satisfies Definition 7: if we write it hierarchically as ∃x 1.R(x 1),∃y 1.S(x 1,y 1)∨∃y 2.T(y 2).∃x 2.S(x 2,y 2), then the variables in S(x 2,y 2) are introduced in a different order from those of S(x 1,y 1).

We end with a simple remark. If d is a disjunctive query that is inversion free, then it has a separator. Indeed, write d=⋁ i c i , and write each component as a hierarchical expression, c i =∃x i .Q i . Re-write d as ∃w.(⋁ i Q i [w/x i ]). Then w is a separator variable: it obviously occurs in all atoms, and in every atom with relation symbol R, it must occur in position π R (1).

3 Queries with Read-Once Lineage

A Boolean expression Φ is read once (RO) if it can be written using the connectors ∨,∧,¬ such that every Boolean variable occurs at most once. We consider only positive Boolean expressions in this paper, and therefore will use only ∨ and ∧. The probability of a read-once Boolean expression can be computed in linear time, because of independence: P(Φ 1Φ 2)=P(Φ 1)⋅P(Φ 2) and P(Φ 1Φ 2)=1−(1−P(Φ 1))(1−P(Φ 2)); this justifies our interest in this class of expressions. In this section we characterize the queries that have read-once lineages. An elegant characterization of read-once Boolean expressions was given by Gurvich [19] (see [16]), but we will not use that characterization. Note that our characterization is of queries, while Gurvich’s characterization is of Boolean expressions.

Definition 8

UCQ(RO) is the class of queries Q s.t. for every database instance D, the lineage of Q on D is a read once Boolean expression.

Recall that CQ denotes the set of conjunctive queries without self-joins. Dalvi and Suciu [9, 10] showed that CQ (P) is precisely the class of hierarchical queries. Olteanu and Huang [20] showed that all hierarchical queries in CQ have read-once lineages, implying CQ (RO)=CQ (P)= “hierarchical queries”. In this section we characterize the class UCQ(RO).

Definition 9

Let Q be a query expression given by the grammar equation (1). We say that Q is hierarchical-read-once if it is hierarchical (see Definition 5), and every relational symbol occurs at most once. A query is hierarchical-read-once if it is equivalent to a hierarchical-read-once expression.

Obviously, every hierarchical CQ query is also hierarchical-read-once; our definition is more interesting when applied to UCQ. The following is a necessary condition for hierarchical-read-once-ness:

Proposition 3

If Q is a hierarchical read-once expression then it is also an inversion-free expression.

The proof is immediate, since no two distinct atoms in Q may refer to the same relational symbol, hence the condition \(\pi_{g_{1}} =\pi_{g_{2}}\) is satisfied vacuously.

For a simple example, consider query q 1 in Table 1. It is equivalent to the expression ∃x.(R(x)∨T(x))∧∃y.S(x,y), which is both hierarchical and read-once. Notice that in the definition we require Q to be at the same time hierarchical and read-once. Sometimes we can achieve these two goals separately, but not simultaneously: for example h 1=R(x 1),S(x 1,y 1)∨S(x 2,y 2),T(y 2) is hierarchical, and can also be written as ∃x.∃y.(R(x)∨T(y))∧S(x,y), which is read-once. Since h 1 has an inversion, by Proposition 3 it cannot be written simultaneously as a hierarchical and read-once expression.

Theorem 3

QUCQ(RO) iff it is hierarchical-read-once.

The “if” direction is a straightforward extension of the technique used in [20] to prove that hierarchical queries in CQ are read-once. For the “only-if”, we construct one database instance D that is “large enough” (depending only on the query), and prove the following: if Q’s lineage on D is read-once, then Q is hierarchical-read-once.

Proof

If: We prove by induction on the structure of a hierarchical-read-once expression Q that its lineage is read-once; this proof extends that of [20]. If Q=Q 1∨/∧Q 2, then Q 1,Q 2 have no relation symbols in common, and their lineage given by (3) is also read-once. If Q=∃x.Q 1 then x must be a root variable, which implies that the lineages of Q 1[a 1/x], …, Q 1[a n /x] do not share any Boolean variables; hence, the lineage given by (2) is also read-once.

Only if: Assume QUCQ(RO); thus \(\varPhi _{Q}^{D}\) is read-once, for every database instance D; we show that Q must be equivalent to a hierarchical-read-once expression. First, we use Theorem 4 to argue that, if QUCQ(RO) then QUCQ(OBDD), hence Q is inversion-free. Referring to Definition 7, for every relation symbol R we denote π R the permutation mapping the variable nesting order to the order in which they occur in an atom with relation symbol R.

We will construct a special database instance D: from the read-once-ness of \(\varPhi ^{D}_{Q}\), we will extract a hierarchical-read-once expression for Q. Let k be the total number of variables plus the total number of atoms in Q. We first construct the active domain for D. Start by choosing k constants a 1,a 2,…,a k called “root constants”: these will be used to populate the attribute π R (1) of the relation R, for each relation symbol R. Next, choose k 2 constants a ij ,1≤i,jk: these will populate the attribute π R (2) of each relation R, such that a ij occurs only in those tuples that also contain a i . Next, choose k 3 constants for the next level of the hierarchy, etc. This way we construct k a tuples for a relation of arity a: note that the functional dependencies π R (i+1)→π R (i) hold for every relation R and every i=1,…,arity(R)−1.

Thus, we have fixed the database D. Next, we prove the following statement by induction: Let Q be any inversion-free query where the total number of variables plus atoms is at most k, and consider its lineage over our fixed database D, \(\varPhi ^{D}_{Q}\): if the lineage is read-once, then Q can be written as a hierarchical-read-once expression. Our induction proceeds on the structure of the read-once expression \(\varPhi ^{D}_{Q}\), abbreviated Φ Q .

Case 1: Suppose Φ Q =ϕ 1ϕ 2. Then ϕ 1,ϕ 2 have no common Boolean variables. We prove something stronger: that the variables come from disjoint sets of relations. Assume contrary, that both have a Boolean variable over the relational symbol R. To simplify the discussion we will assume R is unary; our argument extends in general too. Note that if m 1 is a minterm of ϕ 1 and m 2 is a minterm of ϕ 2, then m 1 m 2 must be a minterm of Φ Q . This is because ϕ 1,ϕ 2 have no tuples in common, hence if another minterm \(m'_{1}m'_{2} \Rightarrow m_{1}m_{2}\), then \(m'_{1} \Rightarrow m_{1}\) and hence m 1 couldn’t have been a minterm of ϕ 1. Now, suppose \(X_{R(a_{1})}\) occurs in ϕ 1 and not in ϕ 2, and \(X_{R(a_{2})}\) occurs in ϕ 2 and not in ϕ 1. Then \(X_{R(a_{1})}X_{R(a_{2})}\) occurs in some minterm in Φ Q . Since the lineage is invariant under permutations of the active domain, for all 1≤i<jk the term \(X_{R(a_{i})}X_{R(a_{j})}\) occurs in some minterm of Φ Q . Consider a third tuple of R, say R(a 3). It must occur in either ϕ 1 or ϕ 2: assume w.l.o.g. it occurs in ϕ 2, and since Φ Q has a minterm that contains \(X_{R(a_{2})}X_{R(a_{3})}\), ϕ 2 must have a minterm that contains it. Hence, after conjoining with ϕ 1, we obtain a minterm in Φ Q that contains \(X_{R(a_{1})}X_{R(a_{2})}X_{R(a_{3})}\), and, therefore, for every 1≤i<j<lk there exists a minterm in Φ Q containing \(X_{R(a_{i})}X_{R(a_{j})}X_{R(a_{l})}\). Repeating this argument leads us to conclude that Φ Q has a minterm containing \(X_{R(a_{1})}\ldots X_{R(a_{k})}\): this is a contradiction because the minterms of Φ Q cannot have more variables than the number of atoms in Q.

Thus, ϕ 1 contains only tuples over the relations R 1,R 2,… and ϕ 2 contains only tuples over the relations S 1,S 2,… Denote Q 1=Q[S 1=S 2=⋯=true] the query obtained from Q by replacing all atoms referring to S i with true; similarly denote Q 2=Q[R 1=R 2=⋯=true]. The lineage of Q 1 on D is ϕ 1: hence, by induction hypothesis, Q 1 is equivalent to a hierarchical-read-once expression. Similarly Q 2. We prove now that QQ 1Q 2. Since every atom logically implies true, we obtain immediately QQ 1 and QQ 2, hence QQ 1Q 2. For the converse, write Q 1Q 2 as a union of conjunctive queries ⋁ i q i , and let \(D_{q_{i}}\) be the canonical database for q i : it suffices to prove that Q is true on \(D_{q_{i}}\) for every q i . Both Q 1 and Q 2 are inversion-free, hence q i is inversion free and the order π R must be same in q i and Q. Therefore the canonical database \(D_{q_{i}}\) satisfies all functional dependencies that hold in D and we can find an isomorphic copy of \(D_{q_{i}}\) in D, since we have chosen D “large enough”. Set all Boolean variables corresponding to this copy to true and all others to false: we have ϕ 1ϕ 2=true (because Q 1Q 2 is true on \(D_{q_{i}}\)), which implies Φ Q =true, implying that Q is true on \(D_{q_{i}}\).

Case 2: Φ Q =ϕ 1ϕ 2. We distinguish two cases:

Case 2.1: Every minterm in Φ Q consists of tuples that have the same root constant. Thus, it may contain variables like \(X_{R(a_{1},a_{13})}X_{R(a_{1},a_{15})}X_{S(a_{1})}\) (same root constant a 1) but not \(X_{R(a_{1},a_{13})}X_{S(a_{2})}\) (distinct root constants a 1,a 2). Then we claim Q must be a disjunctive sentence. Indeed, consider the DNF expression for Q=q 1q 2∨⋯ and assume w.l.o.g. that q 1 is not connected, hence q 1=cc′ where c, c′ are two components. Then the lineage of q 1 includes minterms with mixed root constants, contradiction. Hence, Q is a disjunctive sentence. Now we use the fact that Q is inversion-free; in particular it has a separator, Q=∃x.Q 1, and its lineage is \(\varPhi _{Q} =\bigvee_{i=1,k} \varPhi _{Q_{1}[a_{i}/x]}\). Since Φ Q is read-once, so is each \(\varPhi _{Q_{1}[a_{i}/x]}\) (since the latter is obtained from Φ Q by setting to false all tuples with root constant a j , for ji). Hence, we apply induction hypothesis to Q 1[a i /x] and obtain a hierarchical-read-once expression: this proves that ∃x.Q 1 is hierarchical-read-once.

Case 2.2: Φ Q =ϕ 1ϕ 2 and there is at least one mixed minterm, containing tuples with two distinct root constants, say \(X_{R_{1}(a_{1},\bar{b})}X_{R_{2}(a_{2},\bar{c})}\), and assume w.l.o.g. that this minterm appears in ϕ 1. We will show that all R 2-tuples occur in ϕ 1, i.e. ϕ 2 does not have R 2 tuples. We consider the case when R 1 and R 2 are distinct relational symbols: the case when they are the same symbol is similar. We use again the fact that Q is invariant under permutations of D to argue that Φ Q must contain minterms that contain the tuples \(X_{R_{1}(a_{1},\bar{b})}X_{R_{2}(a_{j},\bar{c}')}\), for any jk. All these minterms must be in ϕ 1, since ϕ 2 may not contain \(X_{R_{1}(a_{1},\bar{b})}\). Thus, ϕ 1 must contain all tuples over R 2. With a similar argument, it must also contain all tuples over R 1.

Denote R 1,R 2,… the relation symbols that occur only in ϕ 1 and S 1,S 2,… the other symbols. By our assumption, at least one symbol is in the first list (because there is a mixed minterm in ϕ 1) and at least one symbol is in the second list (because ϕ 2 is not empty). We prove that no minterm contains tuples with relation symbols from both lists. Indeed, if the minterm is mixed, then we have seen that its symbols appear either only in ϕ 1 (hence they are all R i symbols), or only in ϕ 2 (hence they are all S j symbols). Suppose the minterm contains a unique root constant, say a 1, i.e. the minterm contains \(X_{R_{i}(a_{1}, \ldots)}X_{S_{j}(a_{1},\ldots)}\). Since the minterms are closed under isomorphisms of the domain, there are minterms containing \(X_{R_{i}(a_{2}, \ldots)}X_{S_{j}(a_{2},\ldots)}\), \(X_{R_{i}(a_{3},\ldots)}X_{S_{j}(a_{3},\ldots)}\), etc. All these must belong to ϕ 1 (because they contain R i ); hence ϕ 1 contains all tuples over S j , and therefore S j must also be in the list R 1,R 2,…

Define Q 1=Q[R 1=R 2=⋯=false] i.e. formula obtained from Q by setting all relation symbols R i to false. Similarly, define Q 2=Q[S 1=S 2=⋯=false]. We show that Q=Q 1Q 2, and since by induction hypothesis Q 1,Q 2 have a hierarchical-read-once expression, so does Q. First note that Q i Q, i=1,2, since false implies anything, hence Q 1Q 2Q. We will now show QQ 1Q 2, and here we use an argument similar to the above. Let Q=⋁q i and let \(D_{q_{i}}\) be a canonical database for q i . Since D was chosen large enough, there exists an isomorphic copy of \(D_{q_{i}}\) in D, and, consequently, a minterm in Φ Q consisting of the conjunction of its tuples. This minterm either consists of R i tuples, hence \(D_{q_{i}} \models Q_{2}\), or of S j tuples, hence \(D_{q_{i}} \models Q_{1}\). □

It is decidable if a given query Q is hierarchical-read-once, because for a fixed vocabulary there are only finitely many hierarchical-read-once expressions: simply iterate over all of them and check equivalence to Q. This implies that it is decidable whether QUCQ(RO). For example, one can check that q 2 in Table 1 is not in UCQ(RO), by enumerating all hierarchical-read-once expressions over the vocabulary R, S, T; we will return to q 2 in the next section.

4 Queries and OBDD

OBDD were introduced by Bryant [3] and studied extensively in the context of model checking and knowledge representation. A good survey can be found in [27]; we give here a quick overview. A BDD, is a rooted DAG with two kinds of nodes. A sink node or output node is a node without any outgoing edges, which is labeled either 0 or 1. An inner node, decision node, or branching node is labeled with a Boolean variable X and has two outgoing edges, labeled 0 and 1 respectively. Every node u uniquely defines a Boolean expression Φ u as follows: Φ u =false and Φ u =true for a sink node labeled 0 or 1 respectively, and \(\varPhi _{u} = \neg X \wedge \varPhi _{u_{0}} \vee X \wedge \varPhi _{u_{1}}\) for an inner node labeled with X and with successors u 0,u 1 respectively. The BDD represents a Boolean expression Φ: ΦΦ u where u is the root of the BDD. A Free BDD, or FBDD is one in which every path from the root to a sink node contains any variable X at most once. Given an FBDD that represents Φ, one can compute the probability P(Φ) in time linear in the size of the FBDD: this justifies our interest in FBDD.

While it is trivial to construct a large FBDD for Φ (e.g. as a tree of size 2n that checks exhaustively all n variables X 1,…,X n ), it is not trivial at all to construct a compact FBDD. To simplify the construction problem, Bryant [4] introduced the notion of Ordered BDD, OBDD, which is an FBDD such that there exists a total order Π on the set of variables s.t. on each path from the root to a sink, the variables X 1,…,X n are tested in the order Π (variables may be skipped). One also writes Π-OBDD, to emphasize that the OBDD has order Π. Therefore, the OBDD construction problem has been reduced to the problem of finding a variable order Π.

One can construct an OBDD for any read-once formula Φ in time linear in Φ, by an inductive argument: if Φ=Φ 1Φ 2 first construct OBDDs for Φ 1 and Φ 2, and replace every sink-node labeled 1 in Φ 1 with (an edge to) the root of Φ 2; for Φ 1Φ 2, replace every sink-node labeled 0 in Φ 1 with the root of Φ 2.

Definition 10

UCQ(OBDD) is the class of queries Q s.t. for every database D, one can construct an OBDD for \(\varPhi _{Q}^{D}\) in time polynomial in |D|.

We show an example in Fig. 2. In this section we prove the following:

Fig. 2
figure 2

OBDD for the query R(x),S(x,y) (cf. [20])

Theorem 4

QUCQ(OBDD) iff it is inversion-free.

We have seen that q 2 from Table 1 is not read-once. However, q 2UCQ(OBDD), because it is inversion-free, therefore we obtain the following separation:

Proposition 4

q 2UCQ(OBDD)−UCQ(RO).

The significance of this result is the following. Olteanu and Huang [20] showed that for any hierarchical query Q, one can construct an OBDD for \(\varPhi _{Q}^{D}\) in time O(|D|), proving that CQ (RO)=CQ (OBDD). Our proposition shows that these classes no longer collapse over UCQ.

We also note that all inversion-free queries are hierarchical (Sect. 2), therefore any non-hierarchical query is not in UCQ(OBDD).

In the remainder of the section we prove Theorem 4, in two stages: first showing that one can construct in PTIME an OBDD for inversion-free formulae, and every query with inversion has exponential size OBDD over some database.

4.1 Tractable Queries

Given an OBDD of Φ over variables \(\bar{x}=\{ x_{1},x_{2}, \ldots, x_{n} \}\) with variable order Π, the width at level k, kn is the number of distinct subformulae that result after checking first k variables in the order Π, i.e. \(|\{{\varPhi _{x_{\pi(1)}\ldots x_{\pi(k)} = \bar{b}}}\mid {\bar{b} \in \{ 0,1\}^{k}}\}|\). The width of an OBDD is the maximum width at any level. If the width is w, then a trivial upper bound on the size of the OBDD is nw. In what follows, we give a variable ordering for inversion-free queries under which the width is always constant (exponential in query size) and hence the size of the OBDD is linear. Note that if the size of OBDD is polynomial, then the construction of the OBDD can be done in PTIME in our setting, since the lineage of a UCQ is always a monotone formula and checking the equivalence of monotone formulas is in PTIME.

We first need to define the notion of a shared BDD. A shared BDD for a set of formulas Φ 1,Φ 2,…,Φ m is a BDD where the sink nodes are labeled with {0,1}m i.e. they give the valuation for each of the Φ i , 1≤im. This means a node reached by following the assignments \(\bar{x}\) from the root can be thought of as representing a set of subformulae \(\varPhi _{1\bar{x}},\varPhi _{2\bar{x}},\ldots,\varPhi _{k\bar{x}}\). Shared BDD evaluate a set of formulae simultaneously: this enables us to compute any combination function of the formulae. So, for instance, one can derive the OBDD of Φ 1Φ 2 for any Boolean operation ⊗ from the shared OBDD for Φ 1,Φ 2.

The following is a well-known lemma for OBDD synthesis.

Lemma 2

(cf. [27])

Let Φ 1,Φ 2 be two Boolean functions and consider a fixed variable order Π. If there exist Π-OBDD of width w 1, w 2 for Φ 1, Φ 2 respectively, then there exists a shared Π-OBDD of width w 1 w 2 for Φ 1,Φ 2.

Proposition 5

If Q is inversion-free, then for every database D its lineage has an OBDD with width w=2g, where g is the number of atoms in the query. Therefore, the size of the OBDD is linear in the size of the database.

We give a simple proof, using Lemma 2, that constructs the OBDD inductively on the hierarchical expression for Q: the resulting OBDD has size O(|D|).

Proof

Consider a hierarchical expression for Q, and let π R be the permutation associated to the symbol R (Definition 7). Let D be a database, and assume that its active domain ADom(D) is an ordered domain. We start by defining a linear order Π on all tuples in D. Fix any linear order on the relational symbols, R 1<R 2<⋯. We add all relation symbols to ADom(D), placing them at the beginning of the order. We associate to each tuple in D a string in (ADom(D)), as follows: tuple \(R(a_{\pi_{R}(1)}, a_{\pi_{R}(2)}, \ldots,a_{\pi_{R}(k)})\) is associated to the string a 1 a 2a k R. That is, the first element is the constant on the root attribute position; the second element is the constant on the attribute position corresponding to a quantifier depth 2, etc. We add the relation name at the end. Next, we order the Boolean variables in the lineage expression \(\varPhi _{Q}^{D}\) lexicographically by their string, and denote Π the resulting order. We prove that Π-OBDD has width w=2g, inductively on the structure of the inversion-free expression Q. If Q=Q 1∨/∧Q 2 then we use Lemma 2. If Q=∃x.Q 1, then Φ Q =⋁ aADom(D) Φ Q[a/x]. Let the active domain consist of a 1<a 2<⋯<a n , in this order. The OBDDs for \(\varPhi _{Q[a_{1}/x]},\ldots, \varPhi _{Q[a_{n}/x]}\) are over disjoint sets of Boolean variables (because x is a root variable); assume that their width is w. The OBDD for Φ Q consists of their union, where we redirect the 0 sink nodes of \(\varPhi _{Q[a_{i}/x]}\) to the root node of \(\varPhi _{Q[a_{i+1}/x]}\): the width is still w. The OBDD of a single ground atom, say \(R(\bar{a})\), has width only 2. This completes the proof. □

Corollary 1

If a set of components c 1,c 2,…,c m is inversion-free, then for every database D, they have a shared-OBDD with size linear in the size of the database.

4.2 Hard Queries

For k≥1, define the following queries (see also Fig. 1):

Denote h k =⋁ i=0,k h ki . The queries h k were shown in [8, 11] to be hard for #P and are used to prove the hardness of a much larger class of unsafe queries. We show here that they have a remarkable property w.r.t. OBDD: if the same variable order Π is used to compute all queries h k0, h k1, …, h kk , then at least one of these k+1 OBDDs has exponential size. Note that each query is inversion-free, hence it admits an efficient OBDD, e.g. Fig. 2 illustrates h k0: what we prove is that there is no common order under which all have an efficient OBDD. This tool is quite powerful, allowing us to give a rather simple proof that queries with inversion have exponential size OBDD (Proposition 7). There is no analogous tool for proving #P-hardness: all queries h ki are in PTIME, for i=0,k, and this tells us nothing about the larger query where they occur.

The complete bipartite graph of size n is the following database D over the vocabulary of h k : relation R has n tuples R(a 1),…,R(a n ), relation T has n tuples T(b 1),…,T(b n ), and each relation S i has n 2 tuples S i (a j ,b l ), for i=1,k, and j,l=1,n.

Proposition 6

Let D be the complete bipartite graph of size n, and fix any ordering Π on the corresponding Boolean variables. For any i=0,k, let n i be the size of some Π-OBDD for the lineage of h ki on D. Then \(\sum_{i=0}^{k} n_{i} > k \cdot 2^{\frac{n}{2k}}\).

Proof

Denote the Boolean variables associated to the tuples R(a i ), i=1,n with X 1,X 2,…; those associated to the tuples S p (a i ,b j ) with \(Z^{p}_{ij}\); and those associated to the tuples T(b j ) with Y j . We will refer generically to any variable as v i , and assume the order Π is v 1,v 2,… Denote Φ kp the lineage of h kp on D; by assumption, we have Π-OBDD for each of them. Assume w.l.o.g. that each OBDD is complete i.e. every path from root to sink contains every variable exactly once.

In any OBDD of a Boolean expression Φ, the number of nodes at level h (i.e. after first h variables v 1v h have been eliminated) is the size of the set \(\{{ \varPhi [(v_{1}\ldots v_{h}) =\bar{b}]}\mid {\bar{b} \in \{0,1\}^{h} }\}\). This is because every distinct subformula will result in a new separate node. A standard technique in proving lower bounds on the size of OBDD is to find a level where the number of distinct formulae must be exponential. This immediately gives the same exponential lower bound on the size of OBDD for that ordering.

For any level h, denote h 1, h 2 the number of X, and of Y variables respectively in the initial sequence v 1,v 2,…,v h of Π. Define h to be the first level for which h 1+h 2=n. Denote X set={X i X i ∈{v 1,…,v h }} and X unset=XX set, and similarly Y set, Y unset, Z set, Z unset. W.l.o.g. assume h 1n/2.

Consider the OBDD for \(\varPhi _{k0} = \bigvee_{ij} X_{i}Z^{1}_{ij}\). Suppose there exists j s.t. \(\forall i. ( X_{i} \in \mathbf{X}^{set} \Rightarrow Z^{1}_{ij} \in \mathbf{Z}^{unset} ) \); then for each assignment \(\bar{b}\) to X set, we get a different subformula \(\varPhi _{k0}[\mathbf{X}^{set} = \bar{b}]\). Since the number of such formulae is \(2^{h_{1}}\geq 2^{n/2}\), we obtain n 0>2n/2, which proves the claim. Hence we can assume there is no such j. This means ∀j, ∃i s.t. X i X set and \(Z^{1}_{ij} \in \mathbf{Z}^{set}\).

Define S to be a set of pairs (i,j) as follows. For each j s.t. Y j Y unset, choose some i s.t. \(Z^{1}_{ij} \in \mathbf{Z}^{set}\): then include (i,j) in S. Note that the cardinality of S is nh 2=h 1.

For each p=1,…,k−1, denote C p the subset of S consisting of indices (i,j) s.t. \(Z_{ij}^{1}, \ldots, Z_{ij}^{p} \in \mathbf{Z}^{set}\) and \(Z_{ij}^{p+1} \in \mathbf{Z}^{unset}\); and let C k =S−⋃ p=1,k−1 C p . Thus, C 1,…,C k forms a partition of S. Denoting c 1,…,c k their cardinalities we have c 1+⋯+c k =h 1.

Next, for each p=1,…,k−1, consider the OBDD for \(\varPhi _{kp}= \bigvee_{ij} Z^{p}_{ij} Z^{p+1}_{ij}\). Forall (i,j)∈C p we have \(Z^{p}_{ij} \in \mathbf{Z}^{set}\) and \(Z^{p+1}_{ij} \in \mathbf{Z}^{unset}\). Each assignment of the former variables leads to a different expression over the latter variables: hence there are at least \(2^{c_{p}}\) distinct expressions, therefore the number of nodes in this OBDD is \(n_{p} \geq 2^{c_{p}}\).

Finally, consider the OBDD for \(\varPhi _{kk} = \bigvee_{ij}Z^{k}_{ij}Y_{j}\). Forall (i,j)∈C k we have \(Z^{k}_{ij} \in \mathbf{Z}^{set}\) and Y j Y unset. Using the same argument, we obtain \(n_{k}\geq 2^{c_{k}}\).

Putting everything together we obtain:

Notice that n 0 does not appear above, but we used it in order to construct the set S. This proves our claim. □

Proposition 7

Let Q be a query, and suppose it has an inversion of length k>0. Let D 0 be a complete bipartite graph of size n (i.e. a database over the vocabulary of h k ). Then there exists a database D for Q s.t. |D|=O(|D 0|) and any OBDD for Q has size Ω(k2n/2k).

We use the inversion of length k to construct a database D that mimics the query h k over a complete bipartite graph. Assuming an OBDD for Q on this database, we show that one can set the Boolean variables to 0 or 1, to obtain a lineage for each h ki . What is interesting is that this construction cannot be used to prove #P-hardness of Q by reduction from h k : in other words, Q over D is not equivalent to h k over D 0. But we make Q equivalent to each h ki , and by Proposition 6 this is sufficient to prove that Q has a no compact OBDD.

Proof

Write Q=⋁q j in DNF, and let (x 0,y 0),(x 1,y 1),…,(x k ,y k ) be an inversion in Q. Assume w.l.o.g. that the inversion is of minimal length: this implies there exist atoms \(r, s_{1}, s_{1}', \ldots, s_{k},s_{k}', t\) with the following properties: rat(x 0)−at(y 0), tat(y k )−at(x k ), and for every i=1,k, s i contains x i−1,y i−1, \(s_{i}'\) contains x i ,y i , they unify, and the unification equates x i−1=x i and y i−1=y i . In particular, the atoms s i and \(s_{i}'\) have the same relation symbol. Assume that x i ,y i are variables in the query \(q_{j_{i}}\), for i=0,k. We assume that these k queries are distinct: if not, simply create a fresh copy of the query, creating new copies of its variables. Thus, \(q_{j_{0}}\) contains the atoms r,s 1, query \(q_{j_{1}}\) contains the atoms \(s_{1}',s_{2}\) and so on. Next, we perform variable substitutions in the queries \(q_{j_{0}}, \ldots, q_{j_{k}}\) in order to equate all variables in s i and \(s_{i}'\), except for x i−1,y i−1,x i ,y i . In other words, all atoms along the inversion path have the same variables, except for the variables forming the actual inversion. For example, if the queries were R(x 0,u 0),S 1(x 0,y 0,u 0); S 1(x 1,y 1,u 1),S 2(x 1,y 1,u 1,v 1); S 2(x 2,y 2,u 2,v 2),… then we equate u 0=u 1=u 2=⋯ and v 1=v 2=⋯ This is possible in general because Q is ranked: we only equate variables between \(q_{j_{i}}\) and \(q_{j_{l}}\), but not within the same \(q_{j_{i}}\). We now construct the database D as follows. Its active domain consists of all constants a 1,…,a n ,b 1, …,b n and all variables \(z\in \mathit{Vars}(q_{j_{i}})\) s.t. zx i , zy i , for i=0,k. For each i=0,k, and each j=1,n, l=1,n, let \(q_{j_{i}}[a_{j},b_{l}]\) denote the set of tuples obtained by substituting x i with a j and y i with b l . Define D to be the union of all these sets: \(D = \bigcup_{i,j,l} q_{j_{i}}[a_{j}, b_{l}]\). Because of our earlier variable substitutions, s i [a j ,b l ] and \(s_{i}'[a_{j},b_{l}]\) are the same tuple: this tuple corresponds to the tuple S i (a j ,b l ) in the bipartite graph. Similarly, r(a j ) and t(b l ) correspond to the tuples R(a j ) and T(b l ) in the bipartite graph. Thus, the bipartite graph D 0 is isomorphic to a subset of the database D. Consider now any OBDD for \(\varPhi _{Q}^{D}\), over a fixed variable ordering Π. We can obtain an OBDD for h ki for every i=0,k as follows. Assume 0<i<k. Then we keep unchanged the Boolean variables corresponding to S i (a j ,b l ) and S i+1(a j ,b l ), (that is, the atoms \(s_{i}'[a_{j},b_{l}]\) and s i+1[a j ,b l ]). All other Boolean variables corresponding to tuples in \(q_{j_{i}}[a_{j},b_{l}]\) are set to true; all remaining Boolean variables are set to false. Then the lineage \(\varPhi _{Q}^{D}\) becomes the lineage \(\varPhi ^{D_{0}}_{h_{ki}}\). The case i=0 is similar (here we keep unchanged the Boolean variables corresponding to R(a j ) and S 1(a j ,b l )), and so is the case i=k. Thus, we obtain k+1 OBDD’s for all queries h ki , and all use the same variable order Π. The claim follows now from Proposition 6. □

If Q has an inversion of length 0, then it is non-hierarchical and as we discuss later in Theorem 7 QUCQ(FBDD), and hence QUCQ(OBDD) either.

5 Queries and FBDD

We now turn to FBDD, also known as read-once Branching Programs. Unlike OBDD, here we no longer require the same variable order on different paths. FBDD are known to be strictly more expressive than OBDD over arbitrary (non-monotone) Boolean expressions, for example the Weighted Bit Addressing problem admits polynomial sized FBDD, but no polynomial size OBDD [5, 15, 24]. On the other hand, to the best of our knowledge no monotone formula was known to separate these two classes. Moreover, over conjunctive queries without self-joins, FBDD are no more expressive than OBDD, since the latter already capture CQ (P). In this section we show that FBDD are strictly more expressive than OBDD over UCQ. In particular, we give a simple (!) monotone Boolean expression for which one can construct a FBDD in PTIME, but no polynomial size OBDD exists.

Definition 11

UCQ(FBDD) is the class of queries Q s.t. for any database D, one can construct an FBDD of \(\varPhi _{Q}^{D}\) in time polynomial in |D|.

Clearly UCQ(OBDD)⊆UCQ(FBDD): we prove now that the inclusion is strict, using a simple example.

Example 2

Consider q V in Table 1. This query has an inversion between S(x 1,y 1) and S(x 2,y 2), hence it does not admit a compact OBDD. We show how to construct a compact FBDD. Write it in CNF:

Its CNF lattice is shown in Fig. 1. The minimal element of the lattice is:

Each of d 1,d 2,d 3 is inversion-free, hence they have OBDDs, denote them F 1, F 2, F 3. Of course, F 1 and F 2 use different variable orderings and cannot be combined into an OBDD for q V . Consider the database given by the bipartite graph (Sect. 4) and assume the following order on the active domain: a 1<⋯<a n <b 1<⋯<b n . Our FBDD starts by computing d 3. If d 3=0, then q V =0; this is a sink node. If d 3=1, then, depending on which sink node in F 3 we have reached, either d 1=1 or d 2=1, and we need to continue with either F 2 or F 1 respectively. This way, no path goes through both F 1 and F 2. Note that the FBDD is not ordered, since some paths use the order in F 1, others that in F 2. Figure 3 illustrates the construction. The FBDD inspects the variables in this order: \(X_{R(a_{1})}, X_{R(a_{2})}, \ldots, X_{R(a_{n})},X_{T(b_{1})}, \ldots, X_{T(b_{n})}\). (This is F 3.) Each edge \(X_{R(a_{i})} = 0\) leads to the next node, \(X_{R(a_{i+1})}\), etc. Consider now an edge \(X_{R(a_{i})} = 1\). Here we know d 2 is true, but we still need to evaluate d 1. We create a new copy of F 1 where we set all variables \(X_{R(a_{1})}, \ldots, X_{R(a_{i-1})}\) to 0 (i.e. eliminate these nodes and redirect their incoming edge to their 0-child) and set \(X_{R(a_{i})}\) to 1. Then we connect the edge \(X_{R(a_{i})} = 1\) to the root node of this copy of F 1. Similarly, we connect an edge \(X_{T(b_{j})}=1\) to the root of a copy of F 2 where we set \(X_{R(a_{1})} = \cdots = X_{R(a_{n})} = X_{T(b_{1})} = \cdots = X_{T(b_{j-1})} = 0\) and \(X_{T(b_{j})} = 1\). The result is an FBDD of sizeFootnote 3 O(n 3) (since F 1,F 2 have sizes O(n 2)).

Fig. 3
figure 3

FBDD for the query q V

Thus:

Proposition 8

q V UCQ(FBDD)−UCQ(OBDD).

The significance of this result is the following. The lineage of q V is, to the best of our knowledge, the first “simple” Boolean expression (i.e. monotone, and with polynomial size DNF) that has a polynomial size FBDD but no polynomial size OBDD. Previous examples separating these classes where Weighted Bit Addressing problem (WBA) [5, 15, 24], and other examples given in [26], and these were not “simple”. Our result also constrasts UCQ to CQ : for the latter it follows from [20] that CQ (OBDD)=CQ (FBDD).

In the reminder of this section we will give a partial characterization of UCQ(FBDD), by providing a sufficient condition, and a necessary condition for membership. We start with the sufficient condition.

Definition 12

Let d=⋁c i and \(d' = \bigvee c_{j}'\) be two disjunctive queries, s.t. the logical implication d′⇒d holds. We say that d dominates d′ if for every component \(c_{j}'\) in d′ and for every atom g in \(c_{j}'\) one of the following conditions hold: (a) the relation symbol of g does not occur in d, or (b) there exists a component c i and a homomorphism \(c_{i} \rightarrow c_{j}'\) whose image contains g.

In Example 2, d 3 dominates d 1: if one considers the component R(x 1),S(x 1,y 1) in d 1, then the atom R(x 1) is the image of a homomorphism, while the atom S(x 1,y 1) does not occur at all in d 3. Similarly d 3 dominates d 2.

In analogy to the definition of safe queries Definition 4 we define here rf-safe queries Footnote 4:

Definition 13

(1) Let Q=d 1∧⋯∧d k , and k≥2. Then Q is rf-safe if for every element x in its CNF lattice the disjunctive query λ(x) is rf-safe, and for every two lattice elements xy, λ(x) dominates λ(y). (2) Let d=d 0d 1, be a disjunctive query, where d 0 contains all components c i without variables, and d 1 contains all components c i with at least one variable. Then d is rf-safe if d 1 has a separator w and d 1[a/w] is rf-safe, for a constant a.

For example, query q V is rf-safe, since d 3 dominates both d 1 and d 2. Our sufficient characterization of UCQ(FBDD) is:

Theorem 5

Every rf-safe query is in UCQ(FBDD).

Proof of Theorem 5

We start with a definition. Consider a monotone, Boolean expression, written as a disjunction of minterms: Φ=⋁ i=1,n T i . We also view Φ as a set of minterms, writing T i Φ. Each minterm T i is a set of variables: thus, T i T j means that, as sets, T j T i .

Definition 14

Let Φ, Φ′ be two monotone, Boolean expressions, s.t. Φ′⇒Φ. We say that Φ dominates Φ′ if for every minterm T′∈Φ′, and for every Boolean variable XT′, one of the following conditions hold: (a) either X does not occur in Φ, or (b) there exists a minterm TΦ s.t. XT and TT′.

The following is easy to check:

Lemma 3

If the disjunctive query d dominates d′, then for any database D, the lineage \(\varPhi _{d}^{D}\) dominates \(\varPhi _{d'}^{D}\).

Consider an FBDD for Φ, and a node x. Any path from the root to x corresponds to an assignment of a subset of Boolean variables; we call that an assignment at x.

Call an FBDD for Φ greedy if each sink node x labeled 1 has an additional label consisting of (a) a set s⊆[n] and (b) and index i, such that, for any assignment at x, the following properties hold: T i =1 (i.e. all variables in T i are set to 1 by the assignment). (2) For any js, T j =0. (3) For any ks, if the assignment sets a value of a variable in T k , then that variable is in T i (hence it is set to 1).

A greedy FBDD does exactly what the name says: it evaluates the Boolean DNF expression greedily. If a variable X=0 then it skips all minterms that contain X: these minterms now belong to the set s. If a variable X=1, then it continues to read only variables Y that co-occur with X in some minterm.

Let Φ=⋀ i=1,m Φ i , where each Φ i is a monotone, Boolean expression. Let (L,≤) be the CNF-lattice for Φ constructed as follows. Its elements x are in one-to-one correspondence with Boolean expressions Φ s =⋁ is Φ i , where s⊆[m], up to logical equivalence (i.e. if \(\varPhi _{s_{1}} \equiv \varPhi _{s_{2}}\) then they correspond to the same element x); λ(x)=Φ s denotes the Boolean expression associated to x. And xy if λ(y)⇒λ(x).

Lemma 4

Let Φ=⋀ i=1,m Φ i , and (L,≤) be its CNF lattice. Suppose that, for all xy, λ(x) dominates λ(y). Let F x be a greedy FBDD of size n x for λ(x), for each xL. Then there exists a greedy FBDD for Φ, of size O(m⋅(∏n x )).

Proof

(Sketch) We construct the FBDD by generalizing the idea of Example 2. Let \(x_{0} = \hat{0}\) be the smallest element in the lattice. The FBDD starts with \(F_{x_{0}}\). Consider a sink node. If it is labeled 0, then we leave it labeled 0: we know that Φ 1=⋯=Φ m =0, hence so is Φ. If it is labeled 1, then we have two additional labels: a minterm T i (known to be 1), and a set of minterms, TT (all known to be 0). Let s⊆[m] be the set s.t. is iff T i does not imply Φ i : thus, from that sink node we have to continue to evaluate Φ s . We assume, inductively, to have an FBDD for Φ s . Then we modify it, by setting all variables in T i to 1, and setting all other variables occurring in the set of minterms TT to 0: dominance ensures that the new FBDD still computes correctly Φ s . □

The proof of Theorem 5 follows now directly from the last two lemmas. □

rf-safe is not a complete characterization of UCQ(FBDD). The following query q T , is not rf-safe, but one can construct a polynomial-size FBDD for it.

Next, we present our separation result. Recall the query q W from Table 1. We prove here:

Theorem 6

q W UCQ(FBDD).

We will return to this query in the next section.

Proof

Consider the following three queries:

Thus, q W =d 1d 2d 3. We first prove a surprising fact that given an FBDD for q W , we can construct a shared FBDD for d 1,d 2,d 3. Note that in general it is not possible to split an FBDD into a shared FBDD: we exploit the properties of d 1,d 2,d 3 to do this.

Lemma 5

Given any FBDD for q W of size N, there exists a shared FBDD for d 1,d 2,d 3 of size polynomial in N and data instance.

Call a node shared if for any two paths \(\bar{x},\bar{y}\) from root to the node, \(d_{i \bar{x}} = d_{i \bar{y}}\), for i=1, 2, 3. Hence if all nodes were shared, then the FBDD would also be shared. To prove the lemma, we show that if a node is not shared then the subformula represented by that node is actually an inversion-free query, so we could just replace the FBDD below that node with a shared OBDD. Hence, one can make every node shared, and therefore the FBDD shared.

Proof of Lemma 5 (Transformation into a shared FBDD)

Each node x in an FBDD for F represents a Boolean expression F x , obtained by setting some variables in F. If two paths P1,P2, lead to the same x, then F[P1]=F[P2], where F[P1] denotes the formula obtained by applying the partial assignment P1. Let F be the lineage of q W =d 1d 2d 3, and write it as F=G 1G 2G 3, where G i is the lineage of d i . In general, two paths P1,P2 in the FBDD(q W ) that lead to the same node do not have to equate d 1, i.e. we may have G 1[P1]≠G 1[P2].

Definition 15

An FBDD for g W is called shared if for any two paths P1,P2, if F[P1]=F[P2] then for all i=1,2,3, G i [P1]=G i [P2].

This lemma is significant, because it says that we can transform FBDD(q W ) to compute each of the three queries d 1, d 2, d 3 separately. In general, this is not possible for an arbitrary conjunction of Boolean formulas. What makes this work in our case is that, whenever a node x fails to keep track separately of the three subqueries then the formula at x depends only on d 1,d 2 or only on d 2,d 3. Both these queries are inversion-free, hence in both cases we can construct a shared OBDD for the remaining computation of the two queries, replacing the rest of the FBDD(q W )

Call a node x shared if for any two paths P1,P2 leading to x, we have G i [P1]=G i [P2], for i=1,2,3. We will leave shared nodes unchanged. If x is an non-shared node, then we show how to replace it with a shared OBDD for the remaining formulas. (Some of x’s descendants may become unreachable, and they can be removed later.)

Suppose x is a non-shared node. Let P1,P2 be two paths leading to a node x in the FBDD(F). Then F x =F[P1]=F[P2]. Suppose G 1[P1]≠G 1[P2].

Case 1: For every pair of constants a,b, the path P1 sets either S 3(a,b)=0 or T(b)=0. Then G 2[P1] has only terms R(a′),S 1(a′,b′) and similarly G 3[P1] has only terms S 1(a′,b′),S 2(a′,b′). Denote the three queries below:

Let D 1,D 2,D 3 be the set of tuples that are unset in G 1[P1], G 2[P1], and G 3[P1]. Then F x is the conjunction of the lineages of d 1,e 2,e 3 on these three databases. Since d 1,e 2,e 3 are inversion-free, we can compute a shared OBDD that evaluates all three of them in parallel on D 1,D 2,D 3 (Corollary 1): thus, we have separated the FBDD at x and below x.

Case 2: There exists a pair of tuples X=S 3(a,b), Y=T(b) s.t. P1 leaves them either unset, or set to 1. Set X=Y=1. Then G 2, G 3 become true, and therefore G 1[P,X=1,Y=1]=F[P,X=1,Y=1], for P∈{P1,P2}. Since F[P1]=F[P2] we obtain G 1[P1,X=1,Y=1]=G 1[P2,X=1,Y=1]. Hence, the only way in which G 1[P1] and G 1[P2] may differ is that either one has the term S 2(a,b) and the other has S 2(a,b),S 3(a,b), or one is true and the other has the term S 3(a,b). The first case is impossible because it means that one of the two paths has set S 3(a,b) to true. The second case implies F x =G 2[P]∧G 3[P] for P∈{P 1,P 2} and we repeat the argument above.

This completes the case when G 1 differs on two paths. The case when G 3 differs is similar and omitted. So suppose G 1[P1]=G 1[P2] and G 3[P1]=G 3[P2]. Then, we prove that we also have G 2[P1]=G 2[P2]. Indeed, this follows immediately by inspecting the three query lineages: G 1 is ⋁ a,b R(a)S 1(a,b)∨S 2(a,b),S 3(a,b) and G 2 is ⋁ a,b R(a),S 1(a,b)∨S 3(a,b),T(b). Thus, the subformula of R(a),S 1(a,b) in G 1[P1] is the same as that in G 2[P1]; since G 1[P1]=G 1[P2], it means that this part of G 2 is the same in P1 and in P2. Similarly, from G 3[P1]=G 3[P2] we conclude that the part S 3(a,b),T(b) in G 2 is the same in P1 and P2. Hence, G 2[P1]=G 2[P2]. □

Let \(h_{1}' = R(x_{1}),S(x_{1},y_{1}),S(x_{2},y_{2}),T(y_{2})\). We can show that

Lemma 6

\(h_{1}' \notin \mathit{UCQ}(\mathit{FBDD})\).

We start at the root and choose 2n−1 paths (our database is bipartite as in Sect. 4) as follows: for each node we go in both directions if the given node isn’t a prime implicant in the subformula at that node, otherwise we choose only the 0-edge. Then we exploit the fact that each of these paths has only set a limited number of variables to show that any two paths can differ on the assignment of only a few variables, hence most of them must end in distinct subformulas.

Proof of Lemma 6

Define Φ 1 to be \(\bigvee_{i,j=1}^{n} r_{i} s_{i,j}\), Φ 2 as \(\bigvee_{i,j=1}^{n} s_{i,j}t_{j} \) and F n to be Φ 1Φ 2. Then we show FBDD(F n )=n Ω(log(n)). We start at the root and choose 2n−1 paths \(\mathcal{P}\) as follows: for each node we go in both directions if the given node isn’t a prime implicant in either Φ 1 or Φ 2: we call such nodes branching; otherwise we choose only the 0-edge. We ignore redundant (i.e. the two branches for 0, 1 point to the same node) nodes. We stop a path after we have branched on n−1 nodes. We can always find n−1 nodes to branch on since our function cannot become 0 before we branched on n−1 nodes. This is because each branching variable can set at most n 3 minterms to 0. We have n 4 minterms to set to 0 and that can’t be done with n−1 branching nodes. The set of variables on a branch p are denoted by Vars(p) and p(v) denotes the assignment of the variable v in p. The Boolean formula f p =F n [p(x)/x], x=Vars(p) is obtained by applying the assignments on path p to F n .

Definition 16

Given a Boolean formula f, call a variable v determined, if there exists b∈{0,1} s.t. for any \(p \in \mathcal{P}\) f p =f implies vVars(p) and p(v)=b. Conversely any variable xVars(f) that is not determined is called undetermined.

Now the essence of the proof is that two paths that result in the same function can only differ on the undetermined variables. The following lemma characterizes the variables that can be undetermined.

Lemma 7

Given a path p and a variable xVars(f p ); x is undetermined for f p iff x=s i,j for some 1≤i,jn and

  1. 1.

    r i =0 or s i,j1=1 for some 1≤j1≤n on p and

  2. 2.

    t j =0 or s i1,j =1 for some 1≤i1≤n on p.

Proof

Follows immediately by doing a simple case analysis. □

Note that for any f p , the number of paths q s.t. f q =f p is bounded above by \(2^{\# \textrm{undetermined variables in} f_{p}}\). This is because q and p can only differ on the assignment of undetermined variables. We now bound the number of undetermined variables for any path p. Let n r ,n t be the number of r,t variables set to 0 on path p; n s be the number of s variables set to 1. Then by Lemma 7 the number of undetermined variables is at most (n r +n s )(n t +n s ). Let m r ,m t ,m s similarly be the number of branching variables amongst n r ,n t ,n s . Then, m s =n s and n r m r +m s n t m t +m s . The first equality m s =n s holds because non-branching variables are always set to 0. Also a non-branching variable from r,t is set to 0 iff it becomes a prime implicant; which can only happen if one of the variables from s is set to 1 and conversely setting one variable from s makes at most one prime implicant. This proves the second and third inequality.

Hence the number of undetermined variables is at most (m r +2m s )(m t +2m s )≤4(m r +m s +m t )2. Now consider all paths p where \(l=m_{r} +m_{s} + m_{t} = \frac{\log(n)}{8}\). Consider the complete binary tree of depth n−1 on the branching variables. Flip the edges coming out of r,t nodes in the tree, i.e. 0 to 1 and vice-versa. We map any such path p to a path in this tree by choosing opposite assignment to variables from r,t. This is a 1-1 mapping. And the set of such paths in our tree is exactly the set of paths where the number of nodes tested to be 1 are l, which is \({n-1 \choose l}\). Hence the size of the FBDD is at least \(\frac{{n-1 \choose l}}{2^{4l^{2}}}\) which for \(l=\frac{\log(n)}{8}\) gives the required bound. □

Now to finish the proof, we finally show a reduction from a shared FBDD of d 1,d 2,d 3 to \(h'_{1}\).

Lemma 8

Given a shared FBDD for q W of size N, there exists an FBDD for \(h_{1}'\) of size at most N.

This is, perhaps, the most surprising step, because it seems to reduce a query that is hard for #P (\(h_{1}'\)) to a query that is in PTIME (q W ). However, what we describe below is not a reduction: instead is a transformation of an FBDD.

The goal of the reduction is to set S 1(a,b)=¬S 2(a,b)=S 3(a,b) in FBDD(q W ): it can be easily seen (by inspecting the definition of the two queries) that the new FBDD computes \(h_{1}'\). Since we have shown in Lemma 6 that \(h_{1}'\) has no polynomial size FBDD, this completes the proof.

The difficulty of this step is to show that the FBDD has enough memory to remember if any of S 1(a,b), S 2(a,b), or S 3(a,b) was set. We show that it does have enough memory, by using the fact that it is a shared FBDD, i.e. it computes the queries d 1,d 2,d 3 simultaneously.

Proof of Lemma 8

Start with the shared FBDD for q W , given by Lemma 5. We want to enforce

(4)

for every tuple S 1(a,b).

Modify each node x as follows. If it is a test for R(a) or for T(b), then make no change: it will continue to be a test for the same variable. If it is a test for S i (a,b), i=1,3, then we will either replace it with a test for S(a,b), or will “know” the value of S i (a,b) and will follow only the 0 or the 1 branch. We give the details next.

Suppose node x tests for S 1(a,b). Denote G i,x , i=1,2,3 the three Boolean expressions at x: the FBDD is shared, so it can keep track of them separately.

Step 1: Inspect G 3,x . Recall that the original G 3 contained S 1(a,b),S 2(a,b)∨S 3(a,b),T(b). There are a few cases: (a) G 3,x does not contain S 1(a,b) at all: then we know S 2(a,b)=0 on all paths leading to x. (b) G 3,x contains S 1(a,b) (a prime implicant). Then on all paths to x must set S 2(a,b)=1. In both (a) and (b) we know how to set S 1(a,b) according to (4). (c) G 3,x contains S 1(a,b),S 2(a,b): then we know S 2(a,b) is unset, and continue with step 2.

Step 2. At this point we know S 2(a,b) is unset. Inspect G 1. The original G 1 was R(a),S 1(a,b)∨S 2(a,b),S 3(a,b). We know S 2(a,b) is unset, hence the cases are: (a) G 1,x does not contain S 2(a,b): then we know S 3(a,b)=0 on all paths to x. (b) G 1,x contains S 2(a,b) (a prime implicant). Then on all paths to x, S 3(a,b)=1. In cases (a) and (b) we know how to set S 1(a,b) according to the constraint equation (4). (c) G 1,x contains S 2(a,b),S 3(a,b). Then we know S 3(a,b) is also unset, and it means we can read S(a,b).

So far we have assumed that neither G 1,x nor G 3,x are true. Suppose G 3,x is true. Let x be a maximal node where G 3 becomes true, i.e. the same doesn’t hold for any of the children of x. Due to our previous construction when we transformed the FBDD into a shared one, the entire subgraph reachable from x is isolated. First, we consider all variables S 1,S 2,S 3 already set at x, and update the subgraph under x accordingly. We will need to cope with the variables read within this subgraph. Here, we first rewrite the query d 1,d 2=R(x),S 1(x,y)∨S 2(x 1,y 1),S 3(x 1,y 1),S 3(x 2,y 2),T(y 2). Given our constraint equation (4), this query is equivalent to R(x),S 1(x,y). We simply replace the entire subtree at x with an OBDD for R(x),S(x,y). This completes the proof. □

Our hardness result for FBDD is more limited in scope than that for OBDD; in particular it says nothing about non-hierarchical queries. This, however, follows from a very strong result by Bollig & Wegener [1]. They showed that, for arbitrary large n, there exists a bipartite graph G s.t. the formula Φ=⋁(i,j)∈G X i Y j has no polynomial size FBDD.Footnote 5 This immediately implies that the query Q=R(x),S(x,y),T(y) is not in UCQ(FBDD), because from any FBDD for Q on the complete, bipartite graph one can obtain and FBDD for Φ by setting all variables X S(i,j)=1 for (i,j)∈G and setting X S(i,j)=0 for \((i,j) \not \in G\). In particular, this implies:

Theorem 7

(cf. [1])

If Q is non-hierarchical, then QUCQ(FBDD).

6 Queries and d-DNNFs

d-DNNFs were introduced by Darwiche [12]; a good survey is [13], we review them here briefly. A Negation Normal Form is a rooted DAG, internal nodes are labeled with ∨ or ∧, and leaves are labeled with either a Boolean variable X or its negation ¬X. Each node x in an NNF represents a Boolean expression Φ x , and the NNF is said to represent Φ z , where z is the root node. A Decomposable NNF, or DNNF, is one where for every ∧ node, the expressions of its children are over disjoint sets of Boolean variables. A Deterministic DNNF, or d-DNNF is a DNNF where for every ∨ node, the expressions of its children are mutually exclusive. Given a d-DNNF one can compute its probability in polynomial time, by applying the rules P(Φ x Φ y )=P(Φ x )P(Φ y ) and P(Φ x Φ y )=P(Φ x )+P(Φ y ) (and similarly for nodes with out-degree greater than 2); this justifies our interest in d-DNNF. Any FBDD of size n can be converted to an d-DNNF of size 5n [13]: for any interior node labeled with variable X in the FBDD, write its formula as (¬X)∧Φ y XΦ z , where y and z are the 0-child and the 1-child: obviously, the ∨ is “deterministic”, and the ∧’s are “decomposable”.

It is open whether d-DNNFs are closed under negation [13, pp. 14]; NNFs are obviously closed under negation, but the d-DNNF impose asymmetric restrictions on ∧ and ∨, so by switching them during negation, the resulting NNF is no longer a d-DNNF. For that reason, we extend here d-DNNF’s with ¬-nodes, and denote the result d-DNNF¬: probability computation can still be done in polynomial time on a d-DNNF¬.

Definition 17

UCQ(dDNNF) is the class of queries Q s.t. for any database D, one can construct a d-DNNF for \(\neg \varPhi _{Q}^{D}\) in time polynomial in |D|. UCQ(dDNNF ¬) is the class of queries Q s.t. one can construct a d-DNNF¬ for \(\varPhi _{Q}^{D}\) in time polynomial in |D|.

UCQ(FBDD)⊆UCQ(dDNNF)⊆UCQ(dDNNF ¬)⊆UCQ(P); the first inclusion is can be shown to be strict.

Proposition 9

q W UCQ(dDNNF)−UCQ(FBDD).

The significance of this result is the following. This is, to the best of our knowledge, the first example of a “simple” Boolean expression (meaning monotone, and with a polynomial size DNF) that has a polynomial size d-DNNF but not FBDD. The previous separation of FBDD and d-DNNF is based on a result by Bollig and Wegener [2], which we review briefly. Consider a Boolean matrix of variables X ij . Let Φ 1 denote the formula “there are an even number of 1’s and there is a row consisting only of 1’s”. Let Φ 2 denote the formula “there are an odd number of 1’s and there is a column consisting only of 1’s”; in [2] the authors show that Φ 1Φ 2 does not have a polynomial size FBDD. However, this formula has a polynomial size d-DNNF, because each of Φ 1,Φ 2 has polynomial size OBDD and Φ 1Φ 2false. Note, however, that these formulas are non-monotone and have exponential size DNF’s (they are not in AC0). By contrast, the lineage of q W is monotone, has polynomial size DNF, and separates FBDD from d-DNNF.

In the rest of the section, we give a sufficient criterion for a query Q=d 1∧⋯∧d m , to be in UCQ(dDNNF ¬), which is quite interesting because it explains the border between d-DNNF and PTIME in terms of lattice-theoretic concepts. We need to define some lattice theoretic concepts first. Let the CNF lattice of Q be (L,≤).

We now describe the construction algorithm. If m=1 then Q is a disjunctive query; in this case it must have a separator (assuming FP ≠ #P (Theorem 1)), d 1=∃w.Q 1 and we write: ¬Q=⋀ aADom(D) Q 1[a/w]. The ∧ operator is “decomposable”, i.e. its children are independent.

If m≥2, we express Q=Q 1Q 2, and consider the following derivation for ¬Q, where we write ∨d to indicate that a ∨ operation is disjoint:

(5)

The effect of the decomposition above is that it reduces Q to three subqueries, namely Q 1, Q 2, and Q 1Q 2, whose CNF lattices are meet-sublattices of L, obtained as follows. Let Q=Q 1Q 2, where Q 1=d l1d l2∧⋯ and Q 2=d o1d o2∧⋯. Denote by v 1,…,v m ,u 1,…,u k the co-atoms of this lattice, such that v 1,v 2,… are the co-atoms corresponding to d l1,d l2,… and u 1,u 2,… are the co-atoms for d o1,d o2,….

  • The CNF lattice of Q 1 is \(\overline{M}\), where M={v 1,…,v m }.

  • The CNF lattice of Q 2 is \(\overline{K}\), where K={u 1,…,u k }.

  • The CNF lattice of Q 1Q 2=⋀ i,j (d li d oj ) is \(\overline{N}\), where N={v i u j i=1,m;j=1,k}. Here v i u j denotes the lattice-meet, and corresponds to the query-union.

Note that each of the three lattices above, \(\bar{M}, \bar{K},\bar{N}\) is a strict subset of L.

This justifies the following definition of d-safe queries, analogous to safe queries Definition 4.

Definition 18

(1) Let Q=Q 1Q 2. Then Q is d-safe if Q 1,Q 2,Q 1Q 2 are all d-safe. (2) Let d=c 1∨⋯∨c k be a disjunctive query, and let d=d 0d 1, where d 0 contains all components c i without variables, and d 1 contains all components c i with at least one variable. Then d is d-safe if d 1 has a separator w and d 1[a/w] is d-safe.

Theorem 8

If Q is d-safe, then it is in UCQ(dDNNF ¬).

To illustrate this algorithm, we now show how to construct a d-DNNF for q W .

Proof of Proposition 9

Consider q W =d 1d 2d 3 in Fig. 1.

Denote the three lower points in the lattice as:

We express Q W as d 1∧(d 2d 3), and using (5) get

d 1 is hierarchical-read-once, and d 2d 3 is inversion-free; hence they both have compact d-DNNF. d 1∨(d 2d 3)=d 12 is inversion-free and hence it also admits a compact d-DNNF. □

We prove now that every d-safe query is also safe. Fix a lattice L. Every non-empty subset \(S \subseteq L- \{\hat{1}\}\) corresponds to a query, ⋀ uS λ(u). We define a nondeterministic function NE that maps a non-empty set \(S \subseteq L - \{\hat{1}\}\) to a set of elements \(\mathit{NE}(S) \subseteq \overline{S}\), as follows. If S={v} is a singleton set, then NE(S)={v}. Otherwise, partition S non-deterministically into two disjoint, non-empty sets S=MK, define N={vuvM,uK}, and define NE(S)=NE(M)∪NE(K)∪NE(N). Thus, NE(S) is non-deterministic, because it depends on our choice for partitioning S. The intuition is the following: in order for the query ⋀ uS λ(u) to be d-safe, all lattice points in NE(S) must also be d-safe: they are “non-erasable”.

Call an element zL erasable if there exists a non-deterministic choice for NE(L ) that does not contain z. Recall that L is the set of co-atoms of L. The intuition is that, if z is erasable, then there exists a sequence of applications of rules from Definition 18, which avoids computing z; in other words, it “erases” z from the list of queries in the lattice for which it needs to compute the d-DNNF ¬, and therefore Q z is not required to be d-safe. We prove that only queries Q z where \(\mu_{L}(z,\hat{1})=0\) can be erased:

Lemma 9

If z is erasable in L, then \(\mu_{L}(z, \hat{1}) = 0\).

Proof

We prove the following claim, by induction on the size of the set S: if zNE(S), \(z \neq \hat{1}\), then \(\mu_{\overline{S}}(z, \hat{1}) = 0\) (if \(z \notin \overline{S}\), then we define \(\mu_{\overline{S}}(z, \hat{1}) = 0\)). The lemma follows by taking S=L (the set of all co-atoms in L).

If S={v}, then NE(S)={v} and \(\overline{S} = \{v,\hat{1}\}\): therefore, the claim hold vacuously. Otherwise, let S=MK, and define N={vuvM,uK}. We have NE(S)=NE(M)∪NE(K)∪NE(N). If zNE(S), then zNE(M), zNE(K), and zNE(N). By induction hypothesis \(\mu_{\overline{M}}(z, \hat{1}) =\mu_{\overline{K}}(z, \hat{1}) = \mu_{\overline{N}}(z, \hat{1}) = 0\). Next, we notice that (1) \(\overline{M}, \overline{K}, \overline{N}\subseteq \overline{S}\), (2) \(\overline{S} = \overline{M} \cup \overline{K} \cup \overline{N}\) and (3) \(\overline{M} \cap \overline{K} = \overline{N}\). Then, we apply the definition of the Möbius function directly, using a simple inclusion-exclusion formula:

 □

The lemma implies immediately:

Proposition 10

For any UCQ query Q, if Q is d-safe, then it is safe. The converse does not hold in general: query q 9 is safe but is not d-safe.

It is conjectured that q 9UCQ(dDNNF ¬). Note that the proposition only states that q 9 is not d-safe, but it is not known whether d-safety is a complete characterization of UCQ(dDNNF ¬).

Proof

We prove the statement by induction on Q. We show only the key induction step, which is when Q=⋀ i d i , and L is its CNF lattice. Let ZL denote the nodes corresponding to d-unsafe queries: if Q is d-safe, then all elements in Z are erasable. This implies that ∀zZ, \(\mu(z, \hat{1}) = 0\). Hence, we can apply Möbius’ inversion formula to the lattice L, and refer only to queries that are d-safe; by induction hypothesis, these queries are also safe, implying that Q is safe.

We show that q 9 is safe, but is not d-safe. We will denote the lattice points with query d i d j ∨⋯ in Fig. 1 as d ij. The query at \(\hat{0}\) is the only hard query (since it is equivalent to h 3), and \(\mu(\hat{0},\hat{1}) = 0\). On the other hand, we prove that \(\hat{0}\) cannot be erased. Indeed, the co-atoms of the lattice are L ={d 1,d 2,d 3,d 4}; given the symmetry of d 1,d 2,d 3, there are only three ways to partition the co-atoms into two disjoint sets L =MK:

  • M={d 1,d 2,d 3}, K={d 4}. In this case the lattice \(\overline{M}\) is \(\{\hat{0}, d_{12}, d_{13}, d_{23}, d_{1},d_{2},\allowbreak d_{3}, \hat{1}\}\), and \(\mu_{\overline{M}}(\hat{0}, \hat{1}) = -1\), proving that this query is unsafe, and, therefore, d-unsafe.

  • M={d 1,d 2}, K={d 3,d 4}. In this case the lattice \(\overline{K}\) is \(\{\hat{0}, d_{3}, d_{4}, \hat{1}\}\), and has \(\mu_{\overline{K}}(\hat{0}, \hat{1}) = 1\), hence, by the same argument, is d-unsafe.

  • M={d 1}, K={d 2,d 3,d 4}. Here, too, \(\overline{K} = \{\hat{0}, d_{23}, d_{2}, d_{3}, d_{4}, \hat{1}\}\), and \(\mu_{\overline{K}}(\hat{0}, \hat{1})= 1\).

 □

7 Results on Non-uniform Classes

In this section we look at the non-uniform compact classes for different targets T.

Definition 19

For target T∈{OBDD,FBDD,d-DNNF}, denote by UCQ n(T) the class of all queries QUCQ s.t. \(\varPhi _{D}^{Q}\) has a compilation in T of size polynomial in |D| for all D.

Note that in case of RO, a formula is either RO or not RO. Furthermore, thanks to the result due to Gurvich [19], this can be done in PTIME for monotone formulas that form the lineages of UCQ. On the other hand, a formula may have a compact OBDD, FBDD, or d-DNNF, but our algorithm may not be able to construct it. Hence UCQ n(T)⊇UCQ(T).

For OBDD though, it follows from the results of Sect. 4, that

Proposition 11

UCQ n(OBDD)=UCQ(OBDD).

The proof follows from Proposition 7, which implies that queries not in UCQ(OBDD) do not have a polynomial size OBDD, i.e., UCQUCQ(OBDD)⊆UCQUCQ n(OBDD). Hence UCQ n(OBDD)⊆UCQ(OBDD), which means the two sets must be equal.

We do not have a full characterization for FBDD, d-DNNF, so we do not know if the same is true for them. The main separation results though still hold for non-uniform classes as well.

Proposition 12

Proof

We can construct an FBDD for q V in PTIME (Theorem 5), but it doesn’t always admit a compact OBDD (Proposition 7). This proves the first result. Similarly one can construct a d-DNNF for q W in PTIME (Proposition 9), but it admits no polynomial size FBDD (Theorem 6). This proves the last two separations. □

8 Conclusion

We have studied the problem of compiling the query lineage into compact representations. We considered four compilation targets: read-once, OBDD, FBDD, and d-DNNF. We showed that over the query language of unions of conjunctive queries, these four classes form a strict hierarchy. For the first two classes we gave a complete characterization based on the query’s syntax. For the last two classes we gave sufficient characterizations.

Our two main separation results, between UCQ(OBDD) and UCQ(FBDD), and between UCQ(FBDD) and UCQ(dDNNF), are the first examples of “simple” Boolean expressions (meaning: monotone, and with polynomial size DNFs) that separate those two classes.

We leave three open problems: complete characterizations of FBDD and d-DNNF, and separation of the latter from PTIME. Also, as future work, it would be interesting to investigate compact representations of lineages in other semirings described in [17].