title: How to create a temporary table and not lose the ORM in django?
body: <p>I'm curious how to create a temporary table in django? (the database is mysql, a client requirement) </p>
  
  <pre><code>CREATE TEMPORARY TABLE somewhat_like_a_cache AS
  (SELECT * FROM expensive_query_with_multiple_joins);
  SELECT * FROM somewhat_like_a_cache LIMIT 1000 OFFSET X;
  </code></pre>
  
  <p>The reasoning behind this:
  The resultset is fairly large and I have to iterate it. The expensive query takes around 30 seconds. Without a temporary table I stress the database server for several hours. With the temporary table the expensive query is executed only once and iterating the temporary table in slices is cheap afterwards.</p>
  
  <p>This is no duplicate of 
  <a href="https://stackoverflow.com/questions/16162611/how-to-create-a-temporary-table-in-django-with-orm">How do I create a temporary table to sort the same column by two criteria using Django&#39;s ORM?</a>. The author just wanted to sort by two columns. </p>