13.10. Same Base A and B, 1 - 1 match over cols Aid(E),Bid(E)¶
It is important to realize when relations have the same base. It is because they have the same identifying columns. In many sophisticated databases, it will take a step of using a reduce to create a relation that will have the same base as another relation and can then be Match Joined. For example, let’s consider this larger portion of the schema for the database we have been working with:
Though there are several chicken-feet-out shapes involving Town, what we want to focus on is the two parallel chicken-feet-in shapes whose intersection entities are Achievement and Aspiration, respectively, between Creature and Skill. This set of two different chicken-feet-in shapes involving entities like Creature and Skill is relatively common in databases.
In this database, there can be more than one of the same Skill achieved by a creature, i.e. there can be more than one pair of the same creatureId, skillCode data values in Achievement. (A creature can achieve the same skill more than once.) However, the data for Aspiration contains one creatureId, skillCode pair of data values, because those two columns form its identifier.
We might want to ask an English query like this:
What creatures have achieved and aspired to the same Skill?
One way to interpret this query is to decide that we simply want a single instance of a creature having achieved a skill (creatureId, skillCode) with the creatureId, skillCode of the Aspiration.
To perform this match of Aspiration data with Achievement data we must be careful to make certain that we have a 1 - 1 correspondence between columns we want to match over in the input relations. So with this interpretation, we would perform a Reduce first on Achievement, so that the precedence chart looks like this:
After the Reduce, the Match Join is a same base (Creature-Skill Pair), 1 - 1 case and therefore Symmetric-either.
- creatureId
- The same-base, symmetric-either 1-1 case means the base of the result relations stays the same as the two same input relation bases. What is the base, which implies its identifier?
- skillCode
- The same-base, symmetric-either 1-1 case means the base of the result relations stays the same as the two same input relation bases. What is the base, which implies its identifier?
- skillCode, creatureId
- Correct! The same-base, symmetric-either 1-1 case means the base of the result relations stays the same as the two same input relation bases.
Q-1: Which of these is the identifier for the result relation?
The SQL for this chart then becomes:
13.10.1. A Different Interpretation¶
Another way to consider the posed query is to maintain the M - 1 correspondence between Achievement as A and Aspiration as B by not first doing the Reduce shown above. In this case we can state that what we want to get back is every Achievement matched to Aspiration through creatureId and skillCode.
- Aid(E), Bid(E)
- creatureId, skillCode is not exactly Achievement's identifier
- Aid(S), Bid(E)
- creatureId, skillCode is not some of Achievement's identifier
- Aid(D), Bid(E)
- Yes- creatureId, skillCode is disjoint from Achievement's identifier and exactly Aspiration's identifier.
- Aid(O), Bid(E)
- creatureId, skillCode does not overlap with any of Achievement's identifier
Q-4: What would the ‘works on’ columns be in this case?
- Non-symmetric-A
- Yes, M - 1 implies Non-symmetric-A
- Symmetric-either
- 1 - 1 implies Symmetric-either
- Symmetric-pair
- M - M implies Symmetric pair
Q-5: What is the symmetry of this proposed M - 1 situation?
- Different Base
- Yes, the identifiers of Achievement and Aspiration are different.
- Same base
- The identifier of Achievement is achId and Aspiration's identifier is creatureId, skillCode.
- Same Relation
- Achievement and Aspiration are not the same relation.
Q-6: What is are the bases of A (Achievement) and B (Aspiration) in this situation?
If you would like, try the chart for this different case, now that you have answered these questions.