我已经编写了以下过程来在具有70万个条目的数据库上运行。 我有一个超时错误,所以我将超时延长到6000而不是600.这并没有解决它。我收到丢失的连接错误,然后我重复调用它给出了一个锁定等待超时错误。
是否有更有效的方法来执行相同的任务?
代码正在连接两个表,计算事件发生的次数,最后显示该计数大于零的百分比。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `EvaluateOutput4`()
BEGIN
declare v_max int default (Select count(*) FROM tracker.results);
declare v_counter int default 0;
start transaction;
while v_counter < v_max do
SET @v1 :=
(Select count(*)
FROM tracker.Meetings LEFT outer JOIN tracker.Visits on tracker.Meetings.visit1 =tracker.Visits.id or tracker.Meetings.visit2 =tracker.Visits.id
where (tracker.Meetings.user1= (Select VehicleID from tracker.results where RecordID= v_counter) or tracker.Meetings.user2=(Select VehicleID from tracker.results where RecordID= v_counter) )
and tracker.Visits.node=(Select Node from tracker.results where RecordID= v_counter)
and HOUR(time)>=(Select ArrivalTime from tracker.results where RecordID= v_counter) -1
and HOUR(time)<=(Select ArrivalTime from tracker.results where RecordID= v_counter)+1) ;
Update results set results.Count= @v1
Where results.RecordID=v_counter;
set v_counter = v_counter + 1;
end while;
SET @v2 := (Select count(*)from results where results.Count !=0 );
Set @v4 :=(@v2*100/v_max);
select @v4;
commit;
END