Query optimization is the process of choosing an efficient execution strategy for processing a query. There are two internal representations of a query: a query tree and a query graph. The steps in query processing are: 1. Translating SQL queries into relational algebra by identifying query blocks, nested queries, and aggregate operators. 2. Using external sorting algorithms like sort-merge for large database files that do not fit into main memory. The sorting phase creates runs and the merging phase repeatedly merges the runs in multiple passes until one file remains. 3. Choosing the best execution plan by estimating the cost of different plans and selecting the least expensive one.