Database Repairing with Soft Functional Dependencies

A common interpretation of soft constraints penalizes the database for every violation of every constraint, where the penalty is the cost (weight) of the constraint. A computational challenge is that of finding an optimal subset: a collection of database tuples that minimizes the total penalty when each tuple has a cost of being excluded. When the constraints are strict (i.e., have an infinite cost), this subset is a"cardinality repair"of an inconsistent database; in soft interpretations, this subset corresponds to a"most probable world"of a probabilistic database, a"most likely intention"of a probabilistic unclean database, and so on. Within the class of functional dependencies, the complexity of finding a cardinality repair is thoroughly understood. Yet, very little is known about the complexity of this problem in the more general soft semantics. This paper makes a significant progress in this direction. In addition to general insights about the hardness and approximability of the problem, we present algorithms for two special cases: a single functional dependency, and a bipartite matching. The latter is the problem of finding an optimal"almost matching"of a bipartite graph where a penalty is paid for every lost edge and every violation of monogamy.


Introduction
Soft variants of database constraints (also referred to as weak or approximate constraints) have been a building block of various challenges in data management.In constraint discovery and mining, for instance, the goal is to find constraints, such as Functional Dependencies (FDs) [3,8,11] and beyond [2,12,16], that generally hold in the database but not necessarily in a perfect manner.There, the reason for the violations might be rare events (e.g., agreement on the zip code but not the state) or noise (e.g., mistyping).Soft constraints also arise when reasoning about uncertain data [6,9,18,19]-the database is viewed as a probabilistic space over possible worlds, and the violation of a weak constraint in a possible world is viewed as evidence that affects the world's probability.
Our investigation concerns the latter application of soft constraints.To be more precise, the semantics is that of a parametric factor graph: the probability of a possible world is the product of factors where every violation of the constraint contributes one factor; in turn, this factor is a weight that is assigned upfront to the constraint.This approach is highly inspired by successful concepts such as the Markov Logic Network (MLN) [17].The computational challenges are the typical ones of probabilistic modeling: marginal inference (compute the probability of a query answer) and maximum likelihood (find the most probable world)-the problem that we focus on here.
More specifically, we investigate the complexity of finding a most probable world in the case where the constraints are FDs.By taking the logarithms of the factors, this problem can be formally defined as follows.We are given a database D and a set ∆ of FDs, where every tuple and every FD has a weight (a nonnegative number).We would like to obtain a cleaner subset E of D by deleting tuples.The cost of E includes a penalty for every deleted tuple and a penalty for every violation of (i.e., pair of tuples that violates) an FD; the penalties are the weights of the tuple and the FD, respectively.The goal is to find a subset E with a minimal cost.In what follows, we refer to such E as an optimal subset and to the optimization problem of finding an optimal subset as soft repairing.The optimal subset corresponds to the "most likely intention" in the Probabilistic Unclean Database (PUD) framework of De Sa, Ilyas, Kimelfeld, Ré and Rekatsinas [18] in a restricted case that is studied in their work, and to the "most probable world" in the probabilistic database model of Sen, Deshpande and Getoor [19].In the special case where the FDs are hard constraints (i.e., their weight is infinite or just too large to pay), an optimal subset is simply what is known as a "cardinality repair" [15] or, equivalently [14], a "most probable database" [6].
The computational challenge of soft repairing is that there are exponentially many candidate subsets.We investigate the data complexity of the problem, where the database schema and the FD set are fixed, and the input consists of the database D and all involved weights.Moreover, we assume that D consists of a single relation; this is done without loss of generality, since the problem boils down to soft repairing each relation independently (since an FD does not involve more than one relation).
The complexity of the problem is very well understood in the case of hard constraints (cardinality repairs).Gribkoff, Van den Broeck and Suciu [6] established complexity results for the case of unary FDs (having a single attribute on the left-hand side), and Livshits, Kimelfeld and Roy [14] completed the picture to a full (effective) dichotomy over all possible sets of FDs.For example, the problem is solvable in polynomial time for the FD sets {A → B}, {A → B, B → A} and {A → B, B → A, B → C}, but is NP-hard for {A → B, B → C}.In contrast, very little is known about the more general case where the FDs are soft (and violations are allowed), where the problem seems to be fundamentally harder, both to solve and to reason about.Clearly, for every ∆ where it is intractable to find a cardinality repair, the soft version is also intractable.But the other direction is false (under conventional complexity assumptions).For example, soft repairing is hard for ∆ = {A → B, B → A, B → C}, for the following reason.We can set the weights of A → B and B → C to be very high, making each of them a hard constraint in effect, and the weight of B → A very low, making it ignorable in effect.Hence, an optimal subset is a cardinality repair for {A → B, B → C} that, as said above, is hard to compute.So, which sets of FDs have a tractable soft repairing?The only polynomial-time algorithm we are aware of is that of De Sa et al. [18] for the special case of a single key constraint, that is, ∆ = {X → Y } where XY contain all of the schema attributes; they have left the more general case (that we study here) open.In this work, we make substantial progress in answering this question by presenting algorithms for two types of FD sets: (a) a single FD and (b) a matching constraint.
The first type generalizes the tractability of De Sa et al. [18] from a key constraint to an arbitrary FD (as long as it is the only FD in ∆).Like theirs, our algorithm employs dynamic programming, but in a more involved fashion.This is because their algorithm is based on the fact that in a key constraint X → Y , any two tuples that agree on X are necessarily conflicting.We also show that our algorithm can be generalized to additional sets of FDs.For example, it turns our that the FD set {name → address , name address → email} is tractable as well.(Note that the address attribute on the left-hand side of the second FD is not redundant, as in the ordinary semantics, since the FDs are treated as soft constraints.)In Section 4 we phrase the more general condition that this FD set satisfies.
The second type, matching constraints, refers to FD sets ∆ = {X → Y, X → Y } over a schema with the attributes A 1 , . . .,A k where The simplest example is {A → B, B → A} over the binary schema (A, B) that represents a bipartite graph, and the problem is that of finding the best "almost matching" of a bipartite graph where a penalty is paid for every lost edge and every violation of monogamy.A more involved example is {fn ln → addr , fn addr → ln} over the schema (fn, ln, addr).Our algorithm is based on a reduction to the Minimum Cost Maximum Flow (MCMF) problem [4].
Whether our algorithms cover all of tractable cases remains an open problem for future investigation.(In the Conclusions we discuss the simplest FD sets where the question is left unsolved.)We do show, however, that there is a polynomial-time approximation algorithm with an approximation factor 3, that is, a subset where the penalty is at most three times the optimum.
The rest of the paper is organized as follows.We give the formal setup and the problem definition in Section 2. We then discuss the complexity of the general problem and its relationship to past results in Section 3. We describe our algorithm for soft repairing in Sections 4 and 5 for a single FD and a matching constraint, respectively, and conclude in Section 6.For lack of space, some of the proofs are given in the Appendix.

