title: First-run of queries are extremely slow
body: <p>Our Redshift queries are <em>extremely</em> slow during their first execution. Subsequent executions are much faster (e.g., 45 seconds -> 2 seconds). After investigating this problem, the query compilation appears to be the culprit. This is a known issue and is even referenced on the AWS <a href="https://docs.aws.amazon.com/redshift/latest/dg/c-query-planning.html" rel="nofollow noreferrer">Query Planning And Execution Workflow</a> and <a href="https://docs.aws.amazon.com/redshift/latest/dg/c-query-performance.html" rel="nofollow noreferrer">Factors Affecting Query Performance</a> pages. Amazon itself is quite <a href="https://forums.aws.amazon.com/thread.jspa?threadID=125786" rel="nofollow noreferrer">tight lipped</a> about how the query cache works (tl;dr it's a magic black box that you shouldn't worry about).</p>
  
  <p>One of the things that we tried was increasing the number of nodes we had, however we didn't expect it to solve anything seeing as how query compilation is a single-node operation anyway. It did not solve anything but it was a fun diversion for a bit.</p>
  
  <p>As noted, this is a known issue, however, anywhere it is discussed online, the only takeaway is either "this is just something you have to live with using Redshift" or "here's a super kludgy workaround that only works part of the time because we don't know how the query cache works".</p>
  
  <p>Is there anything we can do to speed up the compilation process or otherwise deal with this? So far about the best solution that's been found is "pre-run every query you might expect to run in a given day on a schedule" which is....not great, especially given how little we know about how the query cache works.</p>