Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand correctly, you're using UUIDs in your primary column? People will say that a regular (integer) primary key will be faster , but there's another way using MySQL's dark side. In fact, MySQL is faster using binary than anything else when indexes are required.</p> <p>Since UUID is 128 bits and is written as hexadecimal, it's very easy to speed up and store the UUID.</p> <p>First, in your programming language remove the dashes</p> <p>From <code>110E8400-E29B-11D4-A716-446655440000</code> to <code>110E8400E29B11D4A716446655440000</code>.</p> <p>Now it's 32 chars (like an MD5 hash, which this also works with).</p> <p>Since a single <code>BINARY</code> in MySQL is 8 bits in size, <code>BINARY(16)</code> is the size of a UUID (8*16 = 128).</p> <p>You can insert using:</p> <p><code>INSERT INTO Table (FieldBin) VALUES (UNHEX("110E8400E29B11D4A716446655440000"))</code></p> <p>and query using:</p> <p><code>SELECT HEX(FieldBin) AS FieldBin FROM Table</code></p> <p>Now in your programming language, re-insert the dashes at the positions 9, 14, 19 and 24 to match your original UUID. If the positions are always different you could store that info in a second field.</p> <p>Full example :</p> <pre><code>CREATE TABLE `test_table` ( `field_binary` BINARY( 16 ) NULL , PRIMARY KEY ( `field_binary` ) ) ENGINE = INNODB ; INSERT INTO `test_table` ( `field_binary` ) VALUES ( UNHEX( '110E8400E29B11D4A716446655440000' ) ); SELECT HEX(field_binary) AS field_binary FROM `test_table` </code></pre> <p>If you want to use this technique with any hex string, always do <code>length / 2</code> for the field length. So for a sha512, the field would be <code>BINARY (64)</code> since a sha512 encoding is 128 characters long.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload