title: Athena: Query exhausted resources at scale factor
body: <p>I am running a query like: </p>
  
  <pre><code>SELECT f.*, p.countryName, p.airportName, a.name AS agentName
  FROM (
      SELECT 
          f.outboundlegid, 
          f.inboundlegid,
          f.querydatetime,
          cast(f.agent as bigint) as agent,
          cast(f.querydestinationplace as bigint) as querydestinationplace,
          f.queryoutbounddate,
          f.queryinbounddate,
          f.quoteageinminutes,
          f.price
      FROM flights f
      WHERE querydatetime &gt;= '2018-01-02'
      AND querydatetime &lt;= '2019-01-10'
  ) f
  INNER JOIN (
    SELECT airportId, airportName, countryName
    FROM airports
    WHERE countryName IN ('Philippines', 'Indonesia', 'Malaysia', 'Hong Kong', 'Thailand', 'Vietnam')
  ) p
  ON f.querydestinationplace = p.airportId
  INNER JOIN agents a
  ON f.agent = a.id
  ORDER BY f.outboundlegid, f.inboundlegid, f.agent, querydatetime DESC
  </code></pre>
  
  <p>What's wrong with it? Or how can I optimize it? It gives me </p>
  
  <blockquote>
    <p>Query exhausted resources at this scale factor</p>
  </blockquote>
  
  <p>I have a flights table and I want to query for flights inside a specific country</p>