Forum Post: RE: For First, For Last, For Each

  • Thread starter Thread starter Fernando Souza
  • Start date Start date
Status
Not open for further replies.
F

Fernando Souza

Guest
First, BREAK is not necessary, unless you are working with break groups. On the first/last and BY discussion, we have added specific information and examples under the FIRST and LAST options of the FOR statement stating that the records are retrieved before any sorting is done to bring that exact point to the developer's attention. The model is that we resolve the query and get the record(s) first and once we have the record(s), we sort them. Sorting is done after we have the result set. The use of "FOR EACH table BY field" with LEAVE as shown in a previous post (and in the documentation) actually looks more like what it really is and performs as expected, that is, get all records that satisfy the query, sort them and then leave once you iterate thought the first (or last) record. Things like MAX-ROWS also have to be used with the understanding that sorting happens after the records are read. Doing anything other than that defeats the purpose if we have to read all records anyway before sorting them and could catch people by surprise with performance issues. If all that said, then a FOR FIRST table BY field doesn't make much sense if sorting will be done. When the BY clause works as substitute for USE-INDEX, it would be clearer to use USE-INDEX instead for a FOR FIRST/LAST block. I will say though that I sympathize with the confusion that this may cause so we could look into adding a compiler warning when we see FOR FIRST/LAST statement with a BY clause that causes sorting to alert developers that the result may not be what they expect.

Continue reading...
 
Status
Not open for further replies.
Back
Top