It's static SQL.
I added OPTIMIZE FOR 10 ROWS. The execution time jumped to 3049ms (originally 420ms), with the same 469 rows fetched.
-----Original Message-----
From: Birgitta Hauser [mailto:Hauser@xxxxxxxxxxxxxxx]
Sent: Friday, June 29, 2018 12:53 PM
To: 'Midrange Systems Technical Discussion' <midrange-l@xxxxxxxxxxxx>
Subject: RE: CURSOR-Table Scan vs Index Scan
Your embedded SQL is it static or dynamic?
If it is static try to add OPTIMIZE for x ROWS (x must be a small integer value, i.e. 3 or 10) at the end of the DECLARE Statement.
In this way you will change the optimization goal.
For dynamic SQL statement (also performed from STRSQL or Run SQL Script) the default is *FIRSTIO, i.e. the query is optimized so that the first block of data is returned as fast as possible. The optimizer may decide for an index access instead of a table scan.
For static SQL Statements the default is *ALLIO, i.e. the query is optimized so that all data is returned as fast as possible. The optimizer may decide for a table scan instead of an index access.
If the x in the OPTIMIZE FOR x ROWS clause is set to a small integer value, Optimization goal *FIRSTIO is used.
If the x is set to a big integer value or all, the optimization goal *ALLIO is used.
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok) "What is worse than training your staff and losing them? Not training them and keeping them!"
"Train people well enough so they can leave, treat them well enough so they don't want to." (Richard Branson)
-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxx> On Behalf Of Justin Taylor
Sent: Freitag, 29. Juni 2018 17:41
To: MIDRANGE-L (midrange-l@xxxxxxxxxxxx) <midrange-l@xxxxxxxxxxxx>
Subject: CURSOR-Table Scan vs Index Scan
SQL Performance Center shows that this query (from embedded SQL) performs a Table Scan (runtime 420ms):
declare POCSR cursor for select PO# , INV , STK , DESCR1 , DESCR2 , DESCR3 from PO where STK like : H or DESCR1 like : H or DESCR2 like : H or DESCR2 like : H order
by INV , PO# desc for read only
I ran the same query in Run SQL Scripts, substituting the same literal for :H. That uses an Index Scan (runtime 95ms).
Run SQL Scripts is using a LF keyed on INV. Debug data for the app shows that LF wasn't selected for this reason:
17 - The left-most key of the access path did not match any fields specified for the selection criteria. Therefore, key row positioning could not be performed, making the cost to use this access path higher than the cost associated with the chosen access method.
I have a standard index over (INV, PO#, x). I'm thinking about creating a new index over only (INV, PO#). Would a standard or EVI index work better?
TIA
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD
As an Amazon Associate we earn from qualifying purchases.