Hacker News new | ask | show | jobs
by lun4r 1409 days ago

  mysql> EXPLAIN SELECT COUNT(*) FROM users \G
  \*\*\*\*\*\*\*\*\*\*\*\*\** 1. row \*\*\*\*\*\*\*\*\*\*\*\*\*\*
             id: 1
    select_type: SIMPLE
          table: users
     partitions: NULL
           type: index
  possible_keys: NULL
            key: needs_review
        key_len: 1
            ref: NULL
           rows: 5290406
       filtered: 100.00
          Extra: Using index
  1 row in set, 1 warning (0.01 sec)

  mysql> EXPLAIN SELECT COUNT(id) FROM users \G
  \*\*\*\*\*\*\*\*\*\*\*\*\*\* 1. row \*\*\*\*\*\*\*\*\*\*\*\*\*\*
             id: 1
    select_type: SIMPLE
          table: users
     partitions: NULL
           type: index
  possible_keys: NULL
            key: needs_review
        key_len: 1
            ref: NULL
           rows: 5290406
       filtered: 100.00
          Extra: Using index
  1 row in set, 1 warning (0.00 sec)
Both (*) and (id) appear to be using the same index. According to the author, the second query would use PRIMARY instead.