An analyst notices that a specific query is slow because it performs a full table scan instead of using the intended index. Which command should the analyst check to ensure the optimizer has the necessary information to choose the correct plan?
Trap 1: OPTIMIZE TABLE.
OPTIMIZE is used to compact small files and improve data layout, which helps with I/O efficiency. While it is important, it does not directly update the statistics that the Cost-Based Optimizer (CBO) needs to determine the best join strategy or access method for a specific query.
Trap 2: VACUUM TABLE.
VACUUM is a maintenance command used to remove old, unreferenced data files that are beyond the retention period. It is essential for storage management and cost control, but it does not influence query planning, optimizer behavior, or the statistics used to determine the most efficient execution path.
Trap 3: REFRESH TABLE.
REFRESH TABLE invalidates the metadata cache and forces the system to reload the table's file list from the underlying storage. It is used when manual changes are made to the storage layer, but it does not generate or update the statistical metadata required by the CBO for intelligent query planning.
- A
OPTIMIZE TABLE.
Why it fails: OPTIMIZE is used to compact small files and improve data layout, which helps with I/O efficiency. While it is important, it does not directly update the statistics that the Cost-Based Optimizer (CBO) needs to determine the best join strategy or access method for a specific query.
- B
ANALYZE TABLE.
ANALYZE TABLE computes column statistics such as min, max, and distinct counts. The query optimizer uses these stats to decide whether a table scan or an index look-up is faster. Outdated statistics are a common cause of poor plan generation, and running this command often corrects the issue.
- C
VACUUM TABLE.
Why it fails: VACUUM is a maintenance command used to remove old, unreferenced data files that are beyond the retention period. It is essential for storage management and cost control, but it does not influence query planning, optimizer behavior, or the statistics used to determine the most efficient execution path.
- D
REFRESH TABLE.
Why it fails: REFRESH TABLE invalidates the metadata cache and forces the system to reload the table's file list from the underlying storage. It is used when manual changes are made to the storage layer, but it does not generate or update the statistical metadata required by the CBO for intelligent query planning.