title: Indexing full column or substring
body: <p>I have a large mariadb table with millions of rows.  The basis for much of the data analysis will be on a 10 digit column like below.  </p>
  
  <pre><code>4047535609
  6099526199
  6014157747
  3045308020
  </code></pre>
  
  <p>For many of the queries, I only need the first 6 digits.  The plan is to index this column, but I'm curious whether it would make much/any difference to create an index of a substring, such as left(sku,6) or just index the whole column.  I should note that most of the queries will involve grouping of common first 6 digits.</p>
  
  <p>HD space isn't really a concern, but with potentially 15-20 million rows, I'm curious about the cardinality of the index.</p>
  
  <p>Edit:  I changed the column name to sku instead of id.  The id column is the primary key. The sku column is not unique.</p>
  
  <pre><code>id int(11) Primary Key
  sku varchar(12)
  rate decimal(5,2)
  region varchar(24)
  quantity int(4)
  orderdate datetime
  </code></pre>
  
  <p>I expect most of the queries to involve grouping of common sku in relation to the other categories such as # of sku at n rate or x region.</p>