-- 流程状态
CREATE INDEX IDX_BPMPROSTATUS_INSTNODEID ON BPM_PRO_STATUS (ACTINSTID,NODEID);
-- 流程意见
create index IDX_TASKOPINION_ACTINSTID on bpm_task_opinion(ACTINSTID);
create index IDX_TASKOPINION_TASKID on bpm_task_opinion(TASKID);
-- 流程堆栈
CREATE INDEX IDX_BPMSTACKINST_depth ON BPM_EXE_STACK (actInstId,depth);
CREATE INDEX IDX_BPMSTACK_PARENTID ON BPM_EXE_STACK (parentId);
-- 表单运行时
CREATE INDEX IDX_BPMFORMRUN_INSTANCENODEID ON BPM_FORM_RUN (ACTINSTANCEID,ACTNODEID);
-- 会签数据
CREATE INDEX IDX_BPMTKSIGNDATA_ACTDEFNODEID ON BPM_TKSIGN_DATA  (ACTINSTID,NODEID);
CREATE INDEX IDX_BPMTKSIGNDATA_TASKID ON BPM_TKSIGN_DATA  (TASKID);
-- 催办任务状态
CREATE INDEX IDX_REMINDERSTATE_TASKUSERID ON BPM_TASK_REMINDERSTATE (TASKID,USERID);
-- 流程实例扩展
CREATE INDEX IDX_PRORUN_INSTANCEID ON BPM_PRO_RUN (ACTINSTID);
CREATE INDEX IDX_PROCESSRUN_CREATORID ON BPM_PRO_RUN (CREATORID);
-- 流程实例扩展历史
CREATE INDEX IDX_PRORUN_HIS_INSTANCEID ON BPM_PRO_RUN_HIS (ACTINSTID);
CREATE INDEX IDX_PROCESSRUN_HIS_CREATORID ON BPM_PRO_RUN_HIS (CREATORID);
-- 流程运行日志
CREATE INDEX IDX_RUNLOG_USERID ON BPM_RUN_LOG (USERID);
CREATE INDEX IDX_RUNLOG_RUNID ON BPM_RUN_LOG (RUNID);
-- 邮件设定
CREATE INDEX IDX_MAILUSERSETTING ON OUT_MAIL_USER_SETING (USERID);
-- 邮件联系人
CREATE INDEX IDX_MAILLINKMAN ON OUT_MAIL_LINKMAN (USERID);
-- 邮件
CREATE INDEX IDX_OUTMAIL_USERID ON OUT_MAIL (USERID);
-- 发送消息
CREATE INDEX IDX_MSGSEND_USERID ON SYS_MSG_SEND (USERID);
-- 消息接收人
CREATE INDEX IDX_MSGRECEIVER_MESSAGEID ON SYS_MSG_RECEIVER (MESSAGEID);
CREATE INDEX IDX_MSGRECEIVER_RECEIVERID ON SYS_MSG_RECEIVER (RECEIVERID);
-- 消息读取
CREATE INDEX IDX_MSGREAD_RECEIVERID ON SYS_MSG_READ (RECEIVERID);
CREATE INDEX IDX_MSGREAD_MESSAGEID ON SYS_MSG_READ (MESSAGEID);
-- 消息回复
CREATE INDEX IDX_MSG_REPLY_MESSAGEID ON SYS_MSG_REPLY (MESSAGEID);
CREATE INDEX IDX_MSG_REPLY_REPLYID ON SYS_MSG_REPLY (REPLYID);

