Enumeration Complexity of Conjunctive Queries with Functional Dependencies

We study the complexity of enumerating the answers of Conjunctive Queries (CQs) in the presence of Functional Dependencies (FDs). Our focus is on the ability to list output tuples with a constant delay in between, following a linear-time preprocessing. A known dichotomy classifies the acyclic self-join-free CQs into those that admit such enumeration, and those that do not. However, this classification no longer holds in the common case where the database exhibits dependencies among attributes. That is, some queries that are classified as hard are in fact tractable if dependencies are accounted for. We establish a generalization of the dichotomy to accommodate FDs; hence, our classification determines which combination of a CQ and a set of FDs admits constant-delay enumeration with a linear-time preprocessing. In addition, we generalize a hardness result for cyclic CQs to accommodate unary FDs, and further conclusions of our development include a dichotomy for enumeration with linear delay. Finally, we show that all our results apply also for CQs with disequalities and in the presence of cardinality dependencies that generalize FDs.


Introduction
When evaluating a non-boolean Conjunctive Query (CQ) over a database, the number of results can be huge.Since this number may be larger than the size of the database itself, we need to use specific measures of enumeration complexity to describe the hardness of such a problem.In this perspective, the best we can hope for is to constantly output results, in such a way that the delay between them is unaffected by the size of the database instance.For this to be possible, we need to allow a precomputation phase before printing the first result, as linear time preprocessing is necessary to read the input instance.

11:2 Enumeration Complexity of CQs with FDs
A known dichotomy determines when the answers to self-join-free acyclic CQs can be enumerated with constant delay after linear time preprocessing [3].This class of enumeration problems, denoted by DelayC lin , can be regarded as the most efficient class of nontrivial enumeration problems and therefore current work on query enumeration has focused on this class [10,15,5].Bagan et al. [3] show that a subclass of acyclic queries, called free-connex, are exactly those that are enumerable in DelayC lin , under the common assumption that boolean matrix multiplication cannot be solved in quadratic time.An acyclic query is called free-connex if the query remains acyclic when treating the head of the query as an additional atom.This and all other results in this paper hold under the RAM model [16].
The above mentioned dichotomy only holds when applied to databases with no additional assumptions, but oftentimes this is not the case.In practice, there is usually a connection between different attributes, and Functional Dependencies (FDs) and Cardinality Dependencies (CDs) are widely used to model situations where some attributes imply others.As the following example shows, these constraints also have an immediate effect on the complexity of enumerating answers for queries over such a schema.
Example 1.For a list of actors and the production companies they work with, we have the query: Q(actor, production) ← Cast(movie, actor), Release(movie, production).At first glance, it appears as though this query is not in DelayC lin , as it is acyclic but not free-connex.Nevertheless, if we take the fact that a movie has only one production company into account, we have the FD Release : movie → production, and the enumeration problem becomes easy: we only need to iterate over all tuples of Cast and replace the movie value with the single production value that the relation Release assigns to it.This can be done in linear time by first sorting (in linear time [12]) both relations according to movie.
Example 1 shows that the dichotomy by Bagan et al. [3] does not hold in the presence of FDs.In fact, we believe that dependencies between attributes are so common in real life, that ignoring them in such dichotomies can lead to missing a significant portion of the tractable cases.Therefore, to get a realistic picture of the enumeration complexity of CQs, we have to take dependencies into account.The goal of this work is to generalize the dichotomy to fully accommodate FDs.
Towards this goal, we introduce an extension of a query Q according to the FDs.The extension is called the FD-extended query, and denoted Q + .In this extension, each atom, as well as the head of the query, contains all variables that can be implied by its variables according to some FD.This way, instead of classifying every combination of CQ and FDs directly, we encode the dependencies within the extended query, and use the classification of Q + to gain insight regarding Q.This approach draws inspiration from the proof of a dichotomy in the complexity of deletion propagation, in the presence of FDs [13].However, the problem and consequently the proof techniques are fundamentally different.
The FD-extension is defined in such a way that if Q is satisfied by an assignment, then the same assignment also satisfies the extension Q + , as the underlying instance is bound by the FDs.In fact, we can show that enumerating the solutions of Q under FDs can be reduced to enumerating the solutions of Q + .Therefore, tractability of Q + ensures that Q can be efficiently solved as well.By using the positive result in the known dichotomy, Q + is tractable w.r.t enumeration if it is free-connex.Moreover, it can be shown that the structural restrictions of acyclicity and free-connex are closed under taking FD-extensions.Hence, the class of all queries Q such that Q + is free-connex is an extension of the class of free-connex queries, and this extension is in fact proper.We denote the classes of queries Q such that Q + is acyclic or free-connex as FD-acyclic respectively FD-free-connex.

