Caché ObjectScript Reference
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   

Initiates a sorting mode to improve performance of multiple sets to a global.
set_global A global variable name.
$SORTBEGIN initiates a special sorting mode during which SET operations to the specified target global are redirected to a process-private temporary area and sorted into subsets. This mode is ended with a call to $SORTEND which copies the data into the target global reference. When the special sorting mode is in effect, all sets to the target global reference and any of its descendants are affected.
$SORTBEGIN is designed to help the performance of operations, such as index building, where a large amount of unordered data needs to be written to a global. When the amount of data written approaches or exceeds the amount of available buffer pool memory, performance can suffer drastically. $SORTBEGIN solves this problem by guaranteeing that data is written to the target global in sequential order, thus minimizing the number of physical disk accesses needed. It does this by writing and sorting data into one or more temporary buffers (using space in the ^CacheTemp global if needed) and then, when $SORTEND is called, copying the data sequentially into the target global.
While $SORTBEGIN is in effect, data read from the target global will not reflect any SET operations. You cannot use $SORTBEGIN in cases where you need to read global values from the same global in which you are inserting values.
Caché object and Caché SQL applications automatically make use of $SORTBEGIN for index and temporary index creation.
The $SORTBEGIN sorting mode can be terminated without writing data to the target global by calling $SORTEND with it optional second parameter set to 0.
If successful, $SORTBEGIN returns a nonzero integer value. If unsuccessful, $SORTBEGIN returns zero.
Sorting Mode Errors
Invoking some operations between the $SORTBEGIN and $SORTEND result in Caché issuing an error code:
See Also