Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Innodb key length on secondary indexes
    primarykey
    data
    text
    <p>MySQL : Ver 14.12 Distrib 5.0.51b, for redhat-linux-gnu (x86_64) using EditLine wrapper</p> <p>sql_1:</p> <pre><code>SELECT SQL_NO_CACHE COUNT(*) FROM `ting_song_info`; </code></pre> <p>result :</p> <pre><code>+----------+ | COUNT(*) | +----------+ | 2637447 | +----------+ 1 row in set (0.42 sec) </code></pre> <p>explain :</p> <pre><code>+----+-------------+----------------+-------+---------------+-------------------+---------+------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------------+-------+---------------+-------------------+---------+------+---------+-------------+ | 1 | SIMPLE | ting_song_info | index | NULL | total_listen_nums | 4 | NULL | 2769410 | Using index | +----+-------------+----------------+-------+---------------+-------------------+---------+------+---------+-------------+ </code></pre> <p>The sql_1 use the key <code>total_listen_nums</code>.</p> <p>Then appoint the key.</p> <p>sql_2 :</p> <pre><code>SELECT SQL_NO_CACHE COUNT(*) FROM `ting_song_info` USE KEY(`album_id`); </code></pre> <p>result :</p> <pre><code>+----------+ | COUNT(*) | +----------+ | 2637447 | +----------+ 1 row in set (5.21 sec) </code></pre> <p>explain:</p> <pre><code>+----+-------------+----------------+-------+---------------+----------+---------+------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------------+-------+---------------+----------+---------+------+---------+-------------+ | 1 | SIMPLE | ting_song_info | index | NULL | album_id | 8 | NULL | 2769410 | Using index | +----+-------------+----------------+-------+---------------+----------+---------+------+---------+-------------+ </code></pre> <p>The key_len of total_listen_nums is shoter than album_id.</p> <p>Is this why sql_1 use total_listen_nums?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload