Playhouse proposal for optimised MySQL UUIDField
This is quite neat! I will pass but hopefully Google will help anyone else find this who may be interested.

I spent the day putting together the most optimised method of storing UUIDs in MySQL/MariaDB, and ended up implementing some research by Percona in which bits are shifted around to give better index performance.

I've since decided to switch over to ObjectIDs instead, but thought I'd share this code. If it doesn't get included in the playhouse then at least it's here for others in future. 

The only remaining performance tweak might be storing it as a BINARY rather than BLOB, as this _may_ perform better under MySQL/Maria (tbc).

I'm not particularly happy about this approach, as it feels quite dirty and inelegant, but it does give the raw performance for those that need it. Also, this has only been tested on Python 3.

``` py

class UUIDField(BlobField):
    """
    Optimized storage for UUID fields in MySQL, based on research by Percona
    https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/

    XXX: Should storage use BINARY instead of BLOB? Needs benchmark
    """

    def db_value(self, value):
        """
        Convert UUID to binary blob

        >>> db_value('12345678-1234-5678-1234-567812345678')
        >>> db_value(uuid.uuid4())
        >>> db_value('lsjfhgjg')
        Exception: ValueError
        """

        # ensure we have a valid UUID
        if not isinstance(value, UUID):
            value = UUID(value)

        # reconstruct for optimal indexing
        parts = str(value).split("-")
        reordered = ''.join([parts[2], parts[1], parts[0], parts[3], parts[4]])
        value = binascii.unhexlify(reordered)
        return super(UUIDField, self).db_value(value)

    def python_value(self, value):
        """
        Convert binary blob to UUID instance
        """
        u = binascii.b2a_hex(value)
        value = u[8:16] + u[4:8] + u[0:4] + u[16:22] + u[22:32]
        return UUID(value)


class UUIDFieldTestCase(unittest.TestCase):
    def test_random(self):
        uuids = [ uuid4() for x in range(100) ]
        for value in uuids:
            a = UUIDField()
            as_binary = a.db_value(value)
            as_result = a.python_value(as_binary)
            self.assertEquals(value, as_result)
            self.assertEquals(str(value), str(as_result))

    def test_single(self):
        value = UUID('AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE')
        a = UUIDField()
        as_binary = a.db_value(value)
        as_result = a.python_value(as_binary)
        self.assertEquals(value, as_result)
        self.assertEquals(str(value), str(as_result))
```
