0

I need to break one table into 2. 1 table will have a one-to-many relationship with the other.

These tables hold credits for shows. More than one person can have the same role in a show, therefore I need a roles table which will have a one-to-many relationship with the names of the performers (i.e. maybe there's a group of people all played "townspeople").

So, the breakdown would be:

credits_roles - The main table. credits_names - The names of the performers (relationship is with the id column in credits_roles).

Originally, it was structured in one table. Each row had a different performer and role. This is causing problems with several queries on the site and this break will simplify things.

I've moved the data that I need into credits_roles using an INSERT statement and GROUP BY. credits_roles now has only the unique roles.

Where I'm having problems is an UPDATE statement that will look up the id in credits_roles and add it to the credits_roles_id column in credits_names.

This is what I have.

UPDATE credits_names 
INNER JOIN credits_roles
    ON credits_names.role_id = credits_roles.role_id AND credits_names.show_id = credits_roles.show_id AND credits_names.credit_class = credits_roles.credit_class
SET credits_names.credit_role_id = credits_roles.id

credits_names is the original table and currently has all of the data. Some of it will be deleted once this project is complete. Right now, I'm joining based on the id of the role (because "townspeople" would have it's own id from a separate roles table), the id of the show that these credits are for, and then there is a credit_class (for cast vs. crew, or CA vs. CR in the table). All of these need to be matched to look up credits_roles.id.

The problem is that the query keeps running...and running...and running. I let it run overnight and it never finished. There are 300,000 records in credits_names. But when I stop the query, no updates have been made.

So, my question is, what do I need to change in this query? It seems like a simple update but it's not doing anything. Or, if not this query, what do I need to do instead?

5
  • 2
    You probably just need indexes on the columns used in the join. Jan 22, 2015 at 12:25
  • Totally agree with @GordonLinoff, create indexes on all columns that are referenced in the join condition. Jan 22, 2015 at 12:27
  • Unfortunately, that didn't work. I created indexes on the columns that I'm joining and ran the query again. The query's been running for 4 hours.
    – Bobo Lobo
    Jan 23, 2015 at 3:56
  • Any other ideas to help me out? I'm completely stuck.
    – Bobo Lobo
    Jan 25, 2015 at 22:04
  • Can anyone offer other suggestions?
    – Bobo Lobo
    Feb 4, 2015 at 23:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.