Fix - Progress Community

EMEA PUG CHALLENGE
How Heroes Navigate the
Query Minefield
www.inenco.com
www.jdpalmer.co.uk
1
THE INENCO GROUP
Inenco is the UK’s leading energy consultancy
helping thousands of businesses of all sizes to
procure, reduce or manage their energy every
day
As well as a strong UK base, Inenco is active in 20
countries and fluent in 13 different European
languages, including Polish
Our growing pan-European team has built long
term relationships with over 130 suppliers across
Europe
Cultural understanding and international
competence covering standard practices,
negotiation strategies and legislation
Systems that can handle all data types for
effective consumption monitoring/ profiling
Overview
Identify which query is bad;
Identify why the query is bad;
Fix the query;
Be a Hero!
3
Overview
Identify which query is bad;
Identify why the query is bad;
Fix the query;
Be a Hero!
4
Know which query, not why
Compile with XREF
What records are being accessed
A whole program is slow
Compile with XREF
Profiling
What records are being accessed
5
Session is slow
Statement Cache
proGetStack
What Records are being accessed
Compile with Xref
Profiling
6
Overview
Identify which query is bad;
Identify why the query is bad;
Fix the query;
Be a Hero!
7
Why is the query bad?
Time based profiling
8
Why is the query bad?
9
Why is the query bad?
Time based profiling
Application Profiler
Hidden start up parameters
-zqil –zqilv (KB 21216)
Table and Index stats
-tablerangesize / -indexrangesize
Client Logging
10
Why is the query bad?
11
Why is the query bad?
ProTop
12
Why is the query bad?
Session
Trace
SessionTrace:UseProfiler
= TRUE.
SessionTrace:StartTracing().
WriteHTML(filename)
SessionTrace:StartSnapshot("ICMAS Stuff").
SessionTrace:UseDBStats = True
SessionTrace:AddDebugInfo(“Descriptor”,v
SessionTrace:StopTracing().
SessionTrace:WriteTrace("ICMASTrace.trc").
ariable).
13
Why is the query bad?
14
15
Why is the query bad?
Summary
Time Based or Effort Based?
Combine the two!
16
Overview
Identify which query is bad;
Identify why the query is bad;
Fix the query;
Be a Hero!
17
Fix the Query
Function on the left of the predicate
18
Fix the Query
NOT or NE in the predicate
Matches in the Clause
19
Fix the Query
Change the table order
20
Table Name
Reads
OrderLine
13,337,423
Order
3954
Item
3375
Fix the Query
Change the table order
21
Table Name
Reads
Item
3374
Order
3374
OrderLine
3374
Fix the Query
Change the table order
22
Table Name
Reads
Order
234
OrderLine
234
Item
4
Fix the Query
Dynamic Queries
23
Fix the Query
Dynamic Queries
24
Fix the Query
Dynamic Queries
25
Table Name
Reads
Table Name
Reads
Customer
1118
Customer
1118
Order
775
Order
775
OrderLine
119
Fix the Query
Dynamic Queries
Table Name
Reads
Table Name
Reads
Order
3954
Order
3953
OrderLine
3954
Customer
1117
Customer
1118
-rereadnolock
QueryHandle:CACHE
26
Fix the Query
Using ranges to avoid a dynamic query
FOR EACH tr_hist WHERE
(tr_hist.tr_type >= type1 AND tr_hist.type <= type2) AND
(tr_hist.tr_eff >= date1 AND tr_hist.tr_eff <= date2) AND
(tr_hist.tr_site >= site1 AND tr_hist.tr_site <= site2) AND
(continue this for about 15 more fields)
27
Fix the Query
BREAK BY on the wrong field
28
Table Name
Reads
Table Name
Reads
Order
7907
Order
3953
Customer
5071
Customer
1117
Fix the Query
Logic in the wrong place
29
Table Name
Reads
OrderLine
13971
Customer
3954
Order
3954
State
3775
Fix the Query
Logic in the wrong place
30
Table Name
Reads
Order
3953
OrderLine
2309
Customer
655
State
632
Fix the Query
TABLE-SCAN
Local Caching
Small tables, Static data
FIELDS
TABLE-SCAN
31
Fix the Query
32
Table Name
Reads
Item
3397
OrderLine
3370
PurchaseOrder
2130
Order
927
POLine
28
Fix the Query
33
Table Name
Reads
OrderLine
3369
PurchaseOrder
2129
Order
926
Item
111
POLine
28
Fix the Query
OR in the predicate
FOR EACH MeterSite NO-LOCK,
EACH ProductGroup NO-LOCK
WHERE ProductGroup.ProductGroupKey EQ
MeterSite.ProductGroupKey
AND (ProductGroup.PgrMeaningType EQ "ELE"
OR ProductGroup.PgrMeaningType EQ "WAT"):
END.
34
Table Name
Reads
Index Name
Reads
MeterSite
420511
ProductGroup.Pkey
841020
ProductGroup
420511
MeterSite.Pkey
421165
Fix the Query
OR in the predicate
FOR EACH MeterSite NO-LOCK,
EACH tt-PGR NO-LOCK
WHERE tt-PGR.ProductGroupKey EQ
MeterSite.ProductGroupKey:
END.
Table Name
Reads
MeterSite
420511
ProductGroup
2
FOR EACH tt-PGR NO-LOCK,
EACH MeterSite NO-LOCK
WHERE MeterSite.ProductGroupKey EQ ttPGR.ProductGroupKey:
Table Name
Reads
END.
35
MeterSite
268097
ProductGroup
2
Overview
Identify which query is bad;
Identify why the query is bad;
Fix the query;
Be a Hero!
36
Be a Hero!
Test, Test, Test - Proactive
Compile with XREF
Profile Code
Examine Table/Index Reads
37
Questions?
Any Questions?
www.jdpalmer.co.uk
38