Formal Setup
We begin with preliminary definitions and terminology that we use throughout the paper.

Databases, FDs and Repairs
A relation schema R(A 1 , . . ., A k ) consists of a relation symbol R and a set {A 1 , . . ., A k } of attributes.A database D over R is a set of facts f of the form R(c 1 , . . ., c k ), where each c i is a constant.We denote by f [A i ] the value that the fact f associates with attribute A i (i.e., f A Functional Dependency (FD) over the relation schema R(A 1 , . . ., A k ) is an expression ϕ of the form X → Y where X, Y ⊆ {A 1 , . . ., A k }.A violation of an FD in a database D is a pair {f, g} of tuples from D that agrees on the left-hand side (i.e., f When there is no risk of ambiguity, we may omit the specification of the relation schema R(A 1 , . . ., A k ) and simply assume that the involved databases and constraints are all over the same schema.
Let D be a database and let ∆ be a set of FDs

Soft Constraints
We define the concept of soft constraints (or weak constraints or weighted rules) in the standard way of "penalizing" the database for every missing fact, on the one hand, and every violation, on the other hand.This is the concept adopted in past work such as the parfactors of De Sa et al. [18], the soft keys of Jha et al. [9], and the PrDB model of Sen et al. [19].The concept can be viewed as a special case of the Markov Logic Network (MLN) [17].
Formally, let D be a database and ∆ a set of FDs.We assume that every fact f ∈ D and every FD ϕ ∈ ∆ have a nonnegative weight, hereafter denoted w f and w ϕ , respectively.(The weight of a fact is sometimes viewed as the log of a validity/existence probability [6,19].) The cost of a subset E of a database D is then defined as follows.
As for the computational model, we assume that every weight is a rational number r/q that is represented using the numerator and the denominator, namely (r, q), where each of the two is an integer represented in the standard binary manner.

Problem Definition: Soft Repairing
The problem we study in this paper, referred to as soft repairing, is the optimization problem of finding a database subset with a minimal cost.Since we consider the data complexity of the problem, we associate with each relation schema and set of FDs a separate computational problem.
Problem 1 (Soft Repairing).Let R(A 1 , . . ., A k ) be a relation schema and ∆ a set of FDs.Soft repairing ( for R(A 1 , . . ., A k ) and ∆) is the following optimization problem: Given a database D, find an optimal subset of D, that is, a subset E of D with a minimal cost(E | D).
Note that a cardinality repair is an optimal subset in the special case where the weight w ϕ of every FD ϕ is ∞ (or just higher than the cost of deleting the entire database), and the weight w f of every fact f is 1.Livshits et al. [14] studied the complexity of finding a weighted cardinality repair, which is the same as a cardinality repair but the weight w f of every fact f can be arbitrary.Hence, both types of cardinality repairs are consistent (i.e., the constraints are strictly satisfied).In contrast, an optimal subset in the general case may violate one or more of the FDs.In the next section we recall the known complexity results for cardinality and weighted cardinality repairs.We assume that the weight of the first FD is 5, and the weight of the second FD is 1 (as the same flight number can be reused for different flights).
The database E 1 of Figure 1 is a cardinality repair of D as no repair of D can be obtained by removing less then three facts.However, E 1 is not a weighted cardinality repair, since its cost is eight, while the cost of E 2 is six.The reader can easily verify that E 2 is a weighted cardinality repair of D. Finally, E 3 is not a repair of D in the traditional sense as it contains a violation of the second FD, but it is an optimal subset of D with cost(E 3 | D) = 5.

Preliminary Complexity Analysis
We consider the data complexity of the problem of computing an optimal subset.We assume that the schema and the set of FDs are fixed, and the input consists of the database.Livshits et al. [14] studied the problems of finding a cardinality repair and a weighted cardinality repair, and established a dichotomy over the space of all the sets of functional dependencies.
In particular, they introduced an algorithm that, given a set ∆ of FDs, decides whether:

Algorithm 1 Simplify
Remove trivial FDs from ∆ if ∆ is not empty then find a removable pair (X, Y ) of attribute sequences: Finding a (weighted) cardinality repair is APX-complete. 1o other possibility exists.The algorithm, which is depicted here as Algorithm 1, is a recursive procedure that attempts to simplify ∆ at each iteration by finding a removable pair (X, Y ) of attribute sets, and removing every attribute of X and Y from all the FDs in ∆ (which we denote by ∆ − XY ).Note that X and Y may be the same, and then the condition states that every FD contains X on the left hand side.If we are able to transform ∆ to an empty set of FDs by repeatedly applying simplification, then the algorithm returns true and finding an optimal consistent subset is solvable in polynomial time.Otherwise, the algorithm returns false and the problem is APX-complete.We state their result for later reference.Theorem 3. [14] Let ∆ be a set of FDs.If ∆ can be emptied via Simplify() steps, then a weighted cardinality repair can be computed in polynomial time; otherwise, finding a cardinality repair is APX-complete.
The hardness side of Theorem 3 immediately implies the hardness of the more general soft-repairing problem.Yet, the other direction (tractability generalizes) is not necessarily true.As discussed in the Introduction, if ∆ = {A → B, B → A, B → C}, then ∆, as a set of hard constraints, is classified as tractable according to Algorithm 1; however, this is not the case for soft constraints.We can generalize this example by stating that if ∆ contains a subset that is hard according to Theorem 3, then soft repairing is hard.(This does not hold when considering only hard constraints, as the example shows that there exists an easy ∆ with a hard subset.)In the following sections, we are going to discuss tractable cases of FD sets.Before that, we will show that the problem becomes tractable if one settles for an approximation.

Approximation
The following theorem shows that soft repairing admits a constant-ratio approximation, for the constant three, in polynomial time.This means that there is a polynomial-time algorithm for finding a subset with a cost of at most three times the minimum.

Theorem 4. For all FD sets, soft repairing admits a 3-approximation in polynomial time.
Proof.We reduce soft repairing to the problem of finding a minimum weighted set cover where every element belongs to 3 sets.'A simple greedy algorithm finds a 3-approximation to this problem in linear time [7].
We set the elements to be {({f, g}, δ) | f, g ∈ D, δ ∈ ∆, f and g contradict δ}.Each element ({f, g}, δ) belongs to three sets: f with weight w f , g with weight w g , and ({f, g}, δ) with weight w δ .Each minimal solution to this set cover problem can be translated to a soft repair: the selected sets that correspond to tuples are removed in the repair.Indeed, a minimal set cover of such a construction has to resolve each conflict by either paying for the removal of at least one of the tuples or paying for the violation.
In terms of formal complexity, Theorem 4 implies that the problem of soft repairing is in APX (for every set of FDs).From this, from Theorem 3 and from the discussion that follows Theorem 3, we conclude the following.
Corollary 5. Let ∆ be a set of FDs.Soft repairing for ∆ is in APX.Moreover, if any subset of ∆ cannot be emptied via Simplify() steps, then soft repairing is APX-complete for ∆.

Algorithm for a Single Functional Dependency
In this section, we consider the case of a single functional dependency, and present a polynomial-time algorithm for soft repairing.Hence, we establish the following result.
Theorem 6.In the case of a single FD, soft repairing can be solved in polynomial time.
Next, we prove Theorem 6 by presenting an algorithm.Later, we also generalize the argument and result beyond a single FD (Theorem 7).We assume that the single FD is ϕ def = X → Y and that our input database is D. We split D into blocks and subblocks, as we explain next.The blocks of D are the maximal subsets of D that agree on the X values.Denote these blocks by D 1 , . . ., D m .Note that there are no conflicts across blocks; hence, we can solve the problem separately for each block and then an optimal subset E is simply the union of optimal subsets E i of the blocks D i : The subblocks of a block D i are the maximal subsets of D i that agree on the Y values (in addition to the X values).We denote these subblocks by D i,1 , . . ., D i,qi .Note that two facts from the same subblock are consistent, while two facts from different subblocks are conflicting.
From here we continue with dynamic programming.For a number j ∈ {0, . . ., q i }, where q i is the number of subblocks of D i , and a number k ∈ {0, . . ., |D i,1 ∪ • • • ∪ D i,j |} of facts, we define the following values that we are going to compute: , the union of the first j subblocks) with precisely k facts.
(If multiple choices of F [i, j, k] exist, we select an arbitrary one.)Once we compute the F [i, q i , k], we are done since it then suffices to return the best subset over all k: find A such that in each FD, A is either an lhs or a consensus attribute 4: We will focus on the former, as the latter is obtained by straightforward bookkeeping.The key observation is that if we decide to delete t facts from D i,j , then we always prefer to delete the t facts with the minimal weight.We use this observation as follows.
For a subblock D i,j and t ∈ {0, . . ., |D i,j |}, denote by top(t, D i,j ) an arbitrary subset of D i,j with t facts of the highest weight.Hence, top(t, D i,j ) is obtained by taking a prefix of size t when sorting the tuples of D i,j from the heaviest to the lightest.Then C[i, j, k] is computed as follows.
The correctness of the above computation is due to the definition of the cost in Equation ( 1).
In particular, in the third case, we go over all options for the number t of facts taken from the subblock D i,j and choose an option with the minimum cost.This cost consists of the following components: is the cost of the best choice of k − t facts from the remaining j − 1 subblocks.t(k − t)w ϕ is the cost of the violations in which the jth subblock participates: any combination of a fact from D i,j and a fact from the other subblocks is a violation of ϕ.
f ∈Di,j \top(t,Di,j ) w f is the cost of removing every fact that is not in top(t, D i,j ) from the jth subblock.This completes the description of the algorithm.From this description, the correctness should be a straightforward conclusion.

Extension
In this section, we generalize the idea from the previous section.An attribute A is an lhs attribute of an FD X → Y if A ∈ X, and it is a consensus attribute of X → Y if X = ∅ and A ∈ Y (hence, X → Y states that all tuples should have the same A value).The simplification step of Algorithm 2 removes an attribute A if for every FD in ∆, it is either an lhs or a consensus attribute.We prove the following.Theorem 7. Let ∆ be a set of FDs.If ∆ can be emptied via L/C-Simplify() steps, then soft repairing for ∆ is solvable in polynomial time.
Note that whenever ∆ can be emptied via L/C-Simplify() steps, it can also be emptied via Simplify() steps.Indeed, if L/C-Simplify() eliminates the attribute A, then we can take: (a) X = {A} and Y = ∅ in Algorithm 1 if A is a consensus attribute of some FD, or (b) X = Y = {A} if A is an lhs attribute of every FD.This is expected due to Theorems 3 and 7, and the observation of Section 3 that soft-repairing is hard whenever computing a cardinality repair is hard.Next, consider the FD set ∆ 2 consisting of the following FDs: Flight → Airline and Flight Date → Destination.This FD set is logically equivalent to ∆ 1 ; hence, they both entail the exact same cardinality repairs.However, these sets are no longer equivalent when considering soft repairing.In particular, two facts that agree on the values of the Flight and Date attributes, but disagree on the values of the Airline and Destination attributes, violate only one FD in ∆ 1 but two FDs in ∆ 2 , which affects the cost of keeping these two tuples in the database.In fact, the FD set ∆ 2 cannot be emptied via L/C-Simplify() steps, as after removing the Flight attribute, no other attribute is either an lhs or a consensus attribute of the remaining FDs.The complexity of soft repairing for ∆ 2 remains an open problem.
Next, we prove Theorem 7 by presenting a polynomial-time algorithm for soft repairing in the case where ∆ can be emptied via L/C-Simplify() steps.Our algorithm generalizes the idea of the algorithm for a single FD, and we again use dynamic programming.
The main observation is as follows.Let A be an attribute chosen by L/C-Simplify(), and let D 1 , . . ., D m be the maximal subsets of D that agree on the value of A, which we refer to as blocks (w.r.t.A).Two facts from different blocks violate all of the FDs wherein A is a consensus attribute and none of the FDs wherein A is an lhs attribute.Therefore, to compute the cost of a soft repair, each pair of facts from different blocks is charged with the violation of all FDs wherein A is a consensus attribute.Then, we can remove A from all FDs and continue the computation separately for each block.Now, let ∆ be an FD set that can be emptied via L/C-Simplify() steps, and let A 1 , . . ., A n be the attributes in the order of such an elimination process.For each ∈ {1, . . ., n + 1}, we denote by ∆ the FD set in line 2 of the th iteration of this execution (after removing the trivial FDs).Thus, ∆ 1 contains every non-trivial FD of ∆, and ∆ n+1 is empty.We also denote by w the total weight of the FDs in ∆ of which A is a consensus attribute (if there are no such FDs, then w = 0).
In the algorithm for a single FD, the recursion steps were with respect to the block D i (which determines the value of X), and so the value of i was a parameter.Here, we need to maintain the assignment τ to all previously handled attributes, and we use τ and as parameters.Given 1 ≤ ≤ n + 1, if τ is an assignment to the attributes A 1 , . . ., A −1 , then D τ denotes the database σ τ D (i.e., the database that contains all the tuples that agree with τ on the values of the attributes A 1 , . . ., A −1 ).We denote by D τ 1 , . . ., D τ q τ the blocks of D τ w.r.t.A .Moreover, we denote by τ ∧ (A = j) the assignment to the attributes A 1 , . . ., A that agrees with block D τ j on the value assigned to A and agrees with τ on all other values.We denote by F [ , τ, j, k] an optimal subset of D τ 1 ∪ • • • ∪ D τ j of size k w.r.t.∆ .We also denote by C[ , τ, j, k] the cost of F [ , τ, j, k].According to Equation (1), our goal is to compute We again focus on the computation of C[ , τ, j, k] that can be done as follows.
The first line (where = n + 1) refers to the case where ∆ is empty.Since there are no FDs that need to be taken into account, the optimal subset of D τ of size k consists of the k facts of the highest weight.In the fourth case, we go over all options for the number t of facts taken from the block D τ j and choose an option with the minimum cost.This cost consists of the following components: is the cost of the best choice of k − t facts from the remaining j − 1 blocks.t(k −t)w is the cost of the violations in which the jth block participates: any combination of a fact from D τ j and a fact from the other blocks , t] is the cost of the further repairing needed following the elimination of A (i.e., repairing with respect to ∆ +1 ) applied to the current block (the t facts from D τ j ) .
The given recursion can be computed in polynomial time via dynamic programming; thus, this proves Theorem 7.

