Search code examples
data-structureshas-and-belongs-to-manyhas-one

Which data structure (full HABTM ?)


I just want to know which of this two structures is the best for better performance:

  • Full HABTM (many to many), but with a very big join table (so only one association for query)
  • Or, HABTM + 1 hasOne (which reduce significantly the join table rows (equal to number of main entity, approximatively 50 000rows) ? But this method forced me to do a query with 2 associations.

So to sum up. Should I use a query with a single association but a big join table (120 000rows) or use a query for 2 associations but with a more lightweight join table ?


Solution

  • After some reflexions, I think I will use a single join. I have just seen some benchmarks that shows single join will be more efficient than multiple queries even if the join table contain lot of rows. It's also less development effort for my application code.

    I remain at your listening for any advice. Thanks