In order for this site to work correctly, and for us to improve the site, we need to store a small file (called a cookie) on your computer.
By continuing to use this website, you agree to our cookies and privacy policy.
  
Home page Home page Home page Home page
Pixel
Pixel Header R1 C1 Pixel
Pixel Header R2 C1 Pixel
Pixel Header R3 C1 Pixel
Pixel

Rebuilding Indexes

Gordon French of Fort Lauderdale recently asked, with reference to the INDEX.SUB program included on Utility Diskette Number 1, "How is it possible to force a rebuild of an index for a file?". The INDEX.SUB routine does not actually force a rebuild as it assumes that you will be rebuilding after adding a new index, in which case it will work perfectly. If however, it is suspected that the indexes have become corrupted it can be long-winded calling INDEX.SUB to remove, readd then rebuild the indexes.

It is possible to instruct the system to rebuild the index for a field by mimicking the action taken by the system when it adds an index to a field. The system simply writes a record to the !INDEXING file, containing information about the file to update and the keyword %%ALL.IDS%%. The listing below shows a generic routine designed to allow the rebuilding of indexes from within an RBASIC program. To use, call with the file name and the field name/index name (EG USER, COMPANY_NAME.XREF, CUST*INV*AR). Note, network users should ensure they incorporate locking logic into this subroutine.


0001       SUBROUTINE REBUILD_INDEX(FILE,FIELD)
0002       *
0003       *  Author   AMcA
0004       *  Date     Jan 91
0005       *  Purpose  To rebuild an index for a field
0006       *  COPYRIGHT Sprezzatura Ltd 1991. Permission given to
0007       *  REVMEDIA subscribers to use in any form.
0008  
0009        DECLARE SUBROUTINE FSMSG
0010  
0011        OPEN "!INDEXING" TO IFILE THEN
0012         GOSUB GET_VOL_INFO
0013         GOSUB UPDATE_INDEX_FILE
0014        END ELSE
0015         FSMSG()
0016        END
0017       RETURN
0018  
0019       GET_VOL_INFO:
0020        FILE_REC = XLATE("FILES",FILE,"","X")
0021        VOL_REC  = XLATE("VOLUMES",FILE_REC<1>,"","X")
0022        VOL_INFO = FILE_REC<2>:"*":FILE_REC<3>:"*":VOL_REC<1>
0023       RETURN
0024  
0025       UPDATE_INDEX_FILE:
0026        UPDATE_REC    = VOL_INFO      ; * Volume Information
0027        UPDATE_REC<2> = 1             ; * Number of transactions
0028        UPDATE_REC<3> = FIELD         ; * Index to update
0029        UPDATE_REC<4> = "%%ALL.IDS%%" ; * Rebuild Flag
0030        UPDATE_REC   := @FM : @FM : @FM
0031        READ ZERO_REC FROM IFILE, "0" ELSE ZERO_REC = @FM
0032        * Ensure there is a trailing field mark
0033        IF INDEX(ZERO_REC,@FM,1) ELSE ZERO_REC := @FM
0034        ZERO_REC := UPDATE_REC
0035        WRITE ZERO_REC TO IFILE, "0"
0036        CALL INDEX.FLUSH(VOL_INFO,'')
0037       RETURN

(Volume 2, Issue 8, Page 7)
Pixel
Pixel Footer R1 C1 Pixel
Pixel
Pixel
Pixel