I want to create a generated column in MySQL/MariaDB as follows:
ALTER TABLE example ADD uuid uuid AS
(UNHEX(INSERT(
INSERT(@hash:=MD5(username),
13, 2, HEX(CONV(SUBSTR(@hash, 13, 2), 16, 10) & 0x0f | 0x30)),
17, 2, HEX(CONV(SUBSTR(@hash, 17, 2), 16, 10) & 0x3f | 0x80))))
This computation only depends on the username
field and is deterministic, yet MySQL won’t allow it as a generated column because it uses local variables. I don’t want to compute the hash three times because its a waste of resources so are there any workarounds around this and if not could someone explain the reason for this limitation?
1