We discovered a Spotfire query that retrieves user authorization, which has the highest cost and is used more than 400 times an hour on our system. It contains an "order by" statement. If this statement is removed it performs 300% faster.
Although TIBCO states that it is hard to change, because the ordering is used in the whole application, The query is mal performing and should be improved.
This is the query:
********************** Query********************
with PARENT_GROUPS_4USER_CTE (GROUP_NAME, GROUP_ID, LEVEL, ISPRIM, PRIMARY_GROUP_ID)
as ( select g.GROUP_NAME, g.GROUP_ID, 1,
case when ((select PRIMARY_GROUP_ID from USERS where USER_ID = @P0) = g.GROUP_ID) then 1 else 0 end ISPRIM, g.PRIMARY_GROUP_ID
from GROUP_MEMBERS gm, GROUPS g where gm.MEMBER_USER_ID = @P1 and g.GROUP_ID = gm.GROUP_ID
union all select g.GROUP_NAME, g.GROUP_ID, 999,
case when ((select PRIMARY_GROUP_ID from USERS where USER_ID = @P2) = g.GROUP_ID)
then 1 else 0 end ISPRIM, g.PRIMARY_GROUP_ID from GROUPS g where g.GROUP_ID = @P3
union all select g.GROUP_NAME, g.GROUP_ID, LEVEL + 1, case when (cte.PRIMARY_GROUP_ID = g.GROUP_ID)
then 1 else 0 end ISPRIM, g.PRIMARY_GROUP_ID from GROUP_MEMBERS gm, PARENT_GROUPS_4USER_CTE cte, GROUPS g
where gm.MEMBER_GROUP_ID = cte.GROUP_ID and g.GROUP_ID = gm.GROUP_ID )
select pk.CATEGORY_NAME, pk.PREFERENCE_NAME, pk.CLASS_TYPE, pv.PREFERENCE_VALUE, pv.PREFERENCE_BLOB_VALUE, pv.LAST_MODIFIED
from ( select GROUP_NAME, GROUP_ID, LEVEL, ISPRIM, PRIMARY_GROUP_ID from PARENT_GROUPS_4USER_CTE ) as x, PREFERENCE_KEYS pk, PREFERENCE_VALUES pv
where pv.GROUP_ID = x.GROUP_ID and pv.PREFERENCE_ID = pk.PREFERENCE_ID
order by pk.CATEGORY_NAME, pk.PREFERENCE_NAME, x.LEVEL, ISPRIM desc, x.GROUP_NAME
************************************************************
Hi Ernst,
Is the query performance now working as expected, after the indexing rebuild in the database, as suggested by TIBCO support?
Thanks