With 40+ million WOANCESTOR records this might not be as good as you might think.
When you are compiling a query the first thing you must do is understand the unique key of a foreign table which will match the attributes from the primary table you are querying from. In Maximo you will learn that the best way to do this is to understand whether the object/table exists at SITE, ORG, SYSTEM or other levels, which you can do in Database Configuration.
WORKORDER object exists at the SITE level and so you should always join by both WONUM and SITEID. Forgetting to join to the SITEID for site level objects is incredibly common, so you are not alone.
You haven't done this in your code snippet but this message is for other techies. DO NOT join site level objects including the ORGID. I remember one query which a colleague was working on, the query ran to about 5-6 pages in a single SQL statement and was taking way over 30 minutes, I think it was actually more than an hour. There were 20+ million work orders. My colleague asked me whether I could look at the query to see whether I had any ideas. It was riddled with clauses of ORGID=ORGID. Take that out, and it will probably cut the amount of time to run the query by about half, it did. For every subquery, the database was having to check whether for a large number of records the ORGID in one row was equal to the ORGID in the other. In Maximo, the SITEID is unique across all organizations, making a check on ORGID superfluous for two tables that are both at the SITE level, for example, finding the work orders belonging to an asset or location.
------------------------------
Andrew Jeffery
------------------------------
Original Message:
Sent: Thu November 19, 2020 07:27 PM
From: User1971
Subject: WHERE clause WOs: Get children too
One way to do this is to wrap the WHERE clause in an EXISTS operator that references the WOANCESTOR table:
exists (select wonum from woancestor where ancestor in (select wonum from workorder where
classstructureid = '60720'and status = 'APPR'
) and wonum=workorder.wonum)
The performance of that EXISTS operator is surprisingly good.
I tried various other 'proper' ways of getting the children in a full-blown query in Toad, but EXISTS in the WHERE clause had the lowest explain-plan cost. I guess the saying, "It's not stupid, if it works" applies here!
Original Message:
Sent: Thu November 19, 2020 07:19 PM
From: User1971
Subject: WHERE clause WOs: Get children too
I have a WHERE clause in the WOTRACK list view:
classstructureid = '60720'and status = 'APPR'
For the WOs that were returned, I also want to get their child WOs too.
What's the best way to do this?
#AssetandFacilitiesManagement
#Maximo