0

My question is also based off How to find all pizzerias that serve every pizza eaten by people over 30?

This is the database I am using for my queries

https://class.stanford.edu/c4x/DB/RA/asset/pizzadata.html

the syntax for writing out relational algebra queries is based off http://www.cs.duke.edu/~junyang/ra/ .

My objective is to "Find all pizzerias that serve only pizzas eaten by people over 30. ". I have the fist couple of steps down but I am struggling with finding pizzerias that have a complete match. Based on the last thread I looked at for the question , it seemed like the div operator was necessary to find the pizzeria that has a complete match with a given list of pizzas. However from http://www.cs.duke.edu/~junyang/ra/, I couldn't find such a div operator. Is there a work around for the div operator? The other answers on that thread were too convoluted and didn't work. This is my query so far

    \project_{pizzeria, pizza} (
\select_{age > 30} (
    Person \join Eats
   )

\join
   Serves

)

What I have here is a query that first locates people over 30 and joins those people with the pizzas they eat. then I join with Serves so I can see the pizzerias that serve those pizzas. I understand I need a complete match - pizzas that serve only what people over 30 eat. That is why I feel like the div operator would be very helpful.

Community
  • 1
  • 1
committedandroider
  • 8,711
  • 14
  • 71
  • 126
  • In such cases the _negative_ formulation often helps: find all pizzerias that serve no pizzas eaten by people less or equal to 30. – Joop Eggen Sep 01 '14 at 07:32
  • It helps only if you manage to do the negations right. You haven't. In order to get it right, most of the time it is needed to spell out the existential/universal quantifications involved BEFORE you start applying the negations. What people aged <= 30 eat is irrelevant when answering the OP question. – Erwin Smout Sep 01 '14 at 12:06

1 Answers1

1

Find all pizzeria's that serve every pizza eaten by people over ...

and

Find all pizzeria's that serve only pizzas eaten by people over ...

are different problems already.

The first should return all the pizzeria's whose set of served pizza's is a superset of the set of pizza's eaten by anyone over ...

The second should return all the pizzeria's whose set of served pizza's is a subset of the set of pizza's eaten by anyone over ...

Yet another problem would be to find the pizzaria's whose set of served pizza's is equal to the set of pizza's eaten by anyone over ...

This aspect of the problem is probably the major reason why RA systems (included SQL processors) offer no direct support for the divide operator : relational divide can come in many flavours and it is hard to tell which one the user will be needing.

Rephrase the problem such that it states the equivalent, then translate that to RA or SQL, e.g. something like "find all the pizzeria's Z such that there does not exist any pizza P and/or person PRS that is over ... and PRS eats P, and P is not served by Z".

Or something like "find all the pizzeria's that are not in the set of those that do not serve some pizza that is eaten by any person over 30".

Erwin Smout
  • 18,113
  • 4
  • 33
  • 52