title: Mysql 5.7 dont use index
body: <p>Hello since i update from mysql 5.5 to percona 5.7</p>
  
  <p>This query:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT COUNT(a.alarm_id) AS `count`, MAX(a.alarm_id) AS `max_alarm_id`, `a`.`priority` 
      FROM `alarm` AS `a` 
      WHERE (a.maintenance_suppress = '0') 
      AND (a.deleted_at = '0000-00-00 00:00:00') 
      AND (a.object_id = '6') 
      GROUP BY `a`.`priority`
  </code></pre>
  
  <p>Wont use indexes as expected any more.</p>
  
  <p>This is the explain for the query:</p>
  
  <pre><code>+----+-------------+-------+------------+------+---------------------------------------------------------------------+-----------+---------+-------------------+------+----------+--------------------------------------------------------+
  | id | select_type | table | partitions | type | possible_keys                                                       | key       | key_len | ref               | rows | filtered | Extra                                                  |
  +----+-------------+-------+------------+------+---------------------------------------------------------------------+-----------+---------+-------------------+------+----------+--------------------------------------------------------+
  |  1 | SIMPLE      | a     | NULL       | ref  | maintenance_suppress,alarm_count,deleted_at,object_id,alarm_count_b | object_id | 10      | const,const,const |    1 |   100.00 | Using index condition; Using temporary; Using filesort |
  +----+-------------+-------+------------+------+---------------------------------------------------------------------+-----------+---------+-------------------+------+----------+--------------------------------------------------------+
  </code></pre>
  
  <p>And this are my indexs:</p>
  
  <pre><code>Keyname                 Type    Unique  Packed  Column                      Cardinality Collation   Null
  PRIMARY                 BTREE   Yes     No      alarm_id                    1156170     A           No  
  quited_by               BTREE   No      No      acknowledged_by                  78     A           Yes 
  deleted_by              BTREE   No      No      deleted_by                        9     A           Yes 
  device_id               BTREE   No      No      component_id                    820     A           Yes 
  message_status_create   BTREE   No      No      message_status_create             2     A           No  
  leaved_at               BTREE   No      No      leaved_at                    597481     A           No  
                                                  message_status_leaved        527117     A           No
  acknowledged_at         BTREE   No      No      acknowledged_at              139029     A           No  
                                                  message_status_acknowledged  176719     A           No
  maintenance_suppress    BTREE   No      No      maintenance_suppress              1     A           No  
  ticket_id               BTREE   No      No      ticket_id                         1     A           Yes 
  alarm_count             BTREE   No      No      priority                          5     A           No  
                                                  specified_class                   8     A           No
                                                  maintenance_suppress              8     A           No
                                                  deleted_at                    27340     A           No
                                                  object_id                     21310     A           No
  deleted_at              BTREE   No      No      deleted_at                    29538     A           No  
  specified_class         BTREE   No      No      specified_class                   2     A           No  
  created_at              BTREE   No      No      created_at                   876796     A           No  
  object_id               BTREE   No      No      object_id                       192     A           No  
                                                  deleted_at                    10261     A           No
                                                  maintenance_suppress          56175     A           No
  alarm_count_b           BTREE   No      No      priority                          6     A           No  
                                                  maintenance_suppress              9     A           No
                                                  deleted_at                    31421     A           No
                                                  object_id                     46226     A           No
  </code></pre>
  
  <p>If i force the index it is going to be slower:</p>
  
  <pre><code>mysql&gt; SELECT COUNT(a.alarm_id) AS `count`, MAX(a.alarm_id) AS `max_alarm_id`, `a`.`priority` 
      -&gt;     FROM `alarm` AS `a` 
      -&gt;     WHERE (a.maintenance_suppress = '0') 
      -&gt;     AND (a.deleted_at = '0000-00-00 00:00:00') 
      -&gt;     AND (a.object_id = '68') 
      -&gt;     GROUP BY `a`.`priority`;
  +-------+--------------+----------+
  | count | max_alarm_id | priority |
  +-------+--------------+----------+
  |     8 |      1278404 |        2 |
  +-------+--------------+----------+
  1 row in set (0.01 sec)
  
  mysql&gt; SELECT COUNT(a.alarm_id) AS `count`, MAX(a.alarm_id) AS `max_alarm_id`, `a`.`priority` 
      -&gt;     FROM `alarm` AS `a` FORCE INDEX (alarm_count_b)
      -&gt;     WHERE (a.maintenance_suppress = '0') 
      -&gt;     AND (a.deleted_at = '0000-00-00 00:00:00') 
      -&gt;     AND (a.object_id = '68') 
      -&gt;     GROUP BY `a`.`priority`;
  +-------+--------------+----------+
  | count | max_alarm_id | priority |
  +-------+--------------+----------+
  |     8 |      1278404 |        2 |
  +-------+--------------+----------+
  1 row in set (0.67 sec)
  </code></pre>
  
  <p>Has anyone a idea what is wrong with my indexs?</p>
  
  <p>SQL fiddle to play arround:
  <a href="http://sqlfiddle.com/#!9/23949/1" rel="nofollow">http://sqlfiddle.com/#!9/23949/1</a></p>