{"id":215,"date":"2009-04-21T13:42:39","date_gmt":"2009-04-21T19:42:39","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=215"},"modified":"2009-04-21T13:42:39","modified_gmt":"2009-04-21T19:42:39","slug":"mysql-5-weirdness","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2009\/04\/21\/mysql-5-weirdness\/","title":{"rendered":"MySql 5 weirdness .."},"content":{"rendered":"<p>So, a user was having some issues with their ranks being calculated totally wrong. \u00a0They were seeing numerous games against themselves. \u00a0Turns out this was the issue &#8211; MySql treats varchar() text with trailing spaces the same as varchar text without trailing spaces. \u00a0So the name &#8220;philhassey&#8221; is the same as &#8220;philhassey &#8221; or &#8220;philhassey \u00a0 \u00a0 &#8221; in a &#8216;select * from ip_stats3 where name = ?&#8217; type of query. \u00a0Here&#8217;s a MySQL session below to demonstrate.<\/p>\n<p>mysql&gt; describe ip_stats3;<\/p>\n<p>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/p>\n<p>| Field \u00a0 | Type \u00a0 \u00a0 \u00a0 \u00a0| Null | Key | Default | Extra |<\/p>\n<p>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/p>\n<p>| name \u00a0 \u00a0| varchar(32) | NO \u00a0 | PRI | NULL \u00a0 \u00a0| \u00a0 \u00a0 \u00a0 |\u00a0<\/p>\n<p>| data \u00a0 \u00a0| longblob \u00a0 \u00a0| YES \u00a0| \u00a0 \u00a0 | NULL \u00a0 \u00a0| \u00a0 \u00a0 \u00a0 |\u00a0<\/p>\n<p>| s_rank \u00a0| int(11) \u00a0 \u00a0 | YES \u00a0| \u00a0 \u00a0 | NULL \u00a0 \u00a0| \u00a0 \u00a0 \u00a0 |\u00a0<\/p>\n<p>| s_win \u00a0 | int(11) \u00a0 \u00a0 | YES \u00a0| \u00a0 \u00a0 | NULL \u00a0 \u00a0| \u00a0 \u00a0 \u00a0 |\u00a0<\/p>\n<p>| s_value | int(11) \u00a0 \u00a0 | YES \u00a0| \u00a0 \u00a0 | NULL \u00a0 \u00a0| \u00a0 \u00a0 \u00a0 |\u00a0<\/p>\n<p>| s_total | int(11) \u00a0 \u00a0 | YES \u00a0| \u00a0 \u00a0 | NULL \u00a0 \u00a0| \u00a0 \u00a0 \u00a0 |\u00a0<\/p>\n<p>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/p>\n<p>6 rows in set (0.00 sec)<\/p>\n<p>\u00a0<\/p>\n<p>mysql&gt; select name from ip_stats3 where name = &#8216;philhassey &#8216;;<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| name \u00a0 \u00a0 \u00a0 |<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| philhassey |\u00a0<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>1 row in set (0.00 sec)<\/p>\n<p>\u00a0<\/p>\n<p>mysql&gt; select name from ip_stats3 where name = &#8216;philhassey&#8217;;<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| name \u00a0 \u00a0 \u00a0 |<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| philhassey |\u00a0<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>1 row in set (0.00 sec)<\/p>\n<p>\u00a0<\/p>\n<p>mysql&gt; select name from ip_stats3 where name like &#8216;philhassey&#8217;;<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| name \u00a0 \u00a0 \u00a0 |<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| philhassey |\u00a0<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>1 row in set (0.00 sec)<\/p>\n<p>\u00a0<\/p>\n<p>mysql&gt; select name from ip_stats3 where name like &#8216;philhassey &#8216;;<\/p>\n<p>Empty set (0.00 sec)<\/p>\n<p>\u00a0<\/p>\n<p>mysql&gt; select name from ip_stats3 where name like &#8216;philhassey%&#8217;;<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| name \u00a0 \u00a0 \u00a0 |<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| philhassey |\u00a0<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>1 row in set (0.00 sec)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, a user was having some issues with their ranks being calculated totally wrong. \u00a0They were seeing numerous games against themselves. \u00a0Turns out this was the issue &#8211; MySql treats varchar() text with trailing spaces the same as varchar text without trailing spaces. \u00a0So the name &#8220;philhassey&#8221; is the same as &#8220;philhassey &#8221; or &#8220;philhassey [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-215","post","type-post","status-publish","format-standard","hentry","category-bugs"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":0,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}