begindeclare hprocessinstanceid bigint default 0; -- 历史流程实例iddeclare hprocessinstanceidstarttime char default ''; -- 历史流程实例启动时间declare hprocessinstanceidendtime char default ''; -- 历史流程实例结束时间declare hactinstid bigint default 0; -- 历史活动实例iddeclare htaskid bigint default 0; -- 历史人工任务iddeclare hvarid bigint default 0; -- 历史流程变量iddeclare rexecutionid bigint default 0; -- 正在执行流程实例iddeclare rvarid bigint default 0; -- 正在执行流程变量iddeclare rtaskid bigint default 0; -- 正在执行人工任务iddeclare rswinmlanceid bigint default 0; -- 泳道id,为了删除partation表记录,本项目无记录declare processcompleteflag int default 0; -- 流程是否结束标识declare taskcompleteflag int default 0; -- 任务是否结束标识declare doneflag int default 0; -- 完成标识,0:未完成;1:已完成declare notfound int default 0;-- 是否未找到数据 标记-- 启动事物-- start transaction;/* 声明历史流程实例的游标 */declare hprocessinstancers cursor for select dbid_,start_,end_ from jbpm4_hist_procinst where start_>='2014-0-0 0:0:0' and start_<'2015-0-0 0:0:0';/* 声明历史活动实例的游标 */declare hactinstrs cursor for select dbid_,htask_ from jbpm4_hist_actinst where hproci_=hprocessinstanceid;/* 声明历史活动实例的游标 */declare htaskrs cursor for select dbid_ from jbpm4_hist_task where dbid_=hactinstid;/* 声明历史活动实例的游标 */declare hvarrs cursor for select dbid_ from jbpm4_hist_var where htask_=rtaskid;/** 声明正在执行流程实例的游标(历史表中因为各种原因未完成的) **/declare rexecutionrs cursor for select dbid_ from jbpm4_execution where dbid_=hprocessinstanceid;/** 声明正在执行流程变量的游标(只删除2014年条件下由于各种原因未完成的流程实例所对应的流程变量) */declare rvarrs cursor for select dbid_ from jbpm4_variable where execution_=hprocessinstanceid;/** 声明正在执行的人工任务的游标(只是2014年开始的流程实例所对应的) **/declare rtaskrs cursor for select dbid_ from jbpm4_task where dbid_=rtaskid;/** 声明泳道的结果集游标,为了删除paritation表,该项目没有记录,实际删除条数为0 **/declare rswinmlancers cursor for select dbid_ from jbpm4_swimlane where dbid_=rswinmlanceid;/* 异常处理 */declare continue handler for sqlstate '02000' set doneflag = 1;/** 删除s,使用嵌套循环..... **/open hprocessinstancers;fetch hprocessinstancers into hprocessinstanceid,hprocessinstanceidstarttime,hprocessinstanceidendtime;-- 获取历史流程实例表的数据数据repeatif hprocessinstanceidendtime='' then-- 没有结束,执行删除正在执行的流程实例表/** 1.查询正在执行的流程实例记录s **/set rexecutionid=hprocessinstanceid; -- 未完成的流程实例与正在执行的流程实例id做对应open rexecutionrs;fetch rexecutionrs into rexecutionid;repeat/** 2.查询该流程实例下的所有正在执行的流程变量记录s 2**/open hvarrs;fetch hvarrs into rvarid;repeat/** 3.删除正在执行的流程变量所对应的人工任务记录s 3**/delete from jbpm4_task where dbid_=rvarid;/** 3.删除正在执行的流程变量所对应的人工任务记录e 3**/delete from jbpm4_variable where dbid_=rvarid; -- 单条删除流程变量记录fetch hvarrs into rvarid;until doneflag end repeat;close hvarrs;/** 2.查询该流程实例下的所有正在执行的流程变量记录e 2**/delete from jbpm4_execution where dbid_=rexecutionid; -- 单条删除流程对象记录fetch rexecutionrs into rexecutionid;until doneflag end repeat;close rexecutionrs;end if;/*** ======删除历史流程记录表相关数据===== **//** 1.查询活动实例表 s **/open hactinstrs;fetch hactinstrs into hactinstid,htaskid;repeat/** 2.查询历史人工活动表记录s **/open htaskrs;fetch htaskrs into htaskid;repeat/** 3.删除历史人工任务 **/delete from jbpm4_hist_task where dbid_=htaskid;fetch htaskrs into htaskid;until doneflag end repeat;close htaskrs;/** 2.查询历史人工活动表记录s **/fetch hactinstrs into hactinstid,htaskid;until doneflag end repeat;close hactinstrs;/** 1.查询活动实例表 e **//*** ======删除历史流程记录表相关数据===== **//** 删除历史活动实例表 **/delete from jbpm4_hist_actinst where hproci_=hprocessinstanceid;set doneflag=0;fetch hprocessinstancers into hprocessinstanceid,hprocessinstanceidstarttime,hprocessinstanceidendtime;-- 获取历史流程实例表的数据数据until doneflag end repeat;close hprocessinstancers;end
使用嵌套之后,10万-百万条数据量删除非常慢,有什么解决方法没有?