As far as possible, the Optimizer creates results tables only when it is absolutely necessary.
If no results table needs to be created, the search can be postponed to the FETCH time (see FETCH Statement). In this way, no memory is used for results, and the first results can be accessed quickly.
However, you cannot always postpone the search to the FETCH time, since some situations always require a results table to be created.
· SELECT for multiple tables (Join)
· SELECT ... FOR REUSE
A results table usually needs to be created in the following cases:
· SELECT DISTINCT ...
· SELECT ... ORDER BY ...
If all of the following conditions apply, no results table needs to be created:
¡ Neither a DISTINCT specification (<distinct spec>) (with a few exceptions), nor the syntax element FOR REUSE, are specified.
¡ The columns that you are sorting by constitute an index in the specified order and with the specified sort order (ascending or descending).
You can use the EXPLAIN statement to find out whether a results table is created (RESULT IS COPIED) or not (RESULT IS NOT COPIED).