UNHEX() é uma função
, portanto, você pode fazer algo como SET @var = '41';
SELECT UNHEX(@var);
SELECT UNHEX(hex_column) FROM my_table;
X , por outro lado, é a sintaxe para um literal hexadecimal
. Você não pode fazer isso:SET @var = '41';
SELECT example@sqldat.com; -- error (string litteral expected)
SELECT X'@var'; -- error (`@` is not a hexadecimal digit)
SELECT X(@var); -- returns NULL, not too sure about the reason... [edit: but this is probably why you are inserting NULL values]
SELECT X(hex_column) FROM my_table; -- returns NULL as well
Isso explica por que você sempre obtém melhor desempenho com
X :você está usando uma construção de linguagem em vez de uma chamada de função. X não precisa avaliar uma variável, pois espera uma string literal.