Query planning is an essential process in database management systems. It involves generating an execution plan for a given SQL query to retrieve data in the most efficient manner. The primary goal of query planning is to minimize the cost of executing a query, which is typically defined in terms of the time or resources required. This is crucial in handling large databases, where inefficient query plans can significantly slow down data retrieval.

For instance, consider the following SQL query: SELECT * FROM students WHERE grade = 'A'; Here, the database has to decide whether to perform a full table scan or use an index (if one exists) on the grade column. The query planner makes this decision based on factors such as the size of the table and the distribution of grades. If the table is large and 'A' grades are rare, it might be more efficient to use an index. Conversely, if the table is small or 'A' grades are common, a full table scan might be faster.