title: MySQL - indexing , order of fields
body: <p>My database size is growing, so I have decided to add indexes (never done that before). So I need some advice. e.g.</p>
  
  <pre><code>SELECT field1, field2 
  
  FROM mytable1
  
  WHERE account_id = :account_id and product_id = :product_id  and version_name = :version_name
  </code></pre>
  
  <p>or </p>
  
  <pre><code>SELECT field1, field2 
  
  FROM mytable1
  
  WHERE version_name = :version_name and  and product_id = :product_id  and account_id = :account_id
  </code></pre>
  
  <p>An account can have many products and product can have millions of versions, which <code>select</code> order in <code>where</code> is faster. <code>version_name</code> is a string.</p>
  
  <p>If I have <code>version_id</code> available which is primary key should I always put that first.</p>
  
  <p>Should I add index upon account_id and product_id together</p>
  
  <p>Does it get all the rows for first condition in <code>where</code>, and then filters the result as per second condition and so on</p>
  
  <p>or</p>
  
  <p>It scans every row for all the three fields, given no index is added</p>