title: Aggregation in Cassandra across partitions
body: <p>I have a Data model like below,</p>
  
  <pre><code>CREATE TABLE appstat.nodedata (
      nodeip text,
      timestamp timestamp,
      flashmode text,
      physicalusage int,
      readbw int,
      readiops int,
      totalcapacity int,
      writebw int,
      writeiops int,
      writelatency int,
      PRIMARY KEY (nodeip, timestamp)
  ) WITH CLUSTERING ORDER BY (timestamp DESC)
  </code></pre>
  
  <p>where, nodeip - primary key and timestamp - clustering key (Sorted by descinding oder to get the latest),</p>
  
  <p>Sample data in this table,</p>
  
  <pre><code>SELECT * from nodedata WHERE nodeip = '172.30.56.60' LIMIT 2;
  
   nodeip       | timestamp                       | flashmode | physicalusage | readbw | readiops | totalcapacity | writebw | writeiops | writelatency
  --------------+---------------------------------+-----------+---------------+--------+----------+---------------+---------+-----------+--------------
   172.30.56.60 | 2017-12-08 06:13:07.161000+0000 |       yes |            34 |     57 |       19 |            27 |       8 |        89 |           57
   172.30.56.60 | 2017-12-08 06:12:07.161000+0000 |       yes |            70 |      6 |       43 |            88 |      79 |        83 |           89
  </code></pre>
  
  <p>This is properly available and whenever I need to get the statistics I am able to get the data using the partition key like below,</p>
  
  <pre><code>SELECT nodeip,readbw,timestamp FROM nodedata WHERE nodeip = '172.30.56.60' AND timestamp &lt; 1512652272989 AND timestamp &gt; 1512537899000;
  </code></pre>
  
  <p>Also successfully aggregate the data like below,</p>
  
  <pre><code>SELECT sum(readbw) FROM nodedata WHERE nodeip = '172.30.56.60' AND timestamp &lt; 1512652272989 AND timestamp &gt; 1512537899000;
  </code></pre>
  
  <p><strong>Now comes the next use case, Where I need to get the cluster data (All the data's of the four nodes),</strong></p>
  
  <p>Like below,</p>
  
  <pre><code>SELECT nodeip,readbw,timestamp FROM nodedata WHERE nodeip IN ('172.30.56.60','172.30.56.61','172.30.56.62','172.30.56.63') AND timestamp &lt; 1512652272989 AND timestamp &gt; 1512537899000;
  </code></pre>
  
  <p>But It clearly mentioned in number of sites that, 'IN query' has lots of performance hiccups, So what is your suggestion in this Data Model of 'nodedata' table mentioned above? (NOTE: Doing Multiple queries in different partitions are okay which I feel like a last option)</p>
  
  <p><strong>Do you have a better approach (or) re-designing this data model in a better way (or) Any better solution to retrieve the data from multiple partitions?</strong></p>
  
  <p>Any help would be really appreciable.</p>
  
  <p>Thanks,<br>
  Harry</p>