Many Associations Leading to Slow Query

Posted by Joey Cadle on Stack Overflow See other posts from Stack Overflow or by Joey Cadle
Published on 2013-06-26T16:20:00Z Indexed on 2013/06/26 16:21 UTC
Read the original article Hit count: 210

Filed under:

I currently have a database that has a lot of many to many associations. I have services which have many variations which have many staff who can perform the variation who then have details on themselves like name, role, etc...

At 10 services with 3 variations each and up to 4 out of 20 staff attached to each service even doing something as getting all variations and the staff associated with them takes 4s.

Is there a way I can reduce these queries that take a while to process? I've cut down the queries by doing eager loading in my DBM to reduce the problems that arise from 1+N issues, but still 4s is a long query for just a testing stage.

Is there a structure out there that would help make such nested many to many associations much quicker to select?

Maybe combining everything past the service level into a single table with a 'TYPE' column ?? I'm just not knowledgable enough to know the solution that turns this 4s query into a 300MS query... Any suggestions would be helpful.

© Stack Overflow or respective owner

Related posts about mysql