title: Clickhouse: DB::Exception: Memory limit (for query) exceeded
body: <p>What should I do when I run out of memory for Clickhouse queries? You can't just crank up the memory, right? There is also a limit to memory, how to configure the hard disk?</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT
      UserID,
      Title
  FROM 
  (
      SELECT
          L.UserID,
          L.Title
      FROM tutorial.hits_v1 AS L
      INNER JOIN tutorial.hits_v2 AS R ON L.UserID = R.UserID
  ) AS T
  ORDER BY UserID ASC
  LIMIT 10
  </code></pre>
  <pre class="lang-xml prettyprint-override"><code>#user.d/abc.xml
  
  
  &lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;yandex&gt;
      &lt;!-- Profiles of settings. --&gt;
      &lt;profiles&gt;
          &lt;!-- Default settings. --&gt;
          &lt;default&gt;
              &lt;!-- Maximum memory usage for processing single query, in bytes. --&gt;
              &lt;max_memory_usage&gt;350000000&lt;/max_memory_usage&gt;
              &lt;max_memory_usage_for_user&gt;350000000&lt;/max_memory_usage_for_user&gt;
              &lt;max_bytes_before_external_group_by&gt;100000000&lt;/max_bytes_before_external_group_by&gt;
              &lt;max_bytes_before_external_sort&gt;100000000&lt;/max_bytes_before_external_sort&gt;
          &lt;/default&gt;
      &lt;/profiles&gt;
  &lt;/yandex&gt;
  
  </code></pre>