Tip:
Highlight text to annotate it
X
Speaker 1: To look at the answer to this question, we have to
remember, what's the relationship that we're trying to
facilitate here. We're saying, movie has many movie goers
through reviews. One way that you could address this question is
you could sketch out for yourself what it looks like when you
set up that association. Here's movies, here's movie goers,
here's the through part of the association. That means that for
any given movie, if we're trying to figure out which movie goers
are associated, the first thing that we got to do is, we're
traversing this association from right to left. Given a movie,
which reviews are about that movie. That means that we're
looking for all the reviews who's movie ID field would match the
ID of the movie in question, correct? How are we going to find
those? We've got two choices. We can do it the hard way which we
do at table scanner reviews and find all the matches or we could
do it the easier way which is to have an index of movie ID in
the reviews table and then we could look it up quickly. Armed
with those, the operation of finding out which movie is
associated with it is relatively easy because all we're *** is
a direct look up on the movie goer ID, that's a primary key. We
get that index for free from the database as it is. The question
as to which foreign- key index would most help is the movie ID
index on the reviews table because that's where you would
otherwise be spending most of your time. Starting from a movie,
trying to figure out which review or reviews have a movie ID
that matches it. If you don't have an index on that, the only
way to do that stuff is at the table scanner so that's what
saves you the most.