Be aware of implicit sorting using the following clauses: DISTINCT, GROUP BY, UNION
Prefer to use a UNION ALL clause instead of a UNION clause.
UNION clause: append result sets together then remove duplicates via a sort.
UNION ALL clause: only append result sets together – no sorting.
If a sort is explicitly required then use an ORDER BY clause.
Use ROWNUM to retrieve only the top rows of the sort:
SELECT * FROM (SELECT … FROM … ORDER BY …) WHERE rownum<=5;
Note: In 9i, the GROUP BY will implicitly sort in the GROUP BY column order where an appropriate index does not exist. However in 10g the GROUP BY will not sort implicitly where an appropriate index does not exist.
Indexes can be created to minimise the workload by avoiding a sort….
A partitioned table can have partitioned or non-partitioned indexes.
A non-partitioned table can have partitioned or non-partitioned indexes.
A partition can have sub-partitions.
Partitioned and non-partitioned index options:
Local partitioned index on a partition of a table.
Global partitioned index on any or all partitions of a table, and the index partitions can be independent of the partitioned table. e.g. global partitioned index on contract ID column of a partitioned table on date column.
Global index on a whole table. i.e. simply an ordinary index.
Partition pruning is the skipping of unnecessary index and data partitions or subpartitions in a query.
Note: the optimizer cannot prune partitions if the SQL statement applies a function to the partitioning column (with the exception of the TO_DATE function). Similarly, the optimizer cannot use an index if the SQL statement applies a function to the indexed column, unless it is a function-based index.