Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join queries and when it's too much

I find that I am using a lot of join queries, especially to get statistics about user operations from my database. Queries like this are not uncommon:

from io in db._Owners where io.tenantId == tenantId
    join i in db._Instances on io.instanceId equals i.instanceId
    join m in db._Machines on i.machineId equals m.machineId
    select ...

My app is still not active, so I have no way of judging if these queries will be computationally prohibitive in real-life. My query:

  1. Is there a limit to when doing too many 'joins' is too much, and can that be described without getting real-life operating stats?
  2. What are my alternatives? For example, is it better to just create additional tables to hold statistics that are I update as I go, rather than pulling together different table sources each time I want statistics?
like image 741
Testing123 Avatar asked Jun 30 '10 21:06

Testing123


1 Answers

If you do not have performance information then do not optimize.

Premature optimization is the root of all evil.

1) I don't think you'll ever reach the "limit". 2) This is called denomalization, premature denormalization is just wasted effort if you don't know if a problem exists.

I'd say your query looks pretty normal.

like image 172
John Farrell Avatar answered Sep 28 '22 10:09

John Farrell