title: In MySql, find strings with a given prefix
body: <p>In MySql, I want to locate records where the string value in one of the columns begins with (or is the same as) a query string. The column is indexed with the appropriate collation order. There is no full-text search index on the column though.</p>
  
  <p>A good solution will:</p>
  
  <ol>
  <li><p>Use the <strong>index</strong> on the column. Solutions that need to iterate over all the records in the table aren't good enough (several million records in the table)</p></li>
  <li><p>Work with strings with <strong>any character values</strong>. Some of the column values contain punctuation characters. The query string might too. Keep this in mind if your solution includes regex characters or similar. The strings are UTF-8 encoded, but if your solution only works with ASCII it could still be useful.</p></li>
  </ol>
  
  <p>The closest I have at this point is</p>
  
  <pre><code>SELECT * FROM TableName WHERE ColumnName BETWEEN query AND &lt;&lt;query+1&gt;&gt;
  </code></pre>
  
  <p>Where <code>&lt;&lt;query+1&gt;&gt;</code> is pre-computed to lexicographically follow <code>query</code> in the collation order. For example, if <code>query</code> is "o hai" then <code>&lt;&lt;query+1&gt;&gt;</code> is "o haj".</p>