READ (1) vs FIND FIRST

Hi everyone!!!
Could you please recommend me which sentence is more efficient READ (1) or FIND FIRST.

Best regards

First choice:

READ (1)  ... FROM ... TO ...

Adabas will return 1 valid record or an end-of-file indicator.

Second choice:

READ (1) ... FROM ... THRU ...

Adabas will return 1 record unless the key value is beyond the end of the file. The THRU clause may reject the returned record.

Third choice:

FIND FIRST ...  
or  
FIND (1) ...

Adabas will create an ISN list, return the record associated with the smallest ISN, and throw away the remaining ISNs. This is fine for 1 ISN or an empty set, but would be very inefficient for keys with many identical values. For example SURNAME=‘SMITH’ would create a very large ISN list here in the US.

Although the question was just about performance, you should note:

FIND FIRST is not valid for structured mode; READ is.

READ starts a processing loop; FIND FIRST does not.

steve

Not to complicate things too much; there are other considerations, although they were not evident in the original problem statement.

First, Ralph’s description of the performance differences is right on. FIND FIRST involves the creation of an ISN list, which, if suitably long, could be an expensive process.

Now, let’s complicate matters in a way not presented by the original post. Suppose there is a WHERE clause.

For example: READ (1) EMPLOYEES BY NAME STARTING FROM ‘SMITH’ ENDING AT ‘SMITH’ WHERE FIRST-NAME = ‘ANN’

versus

FIND FIRST EMPLOYEES WITH NAME = ‘SMITH’ WHERE FIRST-NAME = ‘ANN’

The READ loop generates four L3 commands, the FIND FIRST generates an S1 and three L1s.

In this example (which you can run on your Natural/adabas system; ANN is the fourth SMITH), there is probably not much to choose between the two.

The first L3 (from the READ) is probably a bit faster than the FIND due to the fact that the FIND has to deal with the entire ISN list (e.g. to figure out what *NUMBER is). However, since there are only 19 SMITHs, the difference is pretty small.

After that, we have three L3’s (the READ) versus three L1’s (the FIND). The edge here should be to the FIND, but again, the difference should be pretty small.

HOWEVER, suppose we change the numbers a bit. There are 1000 SMITH’s and ANN is the 989th SMITH.

The first L3 will be faster than the first S1, although not by much (1000 ISN’s will very likely fit in one block). However, every L3 thereafter will be more expensive than the L1’s from the FIND (albeit a small difference). Multiply by 988 however, and the difference suddenly becomes important. Probably (no, I haven’t run a comparison yet), the FIND will outperform the READ.

Okay, it has been a boring day, with gray skies and thunderstorms with lots of lightening. This is perhaps more information than anyone was interested in.

In point of fact, if your code is so efficient that you are down to evaluating READ (1) versus FIND FIRST, you are better than 95% of the Natural systems out in the real world. Relax. Enjoy your status as one of the best performing systems out there.

steve

Thanks a lot Steve and Ralph for your answers.

Regards