Sorted list scan

During a sorted list scan operation, the entire temporary sorted list is scanned and all of the entries contained within the sorted list will be processed.

A sorted list scan is generally considered when the optimizer is considering a plan that requires the data values to be sequenced. The use of a sorted list scan will allow the optimizer to generate a plan that can take advantage of any non-join selection while creating the temporary sorted list. An additional benefit of using a sorted list scan is that the data structure of the temporary sorted list will usually cause the table data within the sorted list to remain resident within main memory after creation thus reducing paging on the subsequent sorted list scan operation.

Table 1. Sorted list scan attributes
Data access method Sorted list scan
Description Read all of the entries in a temporary sorted list. The sorted list may perform distinct processing to eliminate duplicate values or take advantage of the temporary sorted list to sequence all of the rows.
Advantages
  • Reduces the random I/O to the table generally associated with longer running queries that would otherwise use an index to sequence the data.
  • Selection can be performed prior to generating the sorted list to subset the number of rows in the temporary object
Considerations Generally used to process ordering or distinct processing. Can perform poorly when the entire sorted list does not stay resident in memory as it is being populated and processed.
Likely to be used
  • When the use of temporary results is allowed by the query environmental parameter (ALWCPYDTA)
  • When the data is required to be ordered based upon a column or columns for ordering or distinct processing
Example SQL statement
CREATE INDEX X1 ON Employee (LastName, WorkDept)

SELECT * FROM Employee
WHERE WorkDept BETWEEN 'A01' AND 'E01'
ORDER BY FirstNme
OPTIMZE FOR ALL ROWS
Messages indicating use There are multiple ways in which a sorted list scan can be indicated through the messages. The messages in this example illustrate how the SQL Query Engine will indicate a sorted list scan was used.
  • Optimizer Debug:
    CPI4328 -- Access path of file X1 was used by query.
    CPI4325 -- Temporary result file built for query.
  • PRTSQLINF:
    SQL4008 -- Index X1 used for table 1.
    SQL4002 -- Reusable ODP sort used.
SMP parallel enabled No
Also referred to as Sorted List Scan, Preload

Sorted List Scan Distinct

Sorted List Scan Distinct, Preload

Visual Explain icon
Sorted list scan icon