-- 角色和资源的映射
CREATE INDEX IDX_ROLERES_RESID ON SYS_ROLE_RES (RESID);
CREATE INDEX IDX_ROLERES_ROLEID ON SYS_ROLE_RES (ROLEID);
-- 资源
CREATE INDEX IDX_SYSRES_SYSTEMID ON SYS_RES  (SYSTEMID);
CREATE INDEX IDX_SYSRES_PARENTID ON SYS_RES  (PARENTID);
CREATE INDEX IDX_RESURL_RESID ON SYS_RESURL  (RESID);
-- 用户参数
CREATE INDEX IDX_USERPARAM_USERID ON SYS_USER_PARAM  (USERID);
CREATE INDEX IDX_USERPARAM_PARAMID ON SYS_USER_PARAM  (PARAMID);
-- 下属
CREATE INDEX IDX_USERUNDER_USERID ON SYS_USER_UNDER  (USERID);
CREATE INDEX IDX_USERUNDER_UNDERUSERID ON SYS_USER_UNDER  (UNDERUSERID);
-- 组织
create index idx_sysorg_ORGSUPID on SYS_ORG (ORGSUPID);
-- 组织和角色的映射
CREATE INDEX IDX_ORGROLE_ORGID ON SYS_ORG_ROLE  (ORGID);
CREATE INDEX IDX_ORGROLE_ROLE ON SYS_ORG_ROLE  (ROLEID);
-- 表单字段
CREATE INDEX IDX_FORMFIELD_TABLEID ON BPM_FORM_FIELD  (TABLEID);
-- 组织可授权角色
CREATE INDEX IDX_ORGROLEMANAGE_ORGID ON SYS_ORG_ROLEMANAGE  (ORGID);
CREATE INDEX IDX_ORGROLEMANAGE_ROLEID ON SYS_ORG_ROLEMANAGE  (ROLEID);
-- 表单权限
CREATE INDEX IDX_FORMRIGHTS_FORMDEFID ON BPM_FORM_RIGHTS  (FORMKEY);
-- 代理
create index IDX_AGENTCON_SETTINGID on BPM_AGENT_CONDITION (SETTINGID);
create index IDX_AGENTDEF_SETTINGID on BPM_AGENT_DEF (SETTINGID);
create index IDX_AGENTSETTING_AUTHID on BPM_AGENT_SETTING (AUTHID);
create index IDX_AGENTSETTING_AGENTID ON BPM_AGENT_SETTING(AGENTID);

-- 业务中间表
create index IDX_BUSLINK_ORGID on BPM_BUS_LINK (BUS_ORG_ID);
create index IDX_BUSLINK_PK on BPM_BUS_LINK (BUS_PK);
create index IDX_BUSLINK_PKSTR on BPM_BUS_LINK (BUS_PKSTR);
create index IDX_BUSLINK_STARTID on BPM_BUS_LINK (BUS_CREATOR_ID);
-- 抄送转发
create index IDX_PRO_CPTO_RUNID on BPM_PRO_CPTO (RUN_ID);
create index IDX_PRO_CPTO_UID on BPM_PRO_CPTO (CC_UID);
-- 转办代理
CREATE INDEX IDX_TASKEXE_INSTID ON BPM_TASK_EXE (ACT_INST_ID );
CREATE INDEX IDX_TASKEXE_RUNID ON BPM_TASK_EXE ( RUNID );
-- 任务是否已读
CREATE INDEX IDX_TASKREAD_INSTTASK ON BPM_TASK_READ (ACTINSTID , TASKID );
CREATE INDEX IDX_TASKREAD_TASKUSER ON BPM_TASK_READ ( TASKID , USERID );
-- 用户角色关联。
CREATE INDEX IDX_USERROLE_ROLE ON SYS_USER_ROLE (ROLEID);
CREATE INDEX IDX_USERROLE_USER ON SYS_USER_ROLE (userid);
-- 流程流转
create index idx_transto_taskid on BPM_PRO_TRANSTO (taskid);
create index idx_transto_instid on BPM_PRO_TRANSTO (actInstId);
-- 用户帐号
create index idx_sysuser_account on SYS_USER (account);
-- 任务通知人
create index idx_commureceiver_opinionid on BPM_COMMU_RECEIVER(OPINIONID);
create index idx_commureceiver_taskid on BPM_COMMU_RECEIVER(taskid);
-- 流程定义
create index idx_bpmdef_actdefid on BPM_DEFINITION( actDefId);
create index idx_bpmdef_defkey on BPM_DEFINITION( actDefKey);
-- 监控项目
create index idx_mongroupitem_group on  BPM_MON_GROUPITEM(GROUPID);
create index idx_mongroupitem_flowkey on  BPM_MON_GROUPITEM(flowkey);

