A sort requires in-memory work as well as disk work. The in-memory work depends on the number of columns that are sorted, the width of the combined sort key, and the number of row combinations that pass the query filter. Use the following formula to calculate the in-memory work that a sort operation requires:
Wm = (c * Nfr) + (w * Nfrlog2(Nfr))
Sorting can involve writing information temporarily to disk if the amount of data to sort is large. You can direct the disk writes to occur in the operating-system file space or in a dbspace that the database server manages. For details, see Configuring Dbspaces for Temporary Tables and Sort Files.
The disk work depends on the number of disk pages where rows appear, the number of rows that meet the conditions of the query predicate, the number of rows that can be placed on a sorted page, and the number of merge operations that must be performed. Use the following formula to calculate the disk work that a sort operation requires:
Wd = p + (Nfr/Nrp) * 2 * (m - 1))
The factor m depends on the number of sort keys that can be held in memory. If there are no filters, Nfr/Nrp is equivalent to p.
When all the keys can be held in memory, m=1 and the disk work is equivalent to p. In other words, the rows are read and sorted in memory.
For moderate to large tables, rows are sorted in batches that fit in memory, and then the batches are merged. When m=2, the rows are read, sorted, and written in batches. Then the batches are read again and merged, resulting in disk work proportional to the following value:
Wd = ooop + (2 * (Nfr/Nrp))
The more specific the filters, the fewer the rows that are sorted. As the number of rows increases, and the amount of memory decreases, the amount of disk work increases.
To reduce the cost of sorting, use the following methods:
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]