title: MySQL - multiple column index
body: <p>I'm learning MySQL index and found that index should be applied to any column named in the WHERE clause of a SELECT query.</p>
  
  <p>Then I found <a href="https://stackoverflow.com/questions/7261536/mysql-multiple-column-index-vs-multiple-indexes">Multiple Column Index vs Multiple Indexes</a>. </p>
  
  <p>First Q, I was wondering what is multiple column index. I found code bellow from Joomla, is this Multiple Column Index?</p>
  
  <pre><code>CREATE TABLE `extensions` (
      `extension_id` INT(11) NOT NULL AUTO_INCREMENT,
      `name` VARCHAR(100) NOT NULL,
      `type` VARCHAR(20) NOT NULL,
      `element` VARCHAR(100) NOT NULL,
      `folder` VARCHAR(100) NOT NULL,
      `client_id` TINYINT(3) NOT NULL,
      ... ...
      PRIMARY KEY (`extension_id`),
  
      // does code below is multiple column index?
  
      INDEX `element_clientid` (`element`, `client_id`),
      INDEX `element_folder_clientid` (`element`, `folder`, `client_id`),
      INDEX `extension` (`type`, `element`, `folder`, `client_id`)
  )
  </code></pre>
  
  <p>Second Q, am I correct if thinking that one Multiple Column Index is used on one SELECT ?</p>
  
  <pre><code>SELECT column_x WHERE element=y AND clinet_id=y; // index: element_clientid
  
  SELECT ex.col_a, tb.col_b
      FROM extensions ex
      LEFT JOIN table2 tb
      ON (ex.ext_id = tb.ext_id)
      WHERE ex.element=x AND ex.folder=y AND ex.client_id=z; // index: element_folder_clientid
  </code></pre>