 Ευχαριστώ για τη δεύτερη εξοδογή. Βλέπουμε να σας σημαίνουμε ποιο ένιωσο που βλέπουμε τελευταία. Προσπαθούντας πιο πιο ποιο που αντιμετωπίζουμε, είναι η δεύτερη αδυναμία, και οι δεύτεροι αδυναμίες έχουν την ίδια εξοδογή. Η δεύτερη αδυναμία είναι η λαγκότητα που βλέπεις με μεταξύ με πολλές δεύτερες σημερινές, και τελικά να χρησιμοποιήσεις αυτά τα δεύτερη εξοδογή, γυναίκες, διαφορά, κατησιά, προσταγή, προστασία και συλλαγία. Δεν βλέπουμε ότι αυτό δίνει μια στιγμή λάγκο, σε έναν στιγμή που μπορείς να εξηγήσεις κάποιες εξαιρετικές εξαιρετικές, όπως η διεξιότητα, όπως η κουωσία. Και τότε, παρακολουθούμε αυτή η λάγκο για τη διεξιότητα, που είναι ένας κατασχέδι, όπως η διεξιότητα, όχι η διεξιότητα, όχι την πρόσφαση, δεν είναι έξιπη. Και then the first result that we saw was that algebra and calculus have the same expressive power appropriately understood. And appropriately understood means that you have to look at the domain independent formulas of first order logic. And then it is true that relation algebra and the domain independent fragment of relation calculus have identical expressive power. And I also mentioned that testing whether a given first order formula is domain independent is an undecidable problem, but we have an effective syntax that captures domain independent property. Then we looked at these three fundamental decision problems for a query language and in particular for relation calculus. The three problems are the equivalence problem, the containment problem, and the query evaluation problem. And in the case of relation calculus both equivalence and containment turn out to be undecidable. This is a very easy corollary to the Trachten-Bröst theorem, to the finite undecidability of finite validities. And then we also mentioned that the query evaluation problem, which is just the model checking problem, is p-space complete. In fact, I didn't have to do any work for this. It was already covered in the lectures in the morning. So here these are these problems again by way of reminding you. The query equivalence problem contains as a special case logical equivalence, and that's the special case when the queries are Boolean. So in general you have two queries of the same arity, but this is the case that on every database, and for us database means always finite databases, this is the case that they give you the same answer. In particular, in the case of Boolean queries it means are they true on precisely the same databases. Query containment means that the result of evaluating the query on one database containing the other and you want this to happen on every database. Then we took a closer look at the query evaluation problem, which again was covered in the lectures on yesterday morning, and the query evaluation problem has as input two objects, the query and the database. Then you get two families of problems by fixing one of the two inputs. So if you fix the query you talk about data complexity, you have one decision problem for every query, and there the complexity drops to log space. Query complexity or expression complexity is where you fix the database and you let the query move around as inputs and then it can be p-space complete. So for coming from a database point of view, this really tells you that the problems that you are interested have very high complexity and in fact can even be undecidable. The query equivalence is something that you would care about because it's what you would like to do. Someone gives you two queries and you want to test whether or not they do the same thing. So this motivated the question of are there fragments of relational calculus, fragments of first-order logic for which containment and equivalence and evaluation are easier than the full case. And in fact, there is a very nice language. It's the language of conjunctive queries and you are all familiar with this language. I'll give you different ways to think about conjunctive queries and the advantage and the interest in focusing on this class of queries is that they capture the most frequently asked queries against real database systems. So this is the motivation for looking at this class of queries. Formally speaking, a conjunctive query is a query definable by a formula of first-order logic that has this very simple syntax. It's a bunch of existential quantifiers applied to a conjunction of atomic formulas. Atomic formulas, I mean here, literally positive formulas, conjunction of atoms of this form. Some of these variables are quantified out, some are free, and the query returns on every database the set of all k-taples that satisfy this expression. By the way, this is a domain-independent calculus expression, so I don't have to worry about the universe. It's just active domain semantics works perfectly well here. But there is another way to think of these queries. These are precisely the queries that are definable in relational algebra. I remember the five operations as projections of selections of Cartesian product where the selection is very, very simple. The condition is a conjunction of equalities. Where does the conjunction of equalities show here? Well, basically, in some atoms, the atoms may share the same variable, right? So that corresponds to the equality between the variables. And if you want to go to SQL, is again a very natural class of expressions you can write in SQL. This is select from where, where in the where clause, remember the where clause captures the selection condition, is a conjunction of equalities. So it's a very natural fragment to consider. There is another way to write them, which would be of interest to us when we move to data log in the second half of this presentation. This is, we can write them as rules in logic programming. So in the logic programming rule, a logic programming rule is something like this, something like this, where the conjunctions are replaced by commas. Quantification, extensive quantification has disappeared. It is implicitly denoted because you have some variables that occur on the right-hand side but not on the left-hand side. These are assumed to be existentially quantified. Typically, when we write a query like this, the right-hand side is called the body of the query and the left-hand side is called the head of the query. And as I said, the missing variables are extensively quantified and commas stands for conjunction. So let's take this syntax and look at some examples. Path of length 2, all the pairs connected by a path of length 2 in calculus, you will write it like this. There exists a z, e, x, z, and d, z, y. As an algebra expression, you would write it like this. As a rule, you will write it like this. The existential quantification is oppressed. You infer it because z is the variable that occurs here but not on the head. And similarly, a cycle of length 3. It's a Boolean query that says there is a cycle of length 3. You would write it like this as a conjunctive query or like this as a rule. It's perfectly fine to have heads with no variables. This simply means that all the variables on the body are extensively quantified. So this is just different syntaxes for the same type of object. Let me point out that every relational join that we saw yesterday is a conjunctive query and in fact it's a conjunctive query in which we don't have any variables extensively quantified. All the variables occurring on the right occur on the left. So it's a quantifier-free conjunctive query, if you will. And that's how you would write it in sqrt. Conjunctive queries, if you talk to the database practitioners, they call them SPJ queries, select project join. Although they select, you have to understand that we're only talking about conjunctions of equality. So these are known as SPJ queries. So now let's look at our fundamental problems for conjunctive queries. And for the time being I'll suppress the equivalence problem. I'm only going to look at conjunctive query evaluation and conjunctive query containment. So this problem simply means given a conjunctive query in the database find the result of evaluating the query on the database. Containment is true that on every instance i, q1i is contained in q2o5, in the case of Boolean queries, we have implication, logical implication, between two existential conjunctive, existential positive sentences without any disjunctions at all. So we have logical implication. Remember that conjunctive query evaluation for the full case, the full calculus or algebra was p-space complete, query containment is undecidable. We gained anything by going to this small fragment and the answer is yes. There is this very nice result which I'm going to give you a complete proof of this. It's actually not a difficult result. It's much, much easier than anything you've seen in the lectures of my colleagues here. But very important result by Sandra and Merlin from 1977 that in some sense conjunctive query equivalence and conjunctive query containment are the same problem which is very different from the full algebra. One was the side-up, the other was undecidable. Here they are the same problem and they are both NP-complete. And of course the question is why is the common link? By the way, Sandra here is the same Sandra that we saw his name mentioned in... This is a shock Sandra, this thing with graduate of IIT Kanpur. We saw his name yesterday morning with the alternation. In Ram's presentation we saw it in Anousha stock. This is Sandra Harrell. Sandra Harrell paper with an open problem for logic for p-time. So he also had this paper in stock 1977 with Merlin. He was at IBM at the time. Today he's at Microsoft. So what is the common link? The common link is the so-called homomorphism problem. So I'm going to introduce this homomorphism problem and give you just a little... Just scratch the surface of this beautiful problem. Let me remind you what the homomorphism is. You can think of it as a relaxation of the concept of isomorphism between two relational structures. So you have two databases or two relational structures. A homomorphism in our case of databases is a function from the active domain of the one to the active domain of the other that preserves membership in relations from left to right. Meaning that if you have a tuple that belongs to some relation of i then the image of the tuple under this homomorphism is a tuple that belongs to the corresponding relation in j. So it relaxes isomorphism in two ways. It does not have to be 1, 1 and 2. And also this preservation is only from left to right. It's not different only. And as an example which I will use to illustrate some of the concepts and the techniques here and the results is that the graph is three colorable if and only if you have a homomorphism from the graph to K3 where K3 is the triangle. You click with the three elements. And in fact this is a very strong if and only if in the sense that the three colorings of a graph are precisely the homomorphisms that you have from the graph to the triangle. So three colorability is a special case of what we will call in a minute the homomorphism problem. All right. So here is the homomorphism problem. Given two database instances is there a homomorphism from one to the other and we will use this notation i arrow j to denote that such a homomorphism from i to j exists. And one thing we can immediately identify is the exact complexity of the homomorphism problem. It is NP-complete. It certainly is in NP because we guess a function and verify that it preserves membership from left to right but it's also NP-complete. I just showed you why it's NP-complete. But it's NP-complete even if we fix the right-hand side. For a fixed j g is three colorables and only there is a homomorphism from g to k3. What is two colorability? Two colorability is the existence of a homomorphism to k2. Just the end. And k colorability is the existence of a homomorphism to the clique with k elements. So we know the homomorphism problem is NP-complete. Here is an exercise that is tying to something that Anouzo was saying yesterday when he asked the question I think is three set NP-complete under a four reduction. And of course you have to think how you're going to code satisfiability as a class of finite structures. Well, if you do that then as a follow-up exercise is to show that three satisfiability is a special case of the homomorphism problem. The only difficulty is to come up with a writing coding of three set. All right. So the homomorphism problem is a fundamental algorithmic problem. I just showed you that colorability is a special case. Satisfiability is a special case. Planning and many other problems in AI can be viewed as special cases of the homomorphism problem. There is a very important paper by Federer and Vardi back in 1993 in which they argued that every problem in constraint satisfaction which is a large class, a large algorithm in paradigm in artificial intelligence can be viewed as a special case of the homomorphism problem. In fact, I think Mose Vardi tomorrow in his invited talk at the conference will talk about aspects to homomorphism. So we know now the homomorphism problem. So now let's proceed and explain what is behind the Sandra Merlin theorem. This rather surprising situation we remember. Evaluation and containment very different problems for full first order logic. You go to this fragment. They are the same problem but in fact is that they are equivalent to the homomorphism problem but I need some a little bit of machinery to show you this connection and for this we need to bring into the picture canonical conjunctive queries and canonical database instances. And this is very simple. What I hope to do in the next 5 minutes is to make you able to do the transition every time you see a conjunctive query you also see a database and every time you see a database you also see a conjunctive query. So it's like a magic picture. You look at the database or it's a conjunctive query or it's a database. So let's see what's going on. It's very, very simple. So let's start with a database. So we have a database. It's going to be a Boolean conjunctive query which we are going to call the canonical conjunctive query of the database. So what is this? Every element of the active domain every element of the active domain becomes a variable and then the facts of the database these are simply the tuples that belong to some relation become the atomic formulas the conjuncts of the conjunctive query. So concretely concretely if your database had just these three pairs in a binary relation e, eab, ebc, eca then the canonical conjunctive query would say I wrote it as a rule would say exz, ezy, eyx which really means that there exists x, there exists y, there exists z so that we have exz and easy y and eyx So we look at the database we write down the query logicians know this it's the positive atomic diagram of a structure that's all there is to it but now written as a formula in this little fragment of first order logic So from a database we can go to a conjunctive query here are more examples this is a database this is a database which is basically the complete graph with three nodes and the canonical conjunctive query really says there are three nodes and for every two different variables we have all the possible connections right? So we go from the canonical conjunctive query from the database to the canonical conjunctive query we can do the reverse game we can start with a query and view it as a database conjunctive query namely if we have a query like this we simply view the variables as elements of the active domain and we populate the database with the conjuncts of the query So that's what I meant before Whenever you see a database to think of a conjunctive query whenever you see a conjunctive query to think of a database Now I wasn't planning to say this but I was inspired by Anous's presentation today Anous spent some time describing very nicely the three-width of a structure Well there is a connection between three-width of a structure and the canonical conjunctive queries This goes back to some work that Moshe Vardy and I did and then we had a paper with Victor Dalmau So this is from a paper with Victor Dalmau myself and Vardy back in 2002 where the following thing comes out that a database or a relational structure has three-width less than or equal than K If and only if it's a canonical conjunctive query which we call here IQ can be written with at most K-variables So if you don't like the compositions and if you don't like the Cop and Robert's game you come from logic this is if you will the logician's description of the three-width Now what I mean can be written with at most K-variables I wrote the conjunctive queries in prenext normal form but you can think that you can use fewer variables by using nestings, reusing some variables So all you allow in the syntax is atomic formulas you allow atomic formulas conjunctions and the existential quantification but you are allowed to nest them and reuse variables So as long as you can write this or this formula is at most K that's exactly what it means to have three-width K So there is this tight connection between three-width and the expressibility of the canonical conjunctive queries this way but that's an aside, it's not relevant to I just wanted to mention to connect to what Anous mentioned today So we have canonical queries and canonical instances and here is another example If we start with this conjunctive query then we get the corresponding canonical instance and there is a very very basic fact which should be obvious and the obvious fact is that every database if you have a canonical query then the canonical instance satisfies the query right? I mean that's pretty much by English or as then as Colt said one is a self-proving kind of theorem All right So now I want to, I'm almost ready to give you the proof of the general many theorem and this uses a very simple lemma when I teach this to my students I call it the magic lemma just to get them excited but there is nothing really magic about this lemma other than trying to catch your attention So the magic lemma save it here says that the following are equivalent the following are equivalent for some database J for some conjunctive query Q and some instance J one is that J satisfies the query and two that there is a homomorphism H the canonical instance of the query to J and this is really nothing else but the semantics of first order logic when you come to this simple fragment of conjunctive query Why is that? Well let me argue informally here because suppose that J satisfies the query the query is of this form there exists x1, exists xm3 right? Therefore the semantics of first order logic it means there are elements A1, Am in the domain such that when you plug them in the formula the formula becomes true but this really means that the function that assigns to every variable value AI is a homomorphism from IQ to J just follow the definition and vice versa these are the equations from IQ to J then these values these are values IQ is the instance you get from the query so the active domain are the variables so now we have ways to instantiate the variables and make the query true so these are we can use the values of the homomorphism to give values as the interpretation of the existential quantifier so this is not a diploma but first order logic and now I'm ready with this to show you the proof of the tsandra-melning theorem in fact the tsandra-melning theorem you can state it into two different equivalent forms one is dual of the other so here is the tsandra-melning theorem it says that I'll state it first for Boolean conjunctive queries and then we will consider queries with positive variety it says that the following are equivalent for conjunctive queries one is contained in the other two there is a homomorphism h from IQ prime to IQ in other words the canonical instance of the bigger one can be homomorphically mapped into the canonical instance of the smaller one the cross, the new paradoxical nothing paradoxical actually and the third is that IQ satisfies Q prime let me write it here so this is tsandra-melning 1977 and it says if I have Q and Q prime but that which are conjunctive queries then the following are equivalent one Q is contained in Q prime two there is a homomorphism h from there exist some homomorphism h from IQ prime to IQ and three IQ the canonical instance of Q satisfies Q prime the dual form is where you start with the instances and you ask yourself is it the case that there is a homomorphism h from IQ prime in other words we get a yes answer to the homomorphism question this is equivalent to IQ satisfying the canonical conjunctive query of i and it's equivalent to QI prime contained in QI now this is interesting right because you take this homomorphism problem but I thought it was very rich you can do satisfiability colorability planning in fact all of constraints satisfaction and the database theories become very happy it's a database problem conjunctive query containment or conjunctive query evaluation this is interesting about this theorem before getting into the proof if you look at the first statement I give you two queries and I ask you is it the case that Q is contained in Q prime this requires what kind of statement is this for all databases right this is a big universal quantifier this is for all i but look at this statement the existential statement there is a homomorphism sounds a little bit like the completeness theorem what is true or not is exactly what has a proof that's the essence of the completeness theorem we turn a universal quantifier into an existential quantifier so this has a little bit of this flavor well that's why I'm getting NP complete it's exactly right but on the other hand this is also at the logical level this is also second order we are quantifying over all databases the point is that this is an infinite search while this is a finite space so we are turning in fact an infinite search to a finite search notice also that this is interesting in its own right because to verify this statement Q contained in Q prime this means that for every database you have to test that Q of i is contained in Q prime of i this tells you it's enough right so again we reduce a complicated test to something simple all right so now we are ready to prove the homomorphism theorem and we are going to use the magic lemma so let me ask you how many times do you think we are going to use the magic lemma in this proof it's 1 implies 2 2 implies 3, 3 implies 1 so how many times should we use it 1 any other guess 3, 5 all right so let's see why so let's prove 1 implies 2 so assume that Q is contained in Q prime this means that on every database you have the containment in particular look we had this trivial fact that the canonical database of Q satisfies Q right therefore the canonical database of Q satisfies Q prime ah by the magic lemma it means there is a homomorphism from iQ prime to iQ I'll be using the magic lemma for different substitutions for j and q of course right so 2 implies 3 is again an application of the magic lemma in the other direction from iQ prime to iQ by the magic lemma ok 2 implies 1 it follows that iQ satisfies Q prime so we've used it twice so let's now prove that 3 implies 1 so assume that iQ satisfies Q prime so by the magic lemma there is a homomorphism h from iQ prime to iQ that's what we have now we have to prove that Q is contained into prime now there is no other way but start with some j that satisfies Q and we have to prove that j satisfies Q prime so start with a j that satisfies Q well by the magic lemma that's the fourth application there is a homomorphism h prime from iQ to j but now look we have a homomorphism from iQ prime to iQ and the homomorphism from iQ to j there is a nice thing about homomorphism they compose that's obvious from the definition so the composition gives us a homomorphism from iQ prime to j so by the magic lemma that's the fifth application we get that j satisfies Q prime so basically this was really all that was in the tundra manian theorem 7 you could get a stock paper but not today the proof looked more complicated but it's nice we can fit it in one slide after we have built this machine this is a very simple result but extremely useful as you will see we will see many applications of this as we go along and I hope it's clear any questions about this so here is an example here are these two queries these are conjunctive queries well look I claim that Q is contained in Q prime alright Q is contained in Q prime because there is a homomorphism by the way I don't know if you see what is the canonical instance of Q prime do you see this is a cycle with four elements right so I'm just too colouring this cycle with four elements that's my homomorphism from IQ prime to IQ because IQ prime is the cycle with four elements and has a homomorphism to the first one which is just the edge so there is this homomorphism and the other way around it's very easy to see there is an obvious homomorphism from IQ to IQ prime namely the one, the identity so the two together tells you that these two queries are actually equivalent right because we have containment going either way of course you could reason it in a different way but ultimately you have to use something like this just an illustration of the homomorphism theorem so we saw before that the graph is three colourable if and only if there is a homomorphism from the graph to K3 but now we can use the Tzandramelling theorem to give database equivalent descriptions of this this means that K3 the clique with three elements satisfies the canonical conjunctive query of a graph and of course this also means that the canonical conjunctive query of Q3 is contained in the canonical conjunctive query of G so really this tells you that you can take db2 or oracle and use it to do three colourability not a good idea why is that because look see what happens here look at this one you have a tiny little database there comes this big graph so you take a huge conjunctive query with as many conjuncts as many joints elements in the joint as the edges right and that's not what the database systems are good at doing we are using relatively small queries on huge databases but in principle you could use a database solver to do a colourability and of course to do a satisfiability testing so by the way this answers your question about the uniqueness here you have lots and lots of homomorphism in fact as many as the colour ok what happens if the queries are not Boolean if you have positive parity the homomorphism theorem goes through a wide modification so let's assume that the queries in the head they have the same three variables then containment means there is a homomorphism which from the canonical database of the bigger to the canonical database of the smaller which maps the variables of the head to the variables of the head one by one so the homomorphism cannot move these variables around and this is the same as saying that look now Q' now Q' has three variables so IQ together with these elements satisfy the canonical conjunctive query of Q' so it goes through it's a little easier to do it for conjunctive queries and then you can play with applications for instance you can prove that if you take these binary conjunctive queries Q' Q is contained in Q' simply because you have a homomorphism from IQ' to IQ and here is the homomorphism but you verify it so that's illustrating the homomorphism theorem so now we have of course made progress to understand the combined complexity of conjunctive query containment and conjunctive query evaluation because the following problems aren't be complete given two Boolean conjunctive queries is one contained in the other given a Boolean conjunctive query and an instance does the instance satisfy the query they are the same as the homomorphism problem by Sandra Merlin and therefore since the homomorphism theorem isn't be complete these aren't be complete what about conjunctive query equivalence this was containment and evaluation well that's very easy to see also and the reason is the following that it's very easy to see that the following problem isn't be complete I give you a graph that contains a triangle is it free colorable that's NP complete you just take your graph and add a join triangle so given a graph containing a triangle is it free colorable that's NP complete but now if you have a graph that contains a triangle then the graph is free colorable if and only if its canonical conjunctive query is a logical homomorphical equivalent to excuse me logical equivalent to the conjunctive query of the clique so we get that the conjunctive query equivalence problem is also NP complete so here is a picture this is in some sense a very crisp way to quantify the gain and the complexity and decidability that we obtained by lowering our expressive power ok we gave up on union we gave up on difference we just kept projection selections and very careful selections just conjunctions of equality so our language became more limited but we replaced NP completeness for both equivalence and containment what about the query evaluation well the gain of course is in the combined complexity right where it dropped to NP complete for data complexity we are still in lock space because we had the lock space even for the full calculus so the lesson is that yes you can get better behavior for these three fundamental database problems if you make your language smaller right therefore having seen this ok let me not say much about this because Vardy probably is going to talk a lot about this because the combined complexity is yes it's decidable but it's NP complete it's not as bad as P space but it's still NP complete a lot of work has gone into finding a simple case of combined complexity this started with a very nice paper on acyclic joints by Michalis Yanakakis in VLDB 1981 where the idea was to start putting structural conditions on the conjunctive query now since the conjunctive queries are really instances as we just saw you can think of it as being structural restrictions on the instances so this led to many many extensions for instance if your instances have bounded tree width then you get also tractable behavior there are generalizations to something called bounded hyper tree width and there is extensive interaction between constraint satisfaction logic and graph theory and that goes into this area but this is a little bit I mean I could give a whole course on this and I have in the past but I will just move on so we saw before the main was this by restricting the language now we can go back and say let's look at what we gave up so we gave up these two operations and also here we kept only a quality let's try to put some of these operations back and see what happens to the complexity so probably the most natural thing to do next would be to consider relational algebra expressions that also allow union so in other words we are talking now about unions of conjunctive queries so a union of conjunctive queries simply a disjunction of conjunctive queries a disjunction of these simple existential formulas where each of them is a conjunctive query and there is another way to think of this namely if you go back to the algebra you can see what am I going to get if I close my relations under the operations of union, projection and selection with the quality conditions the union of conjunctive queries you can think of this as being a normal form like a sum of products so every the second one is for the purposes here monotone query sometimes people call it positive query so again a union of conjunctive queries is a disjunction of conjunctive queries a monotone query is an expression of algebra that uses only union, Cartesian product projection and selection with the quality conditions clearly every union of conjunctive queries is a monotone query the converse is also true that if you have an expression built from these operations a union projection Cartesian product selection with the quality only you can transform it into a union of conjunctive queries but there is a blob in general there is a blob in general it is the same blob when you take something like conjunctive normal form you translate to disjunctive normal form so monotone queries are precisely the queries expressed in first order logic conjunction, disjunction and existential quantification here is an example of this transformation this query is a monotone query is a join remember the join is really conjunctive query applied to a union that is equivalent to this union of conjunctive queries but you can see we have made it much bigger but in terms of expressive power are the same we are going to see an interesting trade off now as we go along so it is everyone clear we are talking about the same class of queries but with two different syntactic ways to express them let's first talk about the union of conjunctive queries Sageven Yanakakis in 1981 the same year but Yanakakis had his paper in VLDB they had another paper in VLDB where among other things they had this nice result it is a simple result I will show you the proof it settles the containment problem for unions of conjunctive queries and says the following thing suppose I have two finite unions of conjunctive queries one is contained in the other if and only if for every i on the left between n up to m there is a j on the right so that qi is contained in qj' intuitively what it says it is obvious that if two holds one holds that's the most blatant way to have containment this theorem tells you when you talk about unions of conjunctive queries the most blatant way that this can take place is the only way it can take place and the proof now is a two line proof if you use the tsandra-merlin theorem let's see why i argue that two implies one is obvious we are going to use the homomorphism theorem so we assume one holds we want to prove that each qi is contained in some qj' so let's take one of them take qi well we know one database that satisfies qi it's the canonical database so the canonical database of qi satisfies qi therefore it must satisfy the right-hand side therefore it must satisfy one member of the union but now by the homomorphism theorem we have that iqi satisfies qj' qi must be contained in qj' so that's a trivial proof using the tsandra-merlin theorem so that's the power of this result the other direction is obvious any questions about that very very simple but now look at this gives us this tells us that the query containment problem for unions of conjunctive queries is NP complete well the NP hardness is even the special case for conjunctive queries the membership follows because now we can take all these homomorphisms and do a big guess we can combine polynomial many guesses to one big polynomial guess so for every query on the left we guess some query on the right and the homomorphism can verify so we guess and verify that for every i less than or equal to an m this function is a homomorphism from one to the other of course the NP hardness follows from the previous from the case that even for conjunctive queries NP hard I will let you verify that the query evaluation problem for unions of conjunctive queries is NP complete that's an easy exercise so now this is nice because it tells us that we could throw in the union and not make things worse than they were without the union ok that's this looks promising so now let's look at the monotone queries remember the monotone queries you have the same expressive power as the unions of conjunctive queries but we saw that the syntax is more compact well so given the Anakakis had another result in the same paper they didn't have just the almost trivial theorem I showed you before they saw that for monotone queries the containment problem is pi to p complete basically this is the price you pay to translate the monotone to the normal form as unions of conjunctive queries and pi to p is the second level of the polynomial hierarchy contains NP contained in p-space and of course the prototypical problem is for all exist quantified Boolean formulas with two alternations starting with the universal so what comes out of this is that when we go to monotone queries we have the same expressive power more compact syntax but we try in query equivalence and query containment we go from NP complete to pi to p complete but nonetheless certainly below p-space which was the full case so this gives a pretty good analysis of what happens if we include the union we can try to put a little bit of negation and the most innocent form of negation that you can think is what happens if you allow in the selection conditions inequalities not equal or less than so what happens if we also allow inequalities in this case you talk about conjunctive queries with inequalities so for example this would be a conjunctive query with some inequalities Tony Kluck was a very bright young student who was conscious but unfortunately died very very young in 1988 saw that the query containment problem for conjunctive queries with inequalities is in pi to p and van der Maiden 10 years later proved a matching lower bound in POTS 92 that it is pi to p hard so we understand completely that the containment problem for conjunctive queries with inequalities is pi to p complete the evaluation problem stays in the same complexity as before hasn't been completed I'm not going to show you this in effect what you lose here is the homomorphism theorem and what you lose here is not dealing really with only one canonical database you can think that these inequalities are describing some partial relations between some equality types between the elements and then you have to take on all possible databases that extend this type complete this type and that's exactly where the complexity that would cause the complexity to go up