开发者

MYSQL script does not run when I use variable instead of direct text

开发者 https://www.devze.com 2023-02-21 07:06 出处:网络
Maybe someone can help me with one problem. When I use a variable (@ZZ) in script then my query hangs and does not finish. If I use a direct text instead of variable, then query runs norm开发者_如何学

Maybe someone can help me with one problem. When I use a variable (@ZZ) in script then my query hangs and does not finish. If I use a direct text instead of variable, then query runs norm开发者_如何学运维ally. Can somebody tell me what is wrong with this variable?

SET @ZZ = 'asf:urhkgsdmbn.nbc,rtwyu:oneci_Xjhsdu_Hfduerksfgas20110322112751:462516432';
SET @XX = NULL;
USE some_schema;
SELECT SQL_NO_CACHE `hl`, @XX:=`id` FROM `doc` WHERE `uid` = @ZZ LIMIT 0,1;


Just a blind guess until you get something better... The WHERE clause is evaluated for each row and you have quite a lot of rows. If it contains a literal, the SQL optimizer may arrange things in such a way that the expression is evaluated only once and maybe it can do better use of indexes. However, if it contains a session variable it possibly needs to read the variable again and again for every row because it may have been changed.

:-?

0

精彩评论

暂无评论...
验证码 换一张
取 消