title: How to improve performance on SUM from float values in MySQL?
body: <p>I am trying to optimize a query (on MySQL 5.7) that takes about 1s to execute on 3M rows. The desired result is a SUM of float values per day within the last 30days:</p>
  <p>Query:</p>
  <pre><code>SELECT
      DATE,
      SUM(RIX) as value
  FROM
      tbl1 v
  JOIN tbl2 b ON v.BRAND_ID = b.ID and  b.MANUFACTURER_ID = 18670
  WHERE
      DATE BETWEEN FROM_UNIXTIME(1613663944) AND FROM_UNIXTIME(1616255944)
       AND type = 'kwd'
  group by v.DATE
  </code></pre>
  <p>Tbl1 (10K rows):</p>
  <pre><code>create table tbl1
      (
          ID              mediumint unsigned auto_increment
              primary key,
          ID_parent       mediumint unsigned null,
          MANUFACTURER_ID mediumint unsigned not null,
          BRAND           varchar(255)       null,
          CREATED         date               null,
          constraint test
              unique (MANUFACTURER_ID, BRAND),
      );
      
      create index idx2
          on tbl1 (ID_parent);
      
      create index idx3
          on tbl1 (MANUFACTURER_ID);
      
      create index idx4
          on tbl1 (BRAND);
  </code></pre>
  <p>Tbl2 (3M rows:</p>
  <pre><code>create table tbl2
  (
      DATE        date                       not null,
      MERCHANT_ID mediumint unsigned         not null,
      TYPE        enum ('cat', 'kwd', 'css') not null, 
      BRAND_ID    mediumint unsigned         not null,
      RIX         float unsigned             not null,
      primary key (DATE, TYPE, MERCHANT_ID, BRAND_ID)
  )
  
  
  create index idx1
      on tbl2 (RIX);
  </code></pre>
  <p>I could not get it to perform faster. Any ideas on how to improve the query time?</p>