Algorithm for Matching Constraints
Next, we consider the case of a "matching" constraint, where the FD set ∆ states two keys that cover all of the attributes.(We give the precise definition in Section 5.1.)We present a polynomial-time algorithm for soft repairing in this case.For presentation sake, we first describe the algorithm for the special case where the schema is R(A, B) and ∆ def = {A → B, B → A}.Later in the section, we generalize it to the case of two keys.So, we begin by proving the following lemma.

Lemma 9. Soft repairing is solvable in polynomial time for R(A, B) and
In the remainder of this section, we assume the input D over R(A, B).We begin with an observation.For E ⊆ D it holds that:

Since the value
f ∈D w f does not depend on the choice of E, minimizing the value We use the following notation: To solve the problem, we construct a reduction to the Minimum Cost Maximum Flow (MCMF) problem.The input to MCMF is a flow network N , that is, a directed graph (V, E) with a source node s having no incoming edges and a sink node t having no outgoing edges.Each edge e ∈ E is associated with a capacity c e and a cost c(e).A flow f of N is a function f : E → R such that 0 ≤ f (e) ≤ c e for every e ∈ E, and moreover, for every node v ∈ V \ {s, t} it holds that e∈Iv f (e) = e∈Ov f (e) where I v and O v are the sets of incoming and outgoing edges of v, respectively.A maximum flow is a flow f that maximizes the value (s,v)∈E f (s, v), and a minimum cost maximum flow is a maximum flow f with a minimal cost, where the cost of a flow is defined by e∈E f (e) • c(e).We say that f is integral if all values f (e) are integers.It is known that, whenever the capacities are integral (i.e., natural numbers, as will be in our case), an integral minimum cost maximum flow exists and, moreover, can be found in polynomial time [1,Chapter 9].
From D we construct n instances N 1 , . . ., N n of the MCMF problem, where n is the number of facts in D, in the following way.
The network N k constructed from the database of Figure 2a.The capacity of all edges is 1, except for the edge (s, s ) that has capacity k.
database of Figure 2a w.r.t.∆ = {A → B, B → A}, which contains a vertex for each fact in the database and an edge between two vertices if the corresponding facts jointly violate an FD of ∆.The blue edges in the conflict graph are violations of the FD A → B and the red edges are violations of the FD B → A.
For each k ∈ {1, . . ., n} we construct the network N k that consists of the set {s, s , t} ∪ V ∪ A ∪ B ∪ U of nodes where: N k contains the following edges: The capacity of the edge (s, s ) is k and the capacity of the other edges is 1.The intuition for the construction is as follows.A network with edges of the form (v a , u b ) that are connected to a source on one side and a target on the other corresponds to a matching, which in turn corresponds to a traditional repair.To allow violations of A → B, we add the vertices v i a .The cost of a violation of this FD is defined by the cost of the edges (v i a , v a ).In particular, if we keep k facts of the form R(a, •) for some a ∈ D.A we pay k i=1 (k − 1)w ϕ1 for violations of ϕ 1 .We include the vertices v i b to similarly allow violations of B → A. The discarding of facts is discouraged by offering gain for the edges (v a , u b ).Finally, to prevent the case where the flow always fills the entire network (which corresponds to taking all facts and paying for all violations), we introduce the edge (s, s ) which limits the capacity of the network, and enables us to find the minimum cost flow of a given size k.We will show that for every k, the cost of the solution to the MCMF problem on N k will be the cost of the "cheapest" subinstance of D of size k.Hence, the solution to our problem is the cost of the minimal solution among all the instances N 1 , . . ., N n .
Given an integral flow f in N k , the repair D[f ] induced by f , is the set of facts R(a, b) corresponding to edges of the form (v a , u b ) such that f (v a , u b ) = 1.Moreover, given a subinstance E of D of size k, we denote by f E the integral flow in N k defined as follows.
The reader can easily verify that f E is indeed an integral flow in N k .Clearly, the value of the flow is k.
We have the following lemmas.The first is proved in the Appendix and the second follows straightforwardly from the construction of N k and the definition of f E .

Lemma 10. Every integral solution f to MCMF on
Now, let E be an optimal subset of D w.r.t.∆ and assume that |E| = k.Let f * be a solution with the minimum cost among all the solutions to MCMF on N 1 . . ., N n .Lemma 11 implies that there is an integral flow f E in N k such that cost(f E ) = w D (E).Hence, we have that cost(f * ) ≤ w D (E).By applying Lemma 10 on f * , there is another subinstance E of D such that w D (E ) = cost(f * ).Since E is an optimal subset, we have that w D (E) ≤ w D (E ).Overall, we have that cost(f * ) ≤ w D (E) ≤ w D (E ) = cost(f * ), and we conclude that cost(f * ) = w D (E).Therefore, by taking the solution with the lowest cost among all solutions to MCMF on N 1 , . . ., N n , we indeed find a solution to our problem, and that concludes our proof of Lemma 9.
Example 12. Consider again the database of Figure 2a.Assume that: Since the cost of a violation is "too high" in this case (i.e., it is always cheaper to delete a fact involved in a violation than to keep the violation), an optimal subset in this case is, in fact, an optimal repair in the traditional sense (that is, when the constraints are assumed to be hard constraints).One possible optimal repair in this case is {f 2 , f 4 , f 6 }.The flow corresponding to this repair in the network N 3 is illustrated in Figure 4a.Now, assume that: In this case, the cost of deleting a fact is "too high", since each fact is involved in at most two violations, and the cost of keeping the violation is lower than the cost of removing facts involved in the violation.Therefore, the database itself is an optimal subset, and the corresponding flow in the network N 6 is illustrated in Figure 4b.
Figure 4 The flow in the network N k corresponding to an optimal subset of the database of Figure 2a for different weights.
As another example, assume that: Here an optimal subset consists of the facts in {f 1 , f 2 , f 5 , f 6 }, and the corresponding flow in the network N 4 is illustrated in Figure 4c.If we modify the weight of ϕ 2 and define w ϕ2 = 4, while keeping the rest of the weight intact, it is now cheaper to delete the fact f 2 rather than keep the violations it is involved in with f 1 and f 5 ; hence, an optimal subset in this case is {f 1 , f 5 , f 6 }, and the corresponding flow in the network N 3 is illustrated in Figure 4d.
Note that the FD set {A → B} over R(A, B) is in fact a special case of the result of Theorem 14, as we can compute an optimal subset for this FD set using the algorithm described above by defining w B→A = 0.However, this algorithm works only for the case where the single FD is a key and fails to compute the correct solution when the schema contains attributes that do not appear in the FD.The algorithm described in the proof of Theorem 6, on the other hand, can handle this case and does not assume anything about the underlying schema.

