Repairing your Index

If you have to fill or change your class data other than by standard object filer or SQL filer
you also have to get your indexes in line with your data.
Rebuild Index might be time consuming exercise eventually blocking access at all.

I just detected ##class(%Library.Storage).%ValidateIndices()

Not really new, but in 2015.1.1 ,  2016.2.1 there was not a single character of documentation to it.
Now I see on latest

• classmethod %ValidateIndices(idxList As %List = "", autoCorrect As %Boolean = 0, lockOption As %Integer = 1, multiProcess As %Boolean = 1) as %Status

%ValidateIndices() - Validates indices for a class 

Optional. "" to check all indices, or specify a $list of index names to check. Default=""
Optional. If true, correct any errors found. Default=0
Optional. Default = 1 0 - No locking is performed at all 1 - Shared locking as each row is checked 2 - exclusive lock on entire table for duration of the run
Optional. If true, parts of %ValidateIndices will use parallel processing when possible. Default=1


Status Code


  • Do $SYSTEM.OBJ.ValidateIndices("Sample.Person","",1,2)
  • Do $SYSTEM.OBJ.ValidateIndices("Sample.Company",$lb("NameIdx"),1,1)

Indices may also be validated by calling the class method $SYSTEM.OBJ.ValidateIndices(classname,idxList,autoCorrect,lockOption)
There is one main difference between validating indices through $SYSTEM.OBJ.ValidateIndices() and ##class(classname).%ValidateIndices()
$SYSTEM.OBJ.ValidateIndices() will validate the indices for a table, and it will also validate any indices in collection child tables for that table. 
When using ##class(classname).%ValidateIndices(), collection child table indices must be checked with separate calls. 
Also, when calling $SYSTEM.OBJ.ValidateIndices(), multiProcess default is 0. When calling ##class(classname).%ValidateIndices(), multiProcess default is 1.

Is this what I liked to interpret:
The method that removes dead entries and adds missing ones it if I set autoCorrect to 1.
The Index Repair ?
Has anyone ever tried it ?​

  • + 6
  • 0
  • 408
  • 7


I did a short test fiddling arouned ^Samples.PersonI
an to demonstrate the output.

SAMPLES>Do $SYSTEM.OBJ.ValidateIndices("Sample.Person","",1,2)                   
Checking index integrity for class 'Sample.Person'
Begin time:  08/17/2017 21:41:25
Verifying data from data map 'IDKEY' is indexed correctly...
Index 'NameIDX', entry ^Sample.PersonI("NameIDX"," CHANG,QUIGLEY H.",39), has differences between master map data and index map data.  Corrected
Index 'NameIDX', entry ^Sample.PersonI("NameIDX"," CHANG,DAN L.",40) missing.  Corrected
Index 'NameIDX', entry ^Sample.PersonI("NameIDX"," CHADWICK,OLGA E.",43) missing.  Corrected
Index 'NameIDX', entry ^Sample.PersonI("NameIDX"," CANNON,BARBARA W.",81) missing.  Corrected
Data Map evaluation complete, 200 rows checked, 4 errors found, elapsed time: .004733 seconds
Verifying data from index map "$Person" is correct...
Index map "$Person" evaluation complete, 0 errors, elapsed time: .000691 seconds
Verifying data from index map NameIDX is correct...
Index 'NameIDX', entry ^Sample.PersonI("NameIDX"," CEMPER,DAN L.",40), data differs for field 'Name' between data and index map.  Corrected
Index map NameIDX evaluation complete, 1 errors, elapsed time: .001331 seconds
Verifying data from index map SSNKey is correct...
Index map SSNKey evaluation complete, 0 errors, elapsed time: .001195 seconds
Verifying data from index map ZipCode is correct...
Index map ZipCode evaluation complete, 0 errors, elapsed time: .001255 seconds
%ValidateIndices is complete, total elapsed time: .012282 seconds


This looks good so far.

by lack of responses I converted it from a question to an article + comment

Perhaps we can do a Tipps and Tricks section here in the Community for those posts or at least tag such articles special. 


will we meet in Frankfurt at the Symposium  next week ?