11:3
To reach a dichotomy, we now need to answer the following question: Is it possible that Q can be enumerated efficiently even if Q + is not free-connex?To show that an enumeration problem is not within a given class, enumeration complexity has few tools to offer.One such tool is a notion of completeness for enumeration problems [9].However, this notion focuses on problems with a complexity corresponding to higher classes of the polynomial hierarchy.So in order to deal with this problem, Bagan et al. [3] reduced the matrix multiplication problem to enumerating the answers to any query that is acyclic but not free-connex.This reduction fails, however, when dependencies are imposed on the data, as the constructed database instance does not necessarily satisfy the underlying dependencies.
As it turns out, however, the structure of the FD-extended query Q + allows us to extend this reduction to our setting.By carefully expanding the reduced instance such that on the one hand, the dependencies hold and on the other hand, the reduction can still be performed within linear time, we establish a dichotomy.That is, we show that the tractability of enumerating the answers of a self-join-free query Q in the presence of FDs is exactly characterized by the structure of Q + : Given an FD-acyclic query Q, we can enumerate the answers to Q within the class DelayC lin iff Q is FD-free-connex.
The resulting extended dichotomy, as well as the original one, brings insight to the case of acyclic queries.Concerning unrestricted CQs, providing even a first solution of a query in linear time is impossible in general.This is due to the fact that the parameterized complexity of answering boolean CQs, taking the query size as the parameter, is W[1]-hard [14].This does not imply, however, that there are no cyclic queries with the corresponding enumeration problems in DelayC lin .The fact that no such queries exist requires an additional proof, which was presented by Brault-Baron [6].This result holds under a generalization of the triangle finding problem, which is considered not to be solvable within linear time [17].As before, this proof does no longer apply in the presence of FDs.Moreover, it is possible for Q to be cyclic and Q + acyclic.In fact, Q + may even be free-connex, and therefore tractable in DelayC lin .We show that, under the same assumptions used by Brault-Baron [6], the evaluation problem for a self-join-free CQ in the presence of unary FDs where Q + is cyclic cannot be solved in linear time.As linear time preprocessing is not enough to achieve the first result, a consequence is that enumeration within DelayC lin is impossible in that case.This covers all types of CQs and shows a full dichotomy, at least for the case of unary FDs.
The results we present here are not limited to FDs.CDs (Cardinality Dependencies) [7,2] are a generalization of FDs, denoted (R i : A → B, c).Here, the right-hand side does not have to be unique for every assignment to the left-hand side, but there can be at most c different values to the variables of B for every value of the variables of A. FDs are in fact a special case of CDs where c = 1.Constraints of that form appear naturally in many applications.For example: a movie has only a handful of directors and there are at most 200 countries.We show that all results described in this paper also apply to CDs.Moreover, we show how our results can be easily used to yield additional results, such as a dichotomy for CQs with disequalities, and a dichotomy to evaluate CQs with linear delay.

Contributions.
Our main contributions are as follows.
We extend the class of queries that can be evaluated in DelayC lin by incorporating the FDs.This extension is the class of FD-free-connex CQs.We establish a dichotomy for the enumeration complexity of self-join-free FD-acyclic CQs.Consequently, we get a dichotomy for self-join-free acyclic CQs under FDs.We show a lower bound for FD-cyclic CQs.In particular, we get a dichotomy for all self-join-free CQs in the presence of unary FDs.We extend our results to CDs.

I C D T 2 0 1 8 11:4 Enumeration Complexity of CQs with FDs
This work is organized as follows: In Section 2 we provide definitions and results that we will use.Section 3 introduces FD-extended queries and establishes the equivalence between a query and its FD-extension.The generalized version of the dichotomy is shown in Section 4. In Section 5, a lower bound for cyclic queries under unary FDs is shown, and Section 6 shows that all results from the previous sections extend to CDs.Concluding remarks are given in Section 7. All missing proof details can be found in the full version of this article [8].

Preliminaries
In this section we provide preliminary definitions as well as state results that we will use throughout this paper.

Schemas and Functional
Conjunctive Queries.Let var be a set of variables disjoint from dom.A Conjunctive Query (CQ) over a schema S = (R, ∆) is an expression of the form Q( x) ← R 1 ( v 1 ), . . ., R m ( v m ), where R 1 , . . ., R m are relational symbols of R, the tuples x, v 1 , . . ., v m hold variables, and every variable in x appears in at least one of v 1 , . . ., v m .We often denote this query as Q( x) or even Q.Define the variables of Q as var(Q) = m i=1 v i , and define the free variables of Q as free(Q) = x.We call Q( x) the head of Q, and the atomic formulas R i ( v i ) are called atoms.We further use atoms(Q) to denote the set of atoms of Q.A CQ is said to contain self-joins if some relation symbol appears in more than one atom.
For the evaluation Q(I) of a CQ Q with free variables x over a database I, we define Q(I) to be the set of all mappings µ| x such that µ is a homomorphism from R 1 ( v 1 ), . . ., R m ( v m ) into I, where µ| x denotes the restriction (or projection) of µ to the variables x.The problem Decide ∆ Q is, given a database instance I, determining whether such a mapping exists.
Given a query Q over a schema S = (R, ∆), we often identify an FD δ ∈ ∆ as a mapping between variables.That is, if δ has the form To distinguish between these two representations, we usually denote subsets of integers by A, B, C, . .., integers by a, b, c, . .., and variables by letters from the end of the alphabet.

