Although, someone may have ideas of tuning,
I thought that all the effort of tuning without modifying bad desined/coded query would be in vain(much effort and a little gain).
Though it may be difficult to replace the query,
IF you can replace the query,
this might be a starting example to improve the query.
Before the improvement, there are some points to be clear on the requirements/specifications of the query and the design of the tables.
1) How to select/specify QP1, QP2, QP3.
What data/values in STRING_VALUE column.
2) How to choose a corresponding row from UNION ALLed sub-selects inside (...) WI.
They are rows selected from WPSBE00.SWI_T which are ACCESS_KEY IN (50 , 51 , 52).
3) Order of choice in final result.
The query must be assumed multiple rows returned.
Because, it selects a row from multiple rows by "FETCH FIRST 1 ROWS ONLY"
Example 0: Not complete, need additional code and modifications before execution.
Code:
SELECT -- DISTINCT
TA.TKIID AS ID
, TA.APPLIC_NAME AS application_name
, TA.NAME_SPACE AS namespace
, TT.TKTID AS template_ID
, TT.NAME AS template_Name
, TA.OWNER AS owner
, TA.ORIGINATOR AS originator
, TTD.DISPLAY_NAME AS title
, TTD.DESCRIPTION AS description
, TA.STARTED AS creation_date
, TA.LAST_MODIFIED AS modification_date
, TA.PRIORITY AS priority
, TA.STATE AS state
, TA.IS_ESCALATED AS escalated
/* May need to Add expression(s)
to select/specify QP1, QP2, QP3.
, QP1.NUMBER_VALUE AS dealing_id
, QP2.STRING_VALUE AS priority_date
, QP3.STRING_VALUE AS urgency_indicator
*/
, COALESCE(
RU.OWNER_ID
, WI.OWNER_ID ) AS Owner_ID
, WI.EVERYBODY
, WI.GROUP_NAME
, WI.REASON
FROM
WPSBE00.TASK1 TA
INNER JOIN
WPSBE00.TASK_TEMPL TT
ON TT.TKTI D = TA.TKTID
LEFT JOIN
WPSBE00.TASK_TEMPL_DESC TTD
ON TTD.TKTID = TT.TKTID
LEFT JOIN
WPSBE00.QUERY_PROPERTY QP
ON QP.PIID = TA.CONTAINMENT_CTX_ID
AND <...>
INNER JOIN
WPSBE00.SWI_T WI
ON WI.WSID
IN (TA.WSID_1 , TA.WSID_2)
AND WI.ACCESS_KEY
IN (50 , 51 , 52)
LEFT JOIN
WPSBE00.RETRIEVED_USER_T RU
ON WI.ACCESS_KEY = 50
AND RU.QIID = WI.QIID
/*
WHERE TA.TKIID ...
and/or
ORDER BY ...
*/
FETCH FIRST 1 ROWS ONLY
WITH UR
;