mysql - Need to use temporary variable to make REPLACE of SUBSTRING_INDEX work -


we're running mysql 5.5.47 on number of debian servers. on of them, we're seeing following strange behavior:

mysql> set @tkey:='ardard:fae590c4.ffa2.11e5.a318.0cc47a39aeb4-1460351116';   mysql> select replace(substring_index(substring_index(@tkey,':',-1),'-',1), '.','-') guid; +--------------------------------------+ | guid                                 | +--------------------------------------+ | fae5a2.1--0cc47a 9ae47a 9aeb4a 9aeb4 | +--------------------------------------+ 

this supposed extract middle part of @tkey (between : , -) , replace periods hyphens. spaces coming from? other parts of result seem jumbled up: 9aeb4 has been duplicated, a2.1 has been shifted left.

this doesn't happen if assign substring_index intermediate variable.

mysql> set @temp = substring_index(substring_index(@tkey,':',-1),'-',1); mysql> select replace(@temp, '.', '-') guid; +--------------------------------------+ | guid                                 | +--------------------------------------+ | fae590c4-ffa2-11e5-a318-0cc47a39aeb4 | +--------------------------------------+ 

this happens on our production servers. can't reproduce on our development server or sqlfiddle. compared server variables, , there no differences should affect behavior of string functions (there differences in character set , collation variables, changed dev server match production server , still couldn't replicate error.

on production server running mysql 5.5.41 different wrong result:

mysql> select replace(substring_index(substring_index(@tkey,':',-1),'-',1), '.','-') guid; +--------------------------------------+ | guid                                 | +--------------------------------------+ | fae590c4-ffa2-11e5-a318-0cc47a 9aeb4 | +--------------------------------------+ 

this correct except there's space in place of of last 3.

can explain this? mysql bug? couldn't find @ bugs.mysql.com.

this appears bug fixed in mysql 5.6.5. there's similar bug report regarding lower(substring_index(...)). closed comment:

noted in 5.6.5 changelog.

the result of substring_index() missing characters when used argument conversion functions such lower().

i suspect underlying cause pointer misuse resulting in buffer overflow , undefined behavior. haven't corrupted long-lived memory in server.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -