title: Understanding MySQL key_len in Explain Statement
body: <p>According to <a href="http://dev.mysql.com/doc/refman/5.6/en/explain-output.html#explain_key_len" rel="noreferrer">MySQL website</a>, the <code>key_len</code> column indicates the length of the key that MySQL decided to use. The length is <code>NULL</code> if the key column says <code>NULL</code>. Note that the value of key_len enables you to determine how many parts of a multiple-part key MySQL actually uses.</p>
  
  <p>Using an example from my <a href="https://stackoverflow.com/questions/7580685/mysql-why-does-an-order-by-id-runs-much-slower-than-order-by-other-columns">previous question</a>, I have an EXPLAIN SELECT statement that shows MySQL using an <code>Index</code> with <code>key_len: 6</code>. Below shows the composition of the index and columns used.</p>
  
  <pre><code>`Type` char(1) NOT NULL,
  `tn` char(1) NOT NULL DEFAULT 'l',
  `act` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `flA` mediumint(6) unsigned NOT NULL DEFAULT '0',
  KEY `Index` (`Type`, `tn`, `act`, `flA`)
  </code></pre>
  
  <p>So how does the value of <code>key_len</code> allows me to determine that my query uses the first three parts of a multiple-part key?</p>