Generalization into Matching Constraints
By a "matching constraint" we refer to the case of Example 13.Consider the database of our running example (Figure 1), and the following FDs: Flight Airline Date → Origin Destination Airplane, Origin Destination Airplane Date → Flight Airline.The reader can easily verify that these two FDs form a matching constraint.On the other hand, consider the set consisting of the following two FDs: Flight Date → Airline Origin Destination Airplane, Origin Destination Airplane Date → Flight Airline.Here, we do not have a matching constraint since while it holds that X ∪ Y = X ∪ Y = {Flight, Airline, Date, Origin, Destination, Airplane}, the set X ∪ X misses the Airline attribute.
The generalization of Lemma 9 from ∆ = {A → B, B → A} over R(A, B) to the general case of a matching constraint is fairly straightforward.Given an input D for soft repairing over R and ∆, we construct an input D over R and ∆ by defining unique values a(π X ( f )) and b(π X ( f )) for the projections π X ( f ) and π X ( f ) over X and X , respectively, of every fact f of D. Then, the database D is simply the set of all the pairs a(π X f ) and b(π X f ) for all facts f of D: So, in order to solve soft repairing for D, we solve it for D and transform every fact f of D into the corresponding fact f of D. We get the following result.The proof (given in the Appendix) is by showing the correctness of the reduction.Theorem 14. Soft repairing is solvable in polynomial time whenever ∆ is a pair of FDs that constitutes a matching constraint.

Conclusions and Open Problems
We studied the complexity of soft repairing for functional dependencies, where the goal is to find an optimal subset under penalties of deletion and constraint violation.The problem is harder than that computing a cardinality repair, and we have developed two new, nontrivial algorithms solving natural special cases.A full classification of the FD sets remains an open challenge for future research; specifically, the question is what fragment of the positive side of the dichotomy of Livshits et al. [14] remains positive when softness is allowed.We have also shown that the problem becomes tractable if we settle for a 3-approximation.The problem is also open for classes of constraints that are more general than FDs, including equality-generating dependencies (EGDs), denial constraints, and inclusion dependencies.Yet, the problem for these types of dependencies is open already in the case of cardinality repairs, with the exception of some cases of EGDs [13].Another clear direction is that of update repairs where we are allowed to change cell values instead of (or in addition to) deleting tuples and where complexity results are known for hard constraints [10,14].

Details for Section 5
In this section, we provide the missing proofs of Section 5.For convenience, we give the results again here.Proof.First, note that it cannot be the case that f (s , v j a ) = 0 while f (s , v i a ) = 1 for some j < i and i ∈ {1, . . ., # D.A (a)}.Otherwise, we can construct a different integral flow f with f (s , v .From the construction of D, we have that π X f = π X ĝ, while π X f = π X ĝ.Thus, there is an attribute A i ∈ X such that f [A i ] = ĝ[A i ] and since A i ∈ X and X ∪ Y = {A 1 , . . ., A k }, it holds that A i ∈ Y .We conclude that { f , ĝ} |= (X → Y ).We can similarly prove that if {f, g} |= (B → A), then { f , ĝ} |= (X → Y ).Finally, because w A→B = w X→Y and w B→A = w X →Y it holds that ϕ∈∆ w ϕ |vio(E, ϕ)| = φ∈ ∆ w φ|vio( Ê, φ)|.
For the other direction, let Ê be a subset of D, and let E be the subset of D that includes the fact f for every f ∈ Ê.It is again straightforward that f ∈(D\E)w f = f ∈( D\ Ê)w f .Now, let f , ĝ ∈ Ê such that { f , ĝ} |= (X → Y ).We have that f [A i ] = ĝ[A i ] for every A i ∈ X; thus, π X f = π X ĝ and from the construction of D, it holds that f [A] = g [A].On the other hand, the fact that f [A i ] = ĝ[A i ] for some A i ∈ Y together with the fact that X ∪ Y = X ∪ X = {A 1 , . . ., A k } imply that π X f = π X ĝ and f [B] = g [B].Hence, {f, g} |= (A → B).We can similarly prove that if { f , ĝ} |= (X → Y ), then {f, g} |= (B → A), which again implies that ϕ∈∆ w ϕ |vio(E, ϕ)| = φ∈ ∆ w φ|vio( Ê, φ)|, and the concludes our proof.
We denote by vio(D, ϕ) the set of all the violations of the FD ϕ in D. We say that D satisfies ϕ, denoted D |= ϕ, if it has no violations (i.e., vio(D, ϕ) is empty).The database D satisfies a set ∆ of FDs, denoted by D |= ∆, if D satisfies every FD in ∆; otherwise, D violates ∆ (denoted D |= ∆).

Example 2 .
Our running example is based on the database of Figure 1 over the relation schema Flights(Flight, Airline, Date, Origin, Destination, Airplane) that contains information about domestic flights in the United States.The weight of each tuple appears on the rightmost column.The FD set ∆ consists of the following FDs: Flight → Airline: a flight is associated with a single airline.Flight Airline Date → Destination: a flight on a certain date has a single destination.

Example 8 .
Consider the database and the FD set of our running example (Example 2).This FD set, which we denote here by ∆ 1 , can be emptied via L/C-Simplify() steps, by selecting attributes in the following order: {Flight → Airline , Flight Airline Date → Destination} Flight :{∅ → Airline , Airline Date → Destination} Airline :{Date → Destination} Date :{∅ → Destination} Destination :{} Hence, Theorem 7 implies that soft repairing can be solved in polynomial time for ∆ 1 .

Figure 2 A
Figure 2 A database over R(A, B) and its conflict graph w.r.t.{A → B, B → A}.

2 • 2 •
First, we denote the FD A → B by ϕ 1 and the FD B → A by ϕ 2 .We also denote by D.A the set of values occurring in attribute A in D (that is, D.A = {a | ∃f ∈ D(f [A] = a)}).We do the same for attribute B and denote by D.B the set of values that occur in attribute B in D. For each value a ∈ D.A we denote by # D.A (a) the number of appearances of the value a in attribute A (i.e., the number of facts f ∈ D such that f [A] = a).Similarly, we denote by # D.B (b) the number of appearances of the value b in attribute B in D. Observe that vio(D, ϕ 1 ) = 1 a∈D.A [# D.A (a) • (# D.A (a) − 1)] since every fact of the form R(a, b) violates ϕ 1 with every fact R(a, c) where b = c.Similarly, it holds that vio(D, ϕ 2 ) = 1 b∈D.B [# D.B (b) • (# D.B (b) − 1)] Next, we describe the construction of the network N k .Our construction for the database of Figure 2a is illustrated in Figure 3.Note that Figure 2b depicts the conflict graph of the XX:12 Database Repairing with Soft Functional Dependencies

Lemma 10 .
Every integral solution f to MCMF on N k satisfies cost(f ) = w D (f [D]).

2 •
j a ) = f (v j a , v a ) = 1, f (s , v i a ) = f (v ia , v a ) = 0, and f (e) = f (e) for every other edge e.It holds that cost(f) = cost(f ) − c(v i a , v a ) + c(v j a , v a ), and since c(v i a , v a ) > c(v j a , v a ) we will have that cost(f ) < cost(f ) in contradiction to the fact that f is a solution to MCMF on N k .Therefore, for every a ∈ D.A, if the flow entering the node v a is , thenf (s , v i a ) = f (v i a , v a ) = 1 if i ≤ and f (s , v i a ) = f (v i a , v a ) = 0 otherwise.Thus, the total cost of the edges of the form (v i a , v a ) is i=1 [(i − 1)w ϕ1 ] = 1 2 ( − 1)w ϕ1 .By the definition of f [D], there are # f [D].A (a) edges of the form (v a , u b ) for which f (v a , u b ) = 1.By the definition of a flow, this is also the flow entering the node v a , and we have that = # f [D].A (a).We conclude that the total cost of the flow on edges of the form(v i a , v a ) is a∈f [D].A 1 # f [D].A (a) • (# f [D].A (a) − 1) • w ϕ1 = vio(f [D],ϕ1 ) • w ϕ1 .The same argument shows that the total cost of the flow on edges of the form (u b , u i b ) is vio(f [D], ϕ 2 ) • w ϕ2 .Finally, the total cost of the edges of the form (v a , u b ) is g∈f [D] (−w g ) by the definition of f [D] and the construction of the network.We conclude that: + vio(f [D], ϕ 1 ) • w ϕ1 + vio(f [D], ϕ 2 ) • w ϕ2 and cost(f ) = w D (f [D]) by definition.Theorem 14. Soft repairing is solvable in polynomial time whenever ∆ is a pair of FDs that constitutes a matching constraint.Proof.We prove that D has a subset E with cost(E | D) = k if and only if D has a subset Ê with cost( Ê | D) = k.Let E be a subset of D with cost k.Let Ê be a subset of D that includes the fact f for every f ∈ E. By definition, we have that f ∈(D\E)w f = f ∈( D\ Ê)w f ; hence, it is left to show that ϕ∈∆ w ϕ |vio(E, ϕ)| = φ∈ ∆ w φ|vio( Ê, φ)|.Let f, g ∈ E such that {f, g} |= (A → B).Hence, it holds that f [A] = g[A] while f [B] = g[B]

such XX:4 Database Repairing with Soft Functional Dependencies that
. A repair (of D w.r.t.∆) is a maximal consistent subset E; that is, E ⊆ D and E |= ∆, and moreover, E |= ∆ for every E E E ⊆ D. Note that the number of repairs can be exponential in the number of facts of D. A cardinality repair is a repair E of a maximal cardinality (i.e., |E| ≥ |E | for every repair E ).

k] XX:8 Database Repairing with Soft Functional Dependencies Algorithm 2
L/C-Simplify() 1: remove trivial FDs from ∆ 2: if ∆ is not empty then Several directions are left open for future work.A direct open problem is to characterize the class of tractable FDs via a full dichotomy.The simplest sets of FDs where the complexity of soft repairing is open are the following: {A → B, A → C}.Note that this problem is different from {A → BC} that consists of a single FD.{A → B, B → A} in the case where the schema has attributes different from A and B,