![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I noticed this in a program I was working on.... READVU BILL.AMT FROM ADCREDINFO,KEY,39 ELSE BILL.AMT = 0 BILL.AMT<1,1> += DIFF WRITEV BILL.AMT ON ADCREDINFO,KEY,39 That got me tut-tutting because the writev implies another read anyway, so we're reading that record and that group that it is in TWICE. So I started thinking about something like... * * * READU ADREC FROM ADCREDINFO,KEY ELSE ADREC = "" * * * BILL.AMT = ADREC<39,1 * * * BILL.AMT += DIFF * * * ADREC<39,1> = BILL.AMT * * * WRITE ADREC ON ADCREDINFO,KEY But then I thought about it, and wondered if that would make such a difference anyway. Surely when the WRITE is executed we again read the group into memory, update the group and write it away again. Long ago I was taught that this kind of READV.... WRITEV.... is wasteful in terms of disc I/O. But now I'm not so sure. |
#3
| |||
| |||
|
|
On Jan 27, 8:45*am, Bob Dubery <megap... (AT) gmail (DOT) com> wrote: I noticed this in a program I was working on.... READVU BILL.AMT FROM ADCREDINFO,KEY,39 ELSE BILL.AMT = 0 BILL.AMT<1,1> += DIFF WRITEV BILL.AMT ON ADCREDINFO,KEY,39 That got me tut-tutting because the writev implies another read anyway, so we're reading that record and that group that it is in TWICE. So I started thinking about something like... * * * READU ADREC FROM ADCREDINFO,KEY ELSE ADREC = "" * * * BILL.AMT = ADREC<39,1 * * * BILL.AMT += DIFF * * * ADREC<39,1> = BILL.AMT * * * WRITE ADREC ON ADCREDINFO,KEY But then I thought about it, and wondered if that would make such a difference anyway. Surely when the WRITE is executed we again read the group into memory, update the group and write it away again. Long ago I was taught that this kind of READV.... WRITEV.... is wasteful in terms of disc I/O. But now I'm not so sure. VLIST doesn't shed much light. The READVU... WRITEVU generates 0B1CE : 274 reapvu * * * * FILEVAR [19] KEY 39 *=> BILL.AMT 0B1D8 : 0C8 jumpt * * * * *0B1E6: 0B1E0 : 0F8 move * * * * * 0 *=> BILL.AMT 0B1E6 : 060 dyn_extract * *BILL.AMT 1 1 0 *=> $R607 0B1F2 : 004 add * * * * * *$R607 DIFF *=> $R608 0B1FA : 064 dyn_replace * *BILL.AMT 1 1 0 $R608 *=> BILL.AMT 0B208 : 212 writev * * * * BILL.AMT FILEVAR [19] KEY 39 The READU.... WRITEU generates 0B212 : 270 reapu * * * * *FILEVAR [19] KEY *=> ADREC 0B21A : 0C8 jumpt * * * * *0B226: 0B220 : 0F8 move * * * * * "" *=> ADREC 0B226 : 060 dyn_extract * *ADREC 39 1 0 *=> BILL.AMT 0B232 : 004 add * * * * * *BILL.AMT DIFF *=> BILL.AMT 0B23A : 064 dyn_replace * *ADREC 39 1 0 BILL.AMT *=> ADREC 0B248 : 208 write * * * * *ADREC FILEVAR [19] KEY So again it comes down to the amount of I/O that a writev and a write require. |
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
|
There is another consideration here. We have thousands of programs, not all very well written. If we want to know which programs update a particular attribute, we use a finder paragraph to search for the item name and attribute number. Ex: "FIND BP CUSTOMER.ITEM(39) CUSTOMER.ITEM<39> CUSTOMER.ITEM<39,". Of course we then have to look for CUSTOMER.REC, CUST.REC, CUSTREC, CUST, CUS, ad nauseum. My favorite (not) is just REC. Yep, we have that, too. |
#7
| |||
| |||
|
|
Actual database access is at the record level. Even though it happens deep inside the database engine, READV is effectively equivalent to a READ followed by a field extraction. As far as I am aware (and I am open to argument), none of the multivalue platforms is clever enough to spot that something like READV F2 FROM FVAR, ID, 2 ELSE ... READV F7 FROM FVAR, ID, 7 ELSE ... could actually do just one read and extract the two fields. It does, of course, potentially gain from record/group level caching where this is available. As a general rule, if you want to extract two or more fields, do the READ and extract the fields yourself. The one place where READV is really valuable is with field 0 to determine whether a record exists. Although this still has to go to the file to look for the record, it doesn't actually read it into memory. This becomes really important with huge records, especially those sometimes found in directory type files that might be many megabytes long. snip |
#8
| |||
| |||
|
|
And as far as limiting memory usage by reading attr 0, I believe the entire record is always read into memory, and just the requested attribute is copied into process workspace. There is no attribute zero. At least, if I understand correctly, not |
#9
| |||
| |||
|
|
Do all platforms support READV of attr 0? I'm thinking D3 doesn't, or at least didn't. And as far as limiting memory usage by reading attr 0, I believe the entire record is always read into memory, and just the requested attribute is copied into process workspace. Maybe it's just a slight improvement after all. |
#10
| |||
| |||
|
|
You'd love this program then. Somewhere up near the top of this listing it has something like EQU ADCREDINFO TO FILEVAR(18). |
![]() |
| Thread Tools | |
| Display Modes | |
| |