-- BPM_MON_ORGROLE
create index idx_monorgrole_GROUPID on  BPM_MON_ORGROLE(GROUPID);
create index idx_monorgrole_ROLEID on  BPM_MON_ORGROLE(ROLEID);
create index idx_monorgrole_ORGID on  BPM_MON_ORGROLE(ORGID);
-- BPM_NODE_BTN
create index idx_nodebtn_defid on BPM_NODE_BTN(defId);
-- BPM_NODE_SCRIPT
create index idx_nodescript_defid on BPM_NODE_SCRIPT(ACTDEFID);
-- 节点配置
create index idx_nodeset_defid on BPM_NODE_SET (defid);
-- 人员
create index idx_nodeuser_conditionid on BPM_NODE_USER(CONDITIONID);
-- 节点人员条件
create index idx_usercondition_actdefid on BPM_USER_CONDITION(ACTDEFID);
create index idx_usercondition_setid on BPM_USER_CONDITION(SETID);
-- BPM_TASK_FORK
create index idx_taskfork_actinstid on BPM_TASK_FORK(ACTINSTID);
-- 印章权限
create index idx_sealright_SEALID on SYS_SEAL_RIGHT(SEALID);
create index idx_sealright_RIGHTID on SYS_SEAL_RIGHT(RIGHTID);
-- 岗位和个人权限
create index idx_userpos_userid on SYS_USER_POS (userid);
create index idx_userpos_posid on SYS_USER_POS (posid);

-- 工时设定
create index idx_worktime_SETTINGID on SYS_WORKTIME(SETTINGID);

-- SYS_ORG_PARAM
create index idx_orgparam_orgid on SYS_ORG_PARAM(ORGID);
create index idx_orgparam_PARAMID on SYS_ORG_PARAM(PARAMID);


-- Drop indexes 
-- drop index ACT_IDX_TASK_PROCDEF;
-- drop index ACT_IDX_HI_ACT_INST_END;
-- drop index ACT_IDX_HI_ACT_INST_START;
CREATE INDEX IDX_ACTTASK_USERID ON ACT_RU_TASK(ASSIGNEE_);
create index IDX_HIACTINST_ASSIGNEE on ACT_HI_ACTINST (assignee_);
create index IDX_BPMDEF_KEY on BPM_DEFINITION (defkey);

-- 国际化
-- CREATE INDEX IDX_BPMFORMLANGUAGE_FORMID ON BPM_FORM_LANGUAGE (FORMID);
-- create index IDX_SYSLANRES_RESID on SYS_LAN_RES (RES_ID);
-- create index IDX_SYSLANRES_LANTYPE on SYS_LAN_RES (LAN_TYPE);

create index IDX_ACTTASK_PARENTID on act_ru_task(PARENT_TASK_ID_);
create index IDX_PROCESSRUN_HIS_PK on bpm_pro_run_his(businessKey);

CREATE UNIQUE INDEX IDX_SYS_POS_CODE ON SYS_POS(POSCODE);

CREATE UNIQUE INDEX IDX_SYS_JOB_CODE ON SYS_JOB(JOBCODE);

CREATE UNIQUE INDEX IDX_SYS_PARAM_KEY ON SYS_PARAM(PARAMKEY);

CREATE INDEX  NODEID_FLOWKEY_INDEX ON  BPM_NEWFLOW_TRIGGER (FLOWKEY, NODEID);



CREATE INDEX IDX_VIEW_ALIAS ON SYS_QUERY_VIEW (  SQL_ALIAS ASC,    ALIAS ASC);
CREATE INDEX IDX_METAFIELD_SQLID ON SYS_QUERY_METAFIELD (   SQL_ID ASC);
CREATE INDEX IDX_FIELDSETTING_VIEWID ON SYS_QUERY_FIELDSETTING (   VIEW_ID ASC);
CREATE INDEX ID_HISTORYDATA_OBJID ON SYS_HISTORY_DATA (OBJ_ID ASC);
CREATE INDEX GROUPID_INDEX ON SYS_READ_RECORD (GROUPID ASC);
CREATE INDEX OBJECTID_INDEX ON SYS_READ_RECORD (OBJECTID ASC);
CREATE UNIQUE INDEX  OBJECTID_USER_INDEX ON SYS_READ_RECORD (OBJECTID ASC, USERID ASC);



CREATE INDEX MOBILEFORM_KEY ON BPM_MOBILE_FORM_DEF
(
   FORM_KEY
);

