Performance Issue / Bug ? Querying tasks for process variable values for single variable results in lots of joins

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2014 01:18 PM
Hi All,
I am using TaskQuery to find tasks which belong to processes having certain set of possible process variable values for a single variable
For e.g.,
TaskQuery query = taskService.createTaskQuery();
query.processVariableValueEquals("a1", "value1");
query.processVariableValueEquals("a1", "value2");
query.processVariableValueEquals("a1", "value3");
query.processVariableValueEquals("a1", "value4");
long count = query.count();
This call results in following SQL
select count(distinct RES.ID_)
FROM ACT_RU_TASK RES
INNER JOIN ACT_RU_VARIABLE A0 on RES.PROC_INST_ID_ = A0.PROC_INST_ID_
INNER JOIN ACT_RU_VARIABLE A1 on RES.PROC_INST_ID_ = A1.PROC_INST_ID_
INNER JOIN ACT_RU_VARIABLE A2 on RES.PROC_INST_ID_ = A2.PROC_INST_ID_
INNER JOIN ACT_RU_VARIABLE A3 on RES.PROC_INST_ID_ = A3.PROC_INST_ID_
WHERE A0.TASK_ID_ is null and A0.NAME_= 'a1' and A0.TYPE_ = 'string' and A0.TEXT_='value1'
AND
A1.TASK_ID_ is null and A1.NAME_= 'a1' and A1.TYPE_ = 'string' and A1.TEXT_ = 'value1'
AND
A2.TASK_ID_ is null and A2.NAME_= 'a1' and A2.TYPE_ = 'string' and A2.TEXT_ = 'value1'
AND
A3.TASK_ID_ is null and A3.NAME_= 'a1' and A3.TYPE_ = 'string' and A3.TEXT_ = 'value1';
As you can see that as the number of variables values increase, so does the number of joins.
This results in huge time for the query so it won't be practical to use this method for many values.
Is this a bug or there a better way of doing this ?
I am using TaskQuery to find tasks which belong to processes having certain set of possible process variable values for a single variable
For e.g.,
TaskQuery query = taskService.createTaskQuery();
query.processVariableValueEquals("a1", "value1");
query.processVariableValueEquals("a1", "value2");
query.processVariableValueEquals("a1", "value3");
query.processVariableValueEquals("a1", "value4");
long count = query.count();
This call results in following SQL
select count(distinct RES.ID_)
FROM ACT_RU_TASK RES
INNER JOIN ACT_RU_VARIABLE A0 on RES.PROC_INST_ID_ = A0.PROC_INST_ID_
INNER JOIN ACT_RU_VARIABLE A1 on RES.PROC_INST_ID_ = A1.PROC_INST_ID_
INNER JOIN ACT_RU_VARIABLE A2 on RES.PROC_INST_ID_ = A2.PROC_INST_ID_
INNER JOIN ACT_RU_VARIABLE A3 on RES.PROC_INST_ID_ = A3.PROC_INST_ID_
WHERE A0.TASK_ID_ is null and A0.NAME_= 'a1' and A0.TYPE_ = 'string' and A0.TEXT_='value1'
AND
A1.TASK_ID_ is null and A1.NAME_= 'a1' and A1.TYPE_ = 'string' and A1.TEXT_ = 'value1'
AND
A2.TASK_ID_ is null and A2.NAME_= 'a1' and A2.TYPE_ = 'string' and A2.TEXT_ = 'value1'
AND
A3.TASK_ID_ is null and A3.NAME_= 'a1' and A3.TYPE_ = 'string' and A3.TEXT_ = 'value1';
As you can see that as the number of variables values increase, so does the number of joins.
This results in huge time for the query so it won't be practical to use this method for many values.
Is this a bug or there a better way of doing this ?
Labels:
- Labels:
-
Archive
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2014 03:33 AM
Hi All,
Any comments please ? This issue is very important for us !
Any comments please ? This issue is very important for us !
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2014 02:38 AM
Hi Shailendra.
In case that you can create your own query (more efficient one), you can use native query support.
http://www.activiti.org/userguide/#queryAPI
Regards
Martin
In case that you can create your own query (more efficient one), you can use native query support.
http://www.activiti.org/userguide/#queryAPI
Regards
Martin

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2014 05:36 AM
Thanks Martin. As of now I will be using native query support.
