Here is the statement:
SELECT FLD2, FLD3, MIN(MINFLD) AS MINFLD, FROM LIB.FILENAME where ....
GROUP BY MINFLD, FLD2, FLD3, ... fetch first 100 rows only (statement has
been altered to change the field names and for brevity).
The GROUP BY does not seem to work on the 6.1 server. We want the records
returned in ascending order by MINFLD.
As noted by others, an ORDER BY is required to get an ordered sequence.
This would be more obvious on other SQL products. There is a slight
bias on "i" for returning things in the original (arrival sequence)
order, but it is _never guaranteed_ without the use of ORDER BY.
Absent that, there would be a bias on any DB product towards using
whatever index was used to fetch things back.
For instance, perhaps there is an existing index over MINFLD or one is
created as part of the execution of the SQL statement. That's probably
what is usually happening here and why the ordering is "mostly" by
MINFLD.
One would have to do a Visual Explain over the statements from the
various environments to see why there would be differences. But,
differences are possible, because the SQL optimizer may change the
access plan for all kinds of reasons. Since SQL formally allows the
records to come back in any order if there is no ORDER BY, a change of
plan can and will change the order of the records fetched.
Reasons for this include:
1. Changes in the size of the underlying file.
2. Slight changes in the SQL (did someone type fetch first 50 rows only
in some other test?).
3. Whether the QAQQINI file is present (which changes the 'hints' the
optimizer uses).
4. The exact environment used.
Number 4 is particularly relevant.
In this reference:
http://www.ibm.com/developerworks/data/library/techarticle/dm-0611milligan/
. . it shows the goal of *ALLIO versus *FIRSTIO (which I personally know
can greatly influence how records are fetched) varies by comparatively
triffling differences in the environment.
Note that it is even different for native JDBC versus toolbox JDBC, for
instance.
Larry Loen
www.applicationperformancegroup.com
As an Amazon Associate we earn from qualifying purchases.