Hypergraphs.
A hypergraph H = (V, E) is a pair consisting of a set V of vertices, and a set E of non-empty subsets of V called hyperedges (sometimes edges).A join tree of a hypergraph H = (V, E) is a tree T where the nodes are the hyperedges of H, and the running intersection property holds, namely: for all u ∈ V the set {e ∈ E | u ∈ e} forms a connected subtree in T .A hypergraph H is said to be acyclic if there exists a join tree for H. Two vertices in a hypergraph are said to be neighbors if they appear in the same edge.A clique of a hypergraph is a set of vertices, which are pairwise neighbors in H.A hypergraph H is said to be conformal if every clique of H is contained in some edge of H.A chordless cycle of H is a tuple (x 1 , . . ., x n ) such that the set of neighboring pairs of variables of {x 1 , . . ., [4]) that a hypergraph is acyclic iff it is conformal and contains no chordless cycles.
A pseudo-minor of a hypergraph H = (V, E) is a hypergraph obtained from H by a finite series of the following operations: (1) vertex removal: removing a vertex from V and from all edges in E that contain it.(2) edge removal: removing an edge e from E provided that some other e ∈ E contains it.(3) edge contraction: replacing all occurrences of a vertex v (within every edge) with a vertex u, provided that u and v are neighbors.

Classes of CQs.
To a CQ Q we associate a hypergraph H(Q) = (V, E) where the vertices V are the variables of Q and every hyperedge E is a set of variables occurring in a single atom of that is, two succeeding variables appear together in some atom, and no two non-succeeding variables appear together in an atom.Bagan et al. [3] showed that an acyclic CQ has a head-path iff it is not free-connex.
Enumeration Complexity.Given a finite alphabet Σ and binary relation R ⊆ Σ * × Σ * , we denote by Enum R the enumeration problem of given an instance x ∈ Σ * , to output all y ∈ Σ * such that (x, y) ∈ R. In this paper we adopt the Random Access Machine (RAM) model (see [16]).Previous results in the field assume different variations of the RAM model.Here we assume that the length of memory registers is linear in the size of value registers, that is, the accessible memory is polynomial.For a class C of enumeration problems, we say that Enum R ∈ C, if there is a RAM that -on input x ∈ Σ * -outputs all y ∈ Σ * with (x, y) ∈ R without repetition such that the first output is computed in time p(|x|) and the delay between any two consecutive outputs after the first is d(|x|), where: For Enum R ∈ DelayC lin , we have p

(|x|) ∈ O(|x|) and d(|x|) ∈ O(1).
For Enum R ∈ DelayLin, we have p(|x|), d(|x|) ∈ O(|x|).Let Enum R 1 and Enum R 2 be enumeration problems.We say that there is an exact reduction from Enum R 1 to Enum R 2 , written as Enum R 1 ≤ e Enum R 2 , if there are mappings σ and τ such that for every [3] proved that DelayC lin is closed under exact reduction.The same proof holds for any meaningful enumeration complexity class that guarantees generating all unique answers with at least linear preprocessing time and at least constant delay between answers.
Enumerating Answers to CQs.For a CQ Q over a schema S = (R, ∆), we denote by Enum ∆ Q the enumeration problem Enum R , where R is the binary relation between

11:6
Enumeration Complexity of CQs with FDs instances I over S and sets of mappings Q(I).We consider the size of the query as well as the size of the schema to be fixed.Bagan et al. [3] showed that a self-join-free acyclic CQ is in DelayC lin iff it is free-connex: assuming the product of two n × n boolean matrices cannot be computed in time O(n 2 ).

