title: Django Rest Framework large number of queries for nested relationship
body: <p><strong>My problem</strong></p>
  
  <p>I have a large number of nested model serializers (5 levels deep) via one-to-many relationships. The total query time is not that high according to django debug toolkit - maybe 100ms, but it takes about 6s of cpu time to run due to the many hundreds of times the database is being hit per query.</p>
  
  <p>The problem is, 3 of those tables are huge, with millions of rows. As such, whenever I run 'prefetch_related' for anything it takes far longer to execute, sometimes minutes. select_related isn't an option, as they are all one-to-many.</p>
  
  <p>Imagine something like a pedometer that takes steps, and also ties multiple environment readings and accelerometer readings to a step.</p>
  
  <p><strong>Example Schema</strong></p>
  
  <pre><code>Person
  id
  name
  
  Pedometer
  id
  name
  owner(Person)
  
  Step
  id
  info
  timestamp
  pedometer
  
  Environment_Readings
  id
  pressure
  step
  
  Accelerometer_Readings
  id
  force
  step
  </code></pre>
  
  <p><strong>What I want to achieve</strong></p>
  
  <p>So I want to select all people > an array of their pedometers (often multiple) > an array of all steps they have taken in the last minute > array of environment readings and array of accelerometer readings.</p>
  
  <p>I am not seeing a way to prefetch environment_readings or accelerometer_readings as neither have a timestamp. The only ones that can be prefetched appear to be pedometer and step. And for some reason prefetching pedometer seems to slow it down.</p>
  
  <p>Any ideas?</p>