title: MySQL Performance - 1 Million Records - Select Int before Text Field
body: <p>Obviously selecting a text field among 1 million records would be slow and not recommended. Here are two possible solutions.</p>
  
  <ol>
  <li><p>Break the database up giving each user his own database or table and therefore reducing the total records in each table dramatically.</p></li>
  <li><p>Perform the SQL SELECT query to match a INT, where INT is the user ID, and then match the text field.</p></li>
  </ol>
  
  <p>Option 1 would provide an obvious performance gain. But would option number 2 also provide a gain? In the statement, if we match the INT first, would this narrow the result set down to only the matching records and then perform the text field search. For example..</p>
  
  <pre><code>$user_id = 1001;
  $domain_name = "mydomain.com";
  $query = $database-&gt;prepare("SELECT * FROM domains_table WHERE user_id = $user_id &amp;&amp; domain_name = $domain_name");
  </code></pre>
  
  <p>Where switching the position of user_id and domain_name in the above query would destroy performance. Does matching the user_id first offer an advantage here?</p>