title: Clickhouse: order by same order as table storage runs out of memory
body: <p>I have billions of rows in a table </p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE sample ( PN String,  
                        CHROM String,  
                        POS UInt32) 
  ENGINE = MergeTree 
  PARTITION BY PN 
  ORDER BY (CHROM, POS) 
  SETTINGS index_granularity = 8192;
  </code></pre>
  
  <p>each PN having about 5 million rows</p>
  
  <p>I want to return all rows in order of CHROM, POS</p>
  
  <pre class="lang-sql prettyprint-override"><code> select * from sample order by CHROM, POS
  </code></pre>
  
  <p>This runs out of memory. </p>
  
  <p>Since the data is already stored in CHROM, POS order albeit partitioned by PN is there a way to 'stream' all data from the partitions and merge them in order without needing much memory. </p>