FD-Extended CQs
In this section, we formally define the extended query Q + .We then discuss the relationship between Q and Q + : their equivalence w.r.t.enumeration and the possible structural differences between them.As a result, we obtain that if Q + is in a class of queries that allows for tractable enumeration, then Q is tractable as well.
We first define Q + .The extension of an atom R( v) according to an FD S : is added to the variables of R. The FD-extension of a query is defined by iteratively extending all atoms as well as the head according to every possible dependency in the schema, until a fixpoint is reached.The schema extends accordingly: the arities of the relations increase as their corresponding atoms extend, and dummy variables are added to adjust to that change in case of self-joins.The FDs apply in every relation that contains all relevant variables.
be a CQ over a schema S = (R, ∆).We define two types of extension steps: The extension of an atom R i ( v i ) according to an FD R j : A → b.
The arity of R i increases by one, and , where t k is a fresh variable.The extension of the head Q( w) according to an FD R j : A → b.
), obtained by performing all possible extension steps on Q according to FDs of ∆ until a fixpoint is reached.The extension is defined over the schema S + = (R + , ∆ Q + ), where R + is R with the extended arities, and }.Given a query, its FD-extension is unique up to a permutation of the added variables, and renaming of the new variables.As the order of the variables and the naming make no difference w.r.t.enumeration, we can treat the FD-extension as unique.
Example 4. Consider a schema with ∆ = {R 1 : 1 → 2, R 3 : 2, 3 → 1}, and the query We first apply x → y on the head, and then x → y and consequently yz → w on R 2 (x, z).These two FDs now appear in the schema also for R 2 , and the FDs of the extended schema are We later show that the enumeration complexity of a CQ Q over a schema with FDs only depends on the structure of Q + , which is implicitly given by Q.Therefore, we introduce the notions of acyclic and free-connex queries for FD-extensions: 11:7 Definition 5. Let Q be a CQ over a schema S = (R, ∆), and let Q + be its FD-extension.We say that The following proposition shows that the classes of acyclic queries and free-connex queries are both closed under constructing FD-extensions.Proposition 6.Let Q be a CQ over a schema S = (R, ∆).
If the query Q is acyclic, then it is FD-acyclic.
If the query Q is free-connex, then it is FD-free-connex.
Example 1 shows that the converse of the proposition above does not hold.This means that, by Theorem 2, there are queries Q such that we can enumerate the answers to Q + in DelayC lin , but we cannot enumerate the answers to Q with the same complexity, if we do not assume the FDs.The following lemma shows that enumerating the answers of Q (when relying on the FDs) is in fact equally hard as enumerating the answers of Q + .Theorem 7. Let Q be a CQ over a schema S = (R, ∆), and let Q + be its FD-extended query.Then Proof Sketch.We first sketch the reduction Enum ∆ Q ≤ e Enum ∆ Q + Q + .Given an instance I for the problem Enum ∆ Q , we set σ(I) = I + as described next.We start by removing tuples that interfere with the extended dependencies.For every dependency R j : X → y and every atom R k ( v k ) that contains the variables X ∪ {y}, we only keep tuples of R I k that agree with some tuple of R I j over the values of X ∪ {y}.Next, we follow the extension of the schema, and in each step we extend some R I i to R I i according to some FD R j : X → y.For each tuple t ∈ R I i , if there is no tuple s ∈ R I j that agrees with t over the values of X, then we remove t altogether.Otherwise, we copy t to R I i and assign y with the same value that s assigns it.Given an answer µ ∈ Q + (σ(I)), we set τ (µ) to be the projection of µ to free(Q).To show that Enum ∆ Q + Q + ≤ e Enum ∆ Q , we describe the construction of an instance σ(I + ) by "reversing" the extension steps.If an atom was extended, we simply remove the added attribute.If the head was extended using some R j : X → y, then for each tuple in R I i+1 j that assigns y and X with the values y 0 and x 0 respectively, we add the value y 0 to a lookup table with pointer (X, x 0 , y).For every µ ∈ Q(σ(I + )), τ (µ) is defined as µ extended by the values from the lookup table.
The direction Enum ∆ Q ≤ e Enum ∆ Q + Q + of Theorem 7 proves that FD-extensions can be used to expand tractable enumeration classes, as the following corollary states.Corollary 8. Let C be an enumeration class that is closed under exact reduction.Let Q be a CQ and let Q + be its FD-extended query.If Since free-connex queries are in DelayC lin and DelayC lin is closed under exact reduction, if Q is an FD-free-connex query, then the corresponding enumeration problem is in DelayC lin .This follows from Theorem 2 and the fact that We can now revisit Example 1.The query Q(x, y) ← R 1 (z, x), R 2 (z, y) is not free-connex.Therefore, disregarding the FDs, according to Theorem 2 it is not in DelayC lin .However, given R 2 : z → y, the FD-extended query is

A Dichotomy for Acyclic CQs
In this section, we characterize which self-join-free FD-acyclic queries are in DelayC lin .We use the notion of FD-extended queries defined in the previous section to establish a dichotomy stating that enumerating the answers to an FD-acyclic query is in DelayC lin iff the query is FD-free-connex.We will prove the following theorem: Theorem 10.Let Q be an FD-acyclic CQ without self-joins over a schema S = (R, ∆).
The positive case for the dichotomy was described in Corollary 9. Note that the restriction of considering only self-joins-free queries is required only for the negative side.This assumption is standard [3,6,13], as it allows to assign different atoms with different relations independently.The hardness result described here builds on that of Bagan et al. [3] for databases that are assumed not to have FDs, and it relies on the hardness of the boolean matrix multiplication problem.This problem is defined as the enumeration Enum ∅ Π of the query Π(x, y) ← A(x, z), B(z, y) over the schema ({A, B}, ∅) where A, B ⊆ {1, . . ., n} 2 .It is strongly conjectured that this problem is not computable in O(n 2 ) time and currently, the best known algorithms require O(n ω ) time for some 2.37 < ω < 2.38 [11,1].
The original proof describes an exact reduction Enum ∅ Π ≤ e Enum ∅ Q .Since Q is acyclic but not free-connex, it contains a head-path (x, z 1 , . . ., z k , y).Given an instance of the matrix multiplication problem, an instance of Enum ∅ Q is constructed, where the variables x,y and z 1 , . . ., z k of the head-path respectively encode the variables x, y and z of Π, while all other variables of Q are assigned constants.This way, A is encoded by an atom containing x and z 1 , and B is encoded by an atom containing z k and y.Atoms containing some z i and z i+1 only propagate the value of z.Since x and y are in f ree(Q), but z i are not, the answers to Q correspond to those of Π.As no atom of Q contains both x and y, the instance can be constructed in linear time.Constant delay enumeration for Q after linear time preprocessing would result in the computation of the answers of Π in O(n 2 ) time.
FDs restrict the relations that can be assigned to atoms.This means that the reduction cannot be freely performed on databases with FDs, and the proof no longer holds.The following example illustrates where the reduction fails in the presence of FDs.
Example 11.The CQ from Example 1 has the form Q(x, y) ← R 1 (z, x), R 2 (z, y) with the single FD ∆ = {R 2 : z → y}.In the previous section, we show that it is in DelayC lin , so the reduction should fail.Indeed, it would assign R 2 with the same relation as B of the matrix multiplication problem, but this may have two tuples with the same z value and different y values.Therefore, the construction does not yield a valid instance of Enum ∆ Q .
We now give a detailed sketch of a modification of this construction that shows that Enum ∅ Π ≤ e Enum ∆ Q + Q + .Any violations of the FDs are fixed by carefully picking more variables other than those of the head-path to take the roles of x,y and z of the matrix multiplication problem.This is done by introducing the sets V x ,V y and V z which are subsets of var(Q).We say that a variable β plays the role of α, if β ∈ V α .
To clarify the explanation of the reduction, we start by describing a restricted case, where all FDs are unary.The basic idea in the case of general FDs will remain the same, but it will require a more involved construction of the sets V α .

