Thanks Joram.
In the process of improving the performance of the query, we are also modifying Task.xml file to remove the "distinct" from the select statement. "distinct" seems to go to table scan instead of using the index. I noticed that there are insert and update statements in that file. I am wondering if I can modify those to change my insert and update instead of triggers or events. Both triggers and events will slow down creation/modification of task where as modification of insert statement/update statement will have no effect on performance.
I am thinking something like this (additions bolded) - I think I need to figure out mybatis syntax to make it work correctly.
<insert id="insertTask" parameterType="org.activiti.engine.impl.persistence.entity.TaskEntity">
insert into ${prefix}ACT_RU_TASK (ID_, REV_, NAME_, PARENT_TASK_ID_, DESCRIPTION_, PRIORITY_, InvertedPriority_, CREATE_TIME_, OWNER_,
ASSIGNEE_, DELEGATION_, EXECUTION_ID_, PROC_INST_ID_, PROC_DEF_ID_, TASK_DEF_KEY_, DUE_DATE_, SUSPENSION_STATE_)
values (#{id, jdbcType=VARCHAR},
1,
#{name, jdbcType=VARCHAR},
#{parentTaskId, jdbcType=VARCHAR},
#{description, jdbcType=VARCHAR},
#{priority, jdbcType=INTEGER},
#{0-priority, jdbcType=INTEGER},
#{createTime, jdbcType=TIMESTAMP},
#{owner, jdbcType=VARCHAR},
#{assignee, jdbcType=VARCHAR},
#{delegationStateString, jdbcType=VARCHAR},
#{executionId, jdbcType=VARCHAR},
#{processInstanceId, jdbcType=VARCHAR},
#{processDefinitionId, jdbcType=VARCHAR},
#{taskDefinitionKey, jdbcType=VARCHAR},
#{dueDate, jdbcType=TIMESTAMP},
#{suspensionState, jdbcType=INTEGER}
)
</insert>