INDEX_TOGGLE
Published By | Date | Version | Knowledge Level | Keywords |
---|---|---|---|---|
Revelation Technologies | 23 APR 1992 | 2.1X | INTERMEDIATE | SI.MFS, INDEX_TOGGLE, INDEXES, INDEXING, REBUILDING |
Advanced Revelation 2.12 provides a subroutine, INDEX_TOGGLE, that you can use to temporarily remove indexing from a file. This is useful when you need to process a file but you don't need to use or maintain the indexes.
The syntax for INDEX_TOGGLE is:
INDEX_TOGGLE(FILE, HOLD, FLAG)
File is used to pass the name of the target file from which you want to suspend indexing.
Hold stores the information necessary to properly restore indexing.
Flag is passed with one of three values:
0 | Suspend indexing |
1 | Restore indexing |
2 | Restore indexing and rebuild indexes |
Flag is returned null if the operation failed, true (1) otherwise.
Figure 1 shows the proper use of INDEX_TOGGLE.
Network Considerations
INDEX_TOGGLE removes indexing only for the workstation that invokes it. All other workstations on the network continue to use and update indexes normally.
If you update indexed fields, you should not use INDEX_TOGGLE unless you are the only one on the network. You must also be sure to rebuild your indexes at the end of your process in order for them to be maintained. No index transactions are logged while the workstation has indexing turned off.
File Handles
INDEX_TOGGLE removes SI.MFS from the file list maintained in memory, then reopens the file. You should always open (or re-open) your file after calling INDEX_TOGGLE to ensure that you get a valid file handle.
Caution
When restoring or rebuilding indexing, the subroutine does not check to see whether SI.MFS is already on the file. It assumes it is not there.
Remember that, once indexing is turned off for the workstation, all processes on the workstation will not have access to indexes for the file.
If your program crashes before you call INDEX_TOGGLE to restore the indexing, simply reattach the file. This safety mechanism means that you should not use INDEX_TOGGLE if the file will be reattached in the middle of processing.
Examples
Figure 1
DECLARE SUBROUTINE INDEX_TOGGLE EQU OFF$ TO 0 EQU ON$ TO 1 EQU BUILD$ TO 2 EQU FALSE$ TO 0 EQU TRUE$ TO 1 TABLENAME = "SAMPLE_CUSTOMERS" HOLD = "" INDEX_TOGGLE(TABLENAME, HOLD, OFF$) OPEN TABLENAME TO INPUTFILE ELSE FSMSG() INDEX_TOGGLE(TABLENAME, HOLD, ON$) STOP END SELECT INPUTFILE DONE = FALSE$ LOOP READNEXT KEY ELSE DONE = TRUE$ END UNTIL DONE READ RECORD FROM INPUTFILE, KEY THEN /* Processing here */ END REPEAT INDEX_TOGGLE(TABLENAME, HOLD, ON$) /* If the processing updated indexed fields you would use this line instead INDEX_TOGGLE(TABLENAME, HOLD, BUILD$) */ STOP