Obviously the query optimizer built two different access plans for
interactive and batch execution of the statement. There are a LOT of
possible reasons why it may opt to do that. One clear distinction between
STRSQL and batch execution is that STRSQL defaults to *FIRSTIO setting while
batch defaults to *ALLIO optimization goal. Other common differences are
memory pool size, activity levels, language settings, sort sequence
settings, library list ... like I said, there are a LOT of environmental
settings that influence query optimizer's decision making.
Vern offered a good, simple option to try to figure out what exactly causes
the significant difference in execution times - STRDBG. Another one is
Visual Explain, part of iSeries Navigator (probably the best option when
you've narrowed it down to one SQL statement).
Yet another, most detailed option, is the database monitor. Dbmon is
available via green screen STRDBMON command, but Navigator's 'SQL
Performance Monitor' is much more user friendly version of dbmon collection
and more importantly, analysis.
BTW, if you're not happy with 5 second performance of your query, I think
putting 'cdstat' as a leading key for the second index (4 key) is probably
worth a try as well.
Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
Subject: Re: Way to get STRSQL SELECT to run in batch?
On Tue, Jul 29, 2008 at 12:49 PM, Elvis Budimlic <
Build 2 indexes (i.e. CREATE INDEX) if you don't already have keyed lfs
1) CVCUSN, CVRENN, CVSEQN
2) cdCUSN, cdRENN, cdSEQN, cdstat
The indexes above ought to help the performance of your query.
Elvis, the table for 1) has as its primary key those three fields, followed
by three other fields. The table for 2) has as its primary key the first
three field, but not cdstat.
What is most surprising, as I mentioned in my response to Eric, is that the
interactive query took hours to build an index on the 1) table, but when I
submitted it to batch per the CREATE TABLE ZZZZ AS... it took less than 5
seconds for it to run! What gives?
Really mind boggling.