Unary Functional Dependencies
For the unary case, we define the sets V x , V y and V z to be the sets of variables that iteratively imply x, y and some z i respectively.That is, for α ∈ {x, y, z 1 , . . ., z k } we first set V α := {α}, and then apply The Reduction.Let I = (A I , B I ) be an instance of Enum ∅ Π .In order to define σ(I), we describe how to construct the relation R I for every atom R( v) ∈ atoms(Q + ).If var(R)∩V y = ∅, then every tuple (a, c) ∈ A I is copied to a tuple in R I .Variables in V x get the value a, variables in V z get the value c, and variables that play no role are assigned a constant ⊥.That is, we define R σ Otherwise, var(R) ∩ V y = ∅, and we show that var(R) ∩ V x = ∅.In this case we define the relation similarly with B I .Given a tuple (c, b) ∈ B I , the variables of V y get the value b, and those of V z are assigned with c.
Example 12. Consider the FD-extended query Using the head-path (x, z, y), the reduction will set V x = {x, u}, V y = {y}, V z = {z, u}.Given an instance of the matrix multiplication problem with relations A and B, every tuple (a, c) ∈ A will result in a tuple ((a, c), a, c) ∈ R, and every tuple (c, b) ∈ B will result in a tuple (⊥, b, c) ∈ S.
We now outline the correctness of this reduction: Well-defined reduction: For an atom R, either we have var(R) That is, no atom contains variables from both V x and V y .Due to the definition of Q + , this atom would otherwise also contain both x and y.However, they cannot appear in the same relation according to the definition of a head-path.The reduction is therefore well defined, and it can be constructed in linear time via copy and projection.Preserving FDs: The construction ensures that if an FD γ → α exists, then γ has all the roles of α.Therefore, either α has no role and corresponds to the constant ⊥, or every value that appears in α also appears in γ.In any case, all FDs are preserved.1-1 mapping of answers: If a variable of V z would appear in the head of Q + , then by the definition of Q + , some z i will be in the head as well.This cannot happen according to the definition of a head-path.Therefore, the head only encodes the x and y values of the matrix multiplication problem, so two different solutions to Enum ∆ Q + Q + must differ in either x or y, and correspond to different solutions of Enum ∅ Π .For the other direction, the head necessarily contains the variables x and y.Therefore, two different solutions to Enum ∅ Π also correspond to different solutions of

General Functional Dependencies
Next we show how to lift the idea of this reduction to the case of general FDs.In the case of unary FDs, we ensure that the construction does not violate a given FD γ → α, by simply encoding the values of α to γ.In the general case, when allowing more than one variable on the left-hand side of an FD γ 1 , . . ., γ k → α, we must be careful when choosing the variables γ j to which we copy the values of α.Otherwise, as the following example shows, we will not be able to construct the instance in linear time.
Example 13.Consider the query Q(x, y) ← R 1 (x, z, t 1 ), R 2 (z, y, t 1 , t 2 ) over a schema with the FD R 2 : t 1 t 2 → y.Note that Q = Q + is acyclic but not free-connex, and that (x, z, y) is a head-path in H(Q + ).To repeat the idea shown in the unary case and ensure that the FDs still hold, the variable on the right-hand side of every FD is encoded to the variables on the left-hand side.If we encode y to t 1 , then R 1 would contain the encodings of x, y and z.This means that its size will not be linear in that of the matrix multiplication instance, and we cannot hope for linear time construction.On the other hand, if we choose to encode y only to t 2 , the reduction works.
In the following central lemma, we describe a way of carefully picking the variables to which we assign roles, such that all FDs hold and yet the instance can be constructed in linear time.The idea is that we consider the join-tree of Q + and define V x and V y to hold variables that appear only in disjoint parts of this tree.This ensures that no atom contains variables of each.The property of a join-tree is used to guarantee that V x and V y are inclusive enough to correct all FD violations.Lemma 14.Let Q be a CQ with no self-joins over a schema S = (R, ∆), such that Q + is acyclic but not free-connex.Denote a head-path of Q + by (x, z 1 , . . ., z k , y).Then there exist sets of variables V x , V y , V z such that: Proof Sketch.We first define a partition of the atoms of Q into three sets: T x , T y and T mid , where T mid may be empty.Let T be a join tree of H(Q + ), and denote the hyperedges on the head-path by e(x, z 1 ), . . ., e(z k , y).Note that, by definition, each hyperedge of the head-path is a vertex of T .By the running intersection property of T , we can conclude that there is a simple path P from e(x, z 1 ) to e(z k , y) in T , such that e(z 1 , z 2 ), . . ., e(z k−1 , z k ) lie on that path in the order induced by the head-path.Let sep x be the first node on the path P that does not contain x.This exists because e(z k , y) does not contain x, as the head-path is chordless.Similarly, let sep y be the last node on P that does not contain y.Let T x be the set of nodes v in T such that the unique path from v to e(x, z 1 ) does not go through sep x .Similarly, let T y be the set of nodes w in T such that the unique path from w to e(z k , y) does not go through sep y .Next set T mid = V (T ) \ (T x ∪ T y ).Note that the nodes of T are exactly T x ∪ T mid ∪ T y , and we can show that this union is disjoint (see Figure 1).Also note that e(x, z 1 ) ∈ T x and e(z k , y) ∈ T y , but T mid may be empty if the head-path is of length three.Therefore, we established a partition of the atoms to two or three sets.

11:11
Next we define the sets of variables V x , V y and V z .To do so, for w ∈ var(Q), denote Intuitively, Implies(w) is the set of all variables on the left-hand side of FDs that have w on the right-hand side.We now define V x to contain x, and recursively to contain variables that imply those of V x , but we do not take variables that appear outside of T x .V y is defined symmetrically.V z is defined to contain z 1 , . . ., z k , and recursively contain variables that imply those of V z , but now we do not take variables that appear in the head of the query.
More formally, we recursively define: We now prove that V x , V y and V z meet the requirements of the lemma.1.The first claim is immediate from the definition of the sets.

We first show the claim for
and let e(U, be an atom containing all variables of δ.As v ∈ V x , we know that e(U, v) / ∈ T y ∪ T mid , therefore e(U, v) ∈ T x .Assume by contradiction that U ∩ V x = ∅.Let u ∈ U .By definition of V x , this means that u ∈ var(e u ) for some e u ∈ T y ∪ T mid .As T x , T y and T mid are disjoint, we have that e u / ∈ T x , which means that the path between e u and e(x, z 1 ) goes through sep x .This means that the path from e u to e(U, v) goes through sep x too, otherwise the concatenation of this path with the path from e(U, v) to e(x, z 1 ) would result in a path from e u to e(x, z 1 ) not going through sep x .By the running intersection property, u ∈ var(sep x ).Since this is true for all for all u ∈ U , it follows that v ∈ var(sep x ) by definition of Q + , contradicting the fact that v ∈ V x .The case α = y is symmetric.Now for the case where α = z.If U ∩ V z = ∅, then U ⊆ free(Q + ), and by the definition of Q + , z i ∈ free(Q + ), which is a contradiction to the fact that v ∈ var(Q) \ free(Q + ).
Otherwise, R ∈ T y ∪ T mid , and similarly var(R) ∩ V x = ∅.4. By definition of V z , it does not contain any variables of free(Q + ).
With the sets V x , V y , V z at hand, we can now perform the reduction between the two problems for general FDs.The reduction is based on the case of unary FDs, but with the sets defined according to Lemma 14. Requirements 1 and 4 on the sets guarantee a one-to-one mapping between the results of the two problems, requirement 2 guarantees that all FDs are preserved, and requirement 3 guarantees linear time construction.

Lemma 15.
Let Q be a CQ with no self-joins over a schema S = (R, ∆).
This lemma, along with Theorem 7, establishes the hardness result in Theorem 10.This result does not contradict the dichotomy given in Theorem 2: If for a given query Q we have that Q + is acyclic but not free-connex, then Q cannot be free-connex by Proposition 6.
Note that Theorem 10, just like the dichotomy presented by Bagan et al. [3], also applies for CQs with disequalities.The extension for such a query is performed as before, ignoring the disequalities.The equivalence described in Theorem 7 still holds, and the proof remains intrinsically the same.The proof of the hardness result presented here also remains similar, with the sole difference that during the construction we take a different and disjoint domain for each variable.This guarantees that all possible disequalities are preserved.

Cyclic CQs
In the previous section, we established a classification of FD-acyclic CQs, but we did not consider FD-cyclic queries.A known result states that, under certain assumptions, selfjoin-free cyclic queries are not in DelayC lin [6].In this section, we therefore explore how FD-extensions can be used to obtain some insight on the implications of this result in the presence of FDs.We show that (under the same assumptions) self-join-free FD-cyclic queries that contain only unary FDs cannot be evaluated in linear time.For schemas containing only unary FDs, this extends the dichotomy presented in the previous section to all CQs, and also proves a dichotomy for the queries that can be enumerated in linear delay.We will prove the following theorem: Theorem 16.Let Q be a CQ with no self-joins over a schema S = (R, ∆), where ∆ only contains unary FDs.If Q is FD-cyclic, then Decide ∆ Q cannot be solved in linear time, assuming that the Tetra(k) problem cannot be solved in linear time for any k.
As before, the initial hardness proof for cyclic queries no longer holds in the presence of FDs, and we modify the reduction to fix any violations of the FDs.We start by describing the assumption used to obtain the conditional lower bounds.We define Tetra(k) to be the hypergraph with the vertices {1, . . ., k} and the edges {{1, . . ., k} \ {i} | i ∈ {1, . . ., k}}.Let H be a hypergraph.With a slight abuse of notation, we also denote by Tetra(k) the decision problem of whether H contains a subhypergraph isomorphic to Tetra(k).Note that Tetra(3) is the problem of deciding whether a graph contains a triangle, which is strongly believed to be not solvable within time linear in the size of the graph [17].The generalization of this assumption is that the Tetra(k) problem cannot be solved in time linear in the size of the graph for any k.This is a stronger assumption than we used in Section 4, as the Tetra(3) can be reduced to the matrix multiplication problem [17].We will show that if Q + is cyclic and only unary FDs are present, the problem Tetra(k) for some k can be reduced to Decide ∆ Q + Q + .Definition 17.Let H be a cyclic hypergraph.We denote by Tet pm (H) the pseudo-minors of H isomorphic to Tetra(k) for some k, which are obtained in one of the following ways: 1. Vertex removal steps followed by all possible edge removals.2. Vertex and edge removal steps that lead to a chordless cycle, followed by edge contraction and edge removal steps that result in a Tetra(3).Given a query Q, we define Tet pm (Q) = Tet pm (H(Q)).
Brault-Baron [6] showed that if H is cyclic, then Tet pm (H) = ∅.This proof is provided in the full version of this paper.For the reduction we will present next, we first need to show that for an FD-cyclic query Q, no pseudo-minor in Tet pm (Q + ) contains all variables of any FD X → y.Here, we assume that ∆ only contains non-trivial FDs, meaning y / ∈ X.
Lemma 18.Let Q be an FD-cyclic CQ with no self-joins over a schema S = (R, ∆).For every Proof Sketch.Assume by contradiction that the variables of the FD δ = X → y are all part of the pseudo-minor H pm .Note that the variables X ∪ {y} must appear in a common edge that corresponds to the atom that defines δ.We distinguish between two cases.If H pm is obtained only by vertex removal and edge removal steps, then by the definition of Tetra(k) it also contains an edge e with X ⊆ e and y ∈ e.However, this contradicts the fact that Q + is an FD-extension, as every edge containing X must also contain y.The other case is that H pm is a Tetra(3) obtained by edge contraction steps performed on a cycle C.Then X ∪ {y} is contained in a single edge in C, as none of the vertices X ∪ {y} have been deleted.Thus, we have that |X| = 1 and we can denote X = {x}.As C is a cycle, it contains an edge e with x ∈ e and y ∈ e, which contradicts the fact that Q + is an FD-extension.
We are now ready to establish the reduction.Given a pseudo-minor of Tet pm (Q + ) isomorphic to some Tetra(k), we can reduce the problem of checking whether a hypergraph contains a subhypergraph isomorphic to Tetra(k) to finding a boolean answer to Q + .Lemma 19.Let Q be an FD-cyclic CQ with no self-joins over a schema S = (R, ∆), where ∆ only contains unary FDs.Let H pm ∈ Tet pm (Q + ) be a pseudo-minor of H(Q + ) isomorphic to Tetra(k).Then, Tetra(k) ≤ m Decide ∆ Q + Q + , and this reduction can be computed in linear time.
Proof Sketch.Given an input hypergraph G for the Tetra(k) problem, we define an instance I of Decide ∆ Q + Q + .We consider a sequence H(Q + ) = H 1 , H 2 , . . ., H t = H pm of pseudo-minors, each one obtained by performing one operation over the previous one.We define the instance I inductively, by first generating relations that correspond to the edges of H pm , and then "reversing" the operations.For every edge e of H pm , we define a relation R t e that contains all edges of G that have the same size as e.We then construct the relations R i e of H i given the relations R i+1 e of H i+1 .We make the following case distinction: If an edge e was removed as some e contains it, then the relation R e is added as a projection of R e .If H i+1 is obtained from H i by an edge contraction in which a vertex v is replaced by u, then the values corresponding to u in every tuple are copied to the index of v.If a vertex v is removed, then it is assigned with a constant value, and then the following steps are performed on every tuple to correct any FD violations.First, the values of all variables implied by v are concatenated to its value, and then the new value of v is concatenated to all variables implying it.Since Q + is an FD-extension, and since only unary FDs are present, we can conclude that whenever a vertex is removed, if x implies y, then y is present in every edge containing x.This fact guarantees that the FD-correction steps can be performed.This construction defines relations that correspond to H(Q + ), which form I in such a way that G has a subhypergraph isomorphic to H pm iff Q + (I) = ∅.Compliance to any FDs included in H i is shown by induction on the sequence, and the induction base holds trivially due to Lemma 18. Theorem 16 is an immediate consequence of Lemma 19.As in the previous section, by taking a disjoint domain for every variable in the proof of Lemma 19, Theorem 16 also holds for CQs with disequalities.In terms of enumeration complexity, Theorem 16 means that any enumeration algorithm for the answers of such a query cannot output a first solution (or decide that there is none) within linear time, and we get the following corollary.
Corollary 20.Let Q be a CQ with no self-joins over a schema S = (R, ∆), where ∆ only contains unary FDs.If Q is FD-cyclic, then Enum ∆ Q ∈ DelayC lin , assuming that the Tetra(k) problem cannot be solved in linear time for any k.
Less restrictive than constant delay enumeration, the class DelayLin consists of enumeration problems that can be solved with a linear delay between solutions.A lower bound for this class can be achieved similarly to Corollary 20.Regarding tractability, as acyclic CQs are in DelayLin [3], we conclude from Corollary 8 that FD-acyclic CQs are in this class as well.Thus, we obtain a dichotomy stating that CQs are in DelayLin iff they are FD-acyclic.If Q is FD-acyclic, then Enum ∆ Q ∈ DelayLin.
Otherwise (if Q is FD-cyclic), Enum ∆ Q ∈ DelayLin, assuming that the Tetra(k) problem cannot be solved in linear time for any k.
We conclude this section with a short discussion about the extension of our results to general FDs.The following example shows that the proof for Theorem 16 that was provided here cannot be lifted to general FDs.Exploring this extension is left for future work.
Example 22. Consider the query Q() ← R 1 (x, y, u), R 2 (x, w, z), R 3 (y, v, z), R 4 (u, v, w), over a schema with all possible two-to-one FDs in the relations R 1 , R 2 and R 3 .That is, ∆ = {xy → u, yu → x, ux → y, zy → v, yv → z, vz → y, xz → w, zw → x, wx → z}.Note that Q + = Q.The hypergraph H(Q + ) is cyclic, yet it is unclear whether Q can be solved in linear time, and whether Tetra(3) can be reduced to answering Q + .Using Lemma 18, H(Q + ) has triangle pseudo-minors that do not contain all variables of any FD.Consider for example the one obtained by removing all vertices other than x, y, z.A construction similar to that of Lemma 19 would assign u with the values of x and y, assign v with the values of y and z, and assign w with the values of x and z.This results in the edge {u, v, w} containing all three values of any possible triangle, meaning that this edge cannot be constructed in linear time.Other choices of triangle pseudo-minors lead to similar encoding problems.

Cardinality Dependencies
In this last section, we show that the results of this paper also apply to CQs over schemas with cardinality dependencies.Cardinality Dependencies (CDs) [2,7]  The hardness results extend to CDs because FDs are a special case of CDs.Since every instance that preserves the FDs ∆ FD also preserves the CDs ∆, we can conclude that Enum ∆ FD Q ≤ e Enum ∆ Q .When only FDs are present we can apply Theorem 7, and get Enum ∆ FD Q + Q + ≤ e Enum ∆ FD Q .Combining the two we get the following lemma.Lemma 23.Let Q be a CQ over a schema S = (R, ∆), where ∆ is a set of CDs, and let Q + be the corresponding CD-extension.Then Enum ∆ FD Q + Q + ≤ e Enum ∆ Q .Lemma 23 implies that all negative results presented in this paper hold for CDs.In order to extend the positive results, we need to show that the CD-extension is at least as hard as the original query w.r.t.enumeration.We use a slight relaxation of exact reductions: For Enum R 1 ≤ e Enum R 2 , instead of a bijection between the sets of outputs, one output of Enum R 1 corresponds to at most a constant number of outputs of Enum R 2 .

11:16
Enumeration Complexity of CQs with FDs problem for every k.It will be interesting to see whether we can get the same result based on a weaker assumption.Another possible direction involves CDs.To show that enumerating CD-free-connex CQs can be done in DelayC lin , we require polynomial space to store all printed results.It is unclear whether there exists a solution that requires less space.Finally, we wish to explore how the tools provided here can be used to extend other known results on query enumeration, such as a dichotomy for enumerating CQs [6] with negation, to accommodate FDs.
in DelayC lin by Corollary 9.

Figure 1
Figure 1Join tree T of H(Q + ) for head-paths of length greater than 3.The subtrees Tx, Ty and T mid are disjoint, and are separated by the nodes sepx and sepy.
Let Q be a CQ with no self-joins over a schema S = (R, ∆), where ∆ only contains unary FDs.
are a generalization of FDs, where the left-hand side does not uniquely determine the right-hand side, but rather provides a bound on the number of distinct values it can have.Formally, ∆ is the set of CDs of a schema S = (R, ∆).Every δ ∈ ∆ has the form (R i : A → B, c), where R i : A → B is an FD and c is a positive integer.A CD δ is satisfied by an instance I over S, if every set of tuples S ⊆ (R i ) I that agrees on the indices of A, but no pair of them agrees on all indices of B, contains at most c tuples.It follows from the definition that δ is an FD if c = 1.Denote by ∆ FD the FDs obtained from a set of CDs ∆ by setting all c values to one.Given a query Q over S = (R, ∆), we define the CD-extended query Q + of Q to be the FD-extended query of Q over S = (R, ∆ FD ).The schema S + is defined with the original c values, and the CDs are ∆Q + = {(R + i : A → b, c) | ∃(R j : A → B, c) ∈ ∆, b ∈ B, A ∪ {b} ⊆ var(R + i )}.Note that FD-extensions are indeed a special case of CD-extensions.
Dependencies.A schema S is a pair (R, ∆) where R is a finite set {R 1 , ..., R n } of relational symbols and ∆ is a set of Functional Dependencies (FDs).We denote the arity of a relational symbol R i as arity(R i ).An FD δ ∈ ∆ has the formR i : A → B, where R i ∈ R and A, B are non-empty with A, B ⊆ {1, . .., arity(R i )}.Let dom be a finite set of constants.A database I over schema S is called an instance of S, and it consists of a finite relation R I i ⊆ dom arity(Ri) for every relational symbol R i ∈ R, such that all FDs in ∆ are satisfied.An FD δ = R i : A → B is said to be satisfied if, for all tuples u, v ∈ R I i that are equal on the indices of A, u and v are equal on the indices of B.Here we assume that all FDs are of the form R i : A → b, where b ∈ {1, . . ., arity(R i )}, as we can replace an FD of the form R i : A → B where |B| > 1 by the set of FDs {R