I have a MySQL InnoDB table with tens of millions of rows. Each row has uuid column. They are stored in the standard VARBINARY(16). I was recently asked to add a column to this table of VARCHAR(32) that stores the non-dashed UUID hex.
While doing this, I discovered that about half our UUIDs are v1, and the other half are v4. This means that for the first half, since they were all generated on a single machine, the randomness is a bit lacking (only the left-bytes timestamps are different). On the other hand, the newer half are basically completely random.
Is it worth putting an index on this column? If so, I'm struggling to decide how large that index should be (or maybe even what type of index).
VARBINARY(16)
version IS stored without dashes.WHERE c1 = UNHEX('expr')
will resolve the result ofUNHEX()
to a constant and use an index on c1 in a perfectly optimal way ... butWHERE hex(c1) = 'expr'
will scan every row of the table, evaluatingHEX(c1)
on each row to see if it matches'expr'
. The general rule is that if you do not use a column as the argument to a function, the optimizer will get it right.