You are here: Commands > Sort > Sorting versus Indexing

Sorting versus Indexing

The Index command is an alternative to sorting. Running the Sort command is slower and requires more disk space than indexing. However, processing a large sorted file is much faster than processing a large indexed file sequentially. The following table compares the benefits and drawbacks of the Sort and Index commands.

Issue

Sorting

Indexing

Execution speed

Slower

Faster

Resulting file size

Larger

Smaller

Required disk space

More

Less

Subsequent processing of an entire file

Much faster

Much slower

Subsequent processing searching for a few records

Much slower

Much faster

To use the Data Relations command and the Find Literal and Seek Expression options of the Search command, you must use a file that has been indexed rather than sorted.

The Sort command sorts the table in ascending order according to the key fields you specify, unless you specify descending order. The ascending and descending sort order specifications are specific only to a particular field and can be mixed in one Sort command (for example, account number ascending, transaction amount descending).

If you choose to sort on more than one key field, you must select the key fields in the order in which you want the sorting to occur (for example, enter the primary key field first, the secondary key field second and so on). The Sort command sorts on any number of key fields as long as the combined length of the fields being sorted does not exceed 255 characters.

Any type of field, including computed fields and ad hoc expressions, can be used for sorting and the various field types may be freely intermixed. Logical fields are sorted on false before true and numeric fields or expressions in sequence from the most negative through to the most positive field value.

Note: When processing server files that contain related files, record output will be changed to All fields output if you specify the local option or keyword.

Including the optional If, While, First and Next parameters causes a subset of the current table to be sorted into the output file.

Note: If you are connected to a zSeries server, Analyzer sends the error message “Check %s for System Sort messages” to the Command Log when a system sort on the server is unsuccessful. It is important to relay the contents of this message to your technical support staff. If they are unable to resolve the problem, contact Arbutus Technical Support.