Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

MySQL - Same SQL query fast ,but very slow in Stored Procedures?

I had been stucked in this problem for more than 10 hours!

I had tried to add or remove the '@' before variables or params but nothing happened.

I really dont know whats going wrong , help please !

QUERY

select ClientId into @v1 from by_test_db1.recordcd where SN = 'abc';
select ClientId into @v2 from by_test_db1.log      where SN = 'abc';
select concat(@v1,@v2);

SP

delimiter $$
create procedure TEST(newSN varchar(50))
begin 
    declare v1 varchar(50);
    declare v2 varchar(50);
     start transaction;
        select ClientId into v1 from by_test_db1.recordcd where SN = newSN;
        select ClientId into v2 from by_test_db1.log      where SN = newSN;
        select concat(v1,v2);
     commit;
end $$
delimiter ;

MySQL version 5.7

Through there are 100 million rows in the recordcd table ,the QUERY just ran fast and well, but the SP was running so slowly that it timed out and reported an error

Error Code: 2013. Lost connection to MySQL server during query

I tried many ways but none of them worked, I don't know why there is such a ridiculous situation , I dont even know how to search the answer to this situation, so hope you big guys can help me , thank u.

question from:https://stackoverflow.com/questions/65936707/mysql-same-sql-query-fast-but-very-slow-in-stored-procedures

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...