Download - Lacey radabaugh maximo sql queries
![Page 1: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/1.jpg)
Maximo SQL Queries
April 2016
![Page 2: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/2.jpg)
1
• Problem Areas and Solutions
• Query Examples
• Identify Long Running Query
• Dynamic Queries
• Adding New Search Fields
• Q&A
Agenda
![Page 3: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/3.jpg)
2
• Wildcard searches
• select count(*) from workorder where status like ‘%APPR%‘ and siteid
like ‘%BEDFORD%‘ and jpnum like ‘%XX1234%’
• Does full table scan
• Does not use index
Problem Area
![Page 4: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/4.jpg)
3
• SEARCHTYPE = WILDCARD
• User enters value without equal sign
• QBE constructs: column like ‘%value%’
• Database cannot use an index if leading wildcard
Why is Like a Problem?
![Page 5: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/5.jpg)
4
• Teach users to use leading equal sign
• Change SEARCHTYPE to EXACT
• Create a public saved query for them
• If found in a saved query, fix it there
Solution
![Page 6: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/6.jpg)
5
Solution
![Page 7: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/7.jpg)
6
• Upper() Function
• …and upper(column) = ‘VALUE’...
• MAXTYPE is ALN
• QBE uses upper()
• Upper(column) cannot use an index
Problem Area
![Page 8: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/8.jpg)
7
• Need to understand the data
• …upper(column) = '123456‘
– Is column always numeric data?
• …upper(column) = 'WILMAF‘
– Is column always uppercase data?
• If either is true, change maxtype to UPPER
Fixing Upper()
![Page 9: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/9.jpg)
8
• Exists vs. In• The EXISTS function searches for the presence of a single row meeting the stated
criteria
• The IN statement looks for all occurrences
• IN example• SELECT t1.col1 FROM table1 t1
WHERE t1.col2 IN (SELECT t2.col2 FROM table2 t2)
• EXISTS example• SELECT t1.col1 FROM table1 t1
WHERE EXISTS (SELECT ‘1’ FROM table2 t2 WHERE t2.col2 = t1.col2)
• IN query - all rows in table2 will be read for every row in table1
• EXISTS query = a maximum of 1 row from table2 will be read for each row of table1 • This reduces the processing overhead of the statement
Problem Area
![Page 10: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/10.jpg)
9
• Rule of thumb
• If the majority of the filtering criteria are in the subquery then the IN variation may be more performant.
• If the majority of the filtering criteria are in the top query then the EXISTS variation may be more performant
Solution
![Page 11: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/11.jpg)
10
• Saved queries
• Saved performance problems
• Look at the data in the CLAUSE column
• LIKEs
• UPPERs
• Correct them
Query Table
![Page 12: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/12.jpg)
11
• Query cannot be made more efficient
• Query is frequently executed
• Work with the DBA to identify an index that would improve it
• Add the new index in the Database Configuration application
Add Indexes
![Page 13: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/13.jpg)
12
• Find Work Orders that were not filled out correctly with missing crafts
• Where clause• ((woclass = ‘WORKORDER’ or woclass = ‘ACTIVITY’)
and historyflag = 0
and siteid = ‘XXXX’
and istask = 0
and craft is null
and location in (select y.location from locancestor y where y.siteid = ‘XXXX’
and y.ancestor = ‘YYYY’))
Query Example
![Page 14: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/14.jpg)
13
• Find job plans where there is an asset associated with the job plan, and the asset is in location XXXX
• Where clause
• (siteid = ‘YYYY‘ and jpnum in (select x.jpnum from jpassetsplink x
where x.siteid = ‘YYYY‘
and x.assetnum in (select y.assetnum from asset y
where y.location = ‘XXXX’
and y.siteid = ‘YYYY’)))
Query Example
![Page 15: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/15.jpg)
14
• Find inventory where the standard cost greater than $100
• Where clause
• (status != 'OBSOLETE'
and siteid = ‘XXXX'
and itemnum in (select itemnum from invcost
where stdcost > 100
and siteid = ‘XXXX'))
Query Example
![Page 16: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/16.jpg)
15
• Find Safety PM work that are past due in the past 6 months. Shows floating date range.
• Where clause• (woclass = 'WORKORDER' or woclass = 'ACTIVITY')
and status not in ('COMP','CLOSE','CAN')
and istask = 0 and safety = 1
and siteid = ‘XXXX'
and (pmnum is not null or (parent is not null and jpnum is not null))
and targcompdate < add_months (trunc (sysdate, 'MM'), +0)
and targcompdate > add_months (trunc (sysdate, 'MM'), -6)
Query Example
![Page 17: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/17.jpg)
16
• Turn on SQL Time Limit logging
• Writes a log message for each SQL statement which exceeds the limit
• Start with a high value such as 60000 milliseconds (60 seconds) to find the worst performing SQL first
• Property mxe.db.logSQLTimeLimit
• Set in the System Properties application
• If Oracle, schema userid should have SELECT on V$SESSION view
• Set the root sql logger to WARN in the Logging application
Identify Long Running SQL
![Page 18: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/18.jpg)
17
Use case: filter records for logged in user
Solution: the substitution variable :user can be included in the query to resolve to the logged in user, e.g. reportedby = :USER
Use case: filter records for work orders scheduled to start in the next week.
Solution: Reference current date in query. Different depending on database.
SQL Server: schedstart <= ( getdate() + 7)
DB2: schedstart <= ( CURRENT DATE + 7 DAYS)
Oracle: schedstart <= ( sysdate + 7)
Dynamic Queries
![Page 19: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/19.jpg)
18
• End users can search for records by using fields on the List, Advanced Search or Attribute Search screen/dialogs. Maximo writes the sql behind the scenes. The sql can be viewed in the Where Clause.
• OOTB a majority of fields are already available for searching via one of the above search methods
• Sometimes there are other ways users would like to be able to frequently search for records
• The Where Clause allows users to enter a sql statement to search for records. However, access to Where Clause should be limited. If a user isn’t skilled with sql, a very inefficient query could be entered in the Where Clause and this could cause performance issues
Adding New Search Fields
![Page 20: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/20.jpg)
19
• Using Application Designer, new search fields can be added to the List screen and/or Advanced Search
• These search fields can be fields stored as attributes on the main object that is being searched, e.g. Actual Date fields on the work order
• These search fields can also be fields that are related to the object, e.g. PO number where parts are being purchased directly for a work order
Adding New Search Fields
![Page 21: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/21.jpg)
20
Problem: I want to see all work orders completed for a building in the last month but there are no search fields. I could use the Where Clause...but how do I write that sql?
Adding New Search Fields
![Page 22: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/22.jpg)
21
Adding New Search Fields
Solution: add Actual Date fields to Advanced Search via Application Designer and let Maximo write the sql
![Page 23: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/23.jpg)
22
Problem: I want to search for all work orders completed last year where the asset is covered under a warranty contract. I want to search based on Warranty Contract number.
Adding New Search Fields
![Page 24: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/24.jpg)
23
Solution: add Contract as a search field via Application Designer by leveraging a relationship. May leverage existing relationship or may need to create a new one in Database Configuration
Adding New Search Fields
![Page 25: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/25.jpg)
24
• Setting debug properties and logginghttp://www-01.ibm.com/support/docview.wss?uid=swg21291250• Search methodologyhttp://www-01.ibm.com/support/docview.wss?uid=swg21375684• Efficient query syntax for Maximo applications screenhttp://www-01.ibm.com/support/docview.wss?uid=swg21262295• Maximo 7.5 Performance Best Practiceshttps://www.ibm.com/developerworks/community/groups/service/html/communityview?communityUuid=a9ba1efe-b731-4317-9724-a181d6155e3a#fullpageWidgetId=W5f281fe58c09_49c7_9fa4_e094f86b7e98&file=c51d5f5b-dea3-4043-a81f-d5213fc10063• Maximo 7.6 Performance Best Practiceshttps://www.ibm.com/developerworks/community/groups/service/html/communityview?communityUuid=a9ba1efe-b731-4317-9724-a181d6155e3a#fullpageWidgetId=W5f281fe58c09_49c7_9fa4_e094f86b7e98&file=e0291480-2b4f-4366-bb01-e6e7360cd033• Writing efficient SQL queries (DB2 KnowledgeCenter)https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/com.ibm.db2z11.doc.perf/src/tpc/db2z_programsqlperf.dita
Resources
![Page 26: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/26.jpg)
25
• Advanced date queries for Maximo
http://www-01.ibm.com/support/docview.wss?uid=swg21295192
http://www-01.ibm.com/support/docview.wss?uid=swg21262277
• Wildcards and operators for searching
http://www.ibm.com/support/knowledgecenter/SSLKT6_7.6.0/com.ibm.mbs.doc/gp_ui/r_wildcard_operator_search.html
• Variables for dynamic queries in conditional expressions
http://www-01.ibm.com/support/docview.wss?uid=swg21614036
Resources Continued
![Page 27: Lacey radabaugh maximo sql queries](https://reader030.vdocuments.site/reader030/viewer/2022012404/5870581e1a28aba2118b5d47/html5/thumbnails/27.jpg)
Thank You