Databricks-DE-Pro Developing Code (Python/SQL) Practice Question
A data engineer is developing a PySpark job that reads from a Delta table and performs a series of transformations. The engineer notices that the job is slow and suspects that the query plan is not optimized because statistics are outdated. Which command should the engineer run to update the statistics for the Delta table to improve query performance?
⚠ Common exam trap
The trap here is assuming that OPTIMIZE, which improves file layout, also updates statistics; however, statistics are separate metadata that require the ANALYZE TABLE command.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
ANALYZE TABLE table_name COMPUTE STATISTICS
The correct command is ANALYZE TABLE table_name COMPUTE STATISTICS. This command gathers statistics such as row count, column cardinality, and min/max values, which the Spark optimizer uses to generate efficient query plans. Outdated statistics can cause poor join orders or unnecessary shuffles. OPTIMIZE, VACUUM, and REFRESH TABLE serve different purposes and do not update statistics. Therefore, ANALYZE TABLE is the appropriate action to improve performance when statistics are stale.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
VACUUM table_name
Why it's wrong here
VACUUM removes old, unreferenced files from the Delta table to save storage, but it does not update statistics. It is a maintenance operation for file cleanup and does not affect the query optimizer's metadata. Running VACUUM would not improve performance due to outdated statistics; in fact, it could remove files that are still needed if not careful. The scenario requires updating statistics, so this command is irrelevant.
- ✗
REFRESH TABLE table_name
Why it's wrong here
REFRESH TABLE invalidates the cached metadata and data for the table, forcing Spark to reload it from the source. While it can help if the table was modified externally, it does not compute statistics. The query optimizer relies on statistics, not just cached data. In this scenario, the issue is outdated statistics, so refreshing the table would not update the statistics. It might be useful in other contexts but not for this specific problem.
- ✗
OPTIMIZE table_name
Why it's wrong here
OPTIMIZE is used to compact small files and improve read performance by reducing the number of files, but it does not update table statistics used by the query optimizer. While it can improve performance, it does not address the issue of outdated statistics. The scenario specifically mentions outdated statistics as the suspected cause, so OPTIMIZE alone would not resolve that. It is complementary but not the correct command for updating statistics.
- ✓
ANALYZE TABLE table_name COMPUTE STATISTICS
Why this is correct
This command computes statistics for the table, which the Spark optimizer uses to make better decisions about join strategies, filter pushdown, and other optimizations. In Databricks, running ANALYZE TABLE on a Delta table updates the statistics stored in the metastore. This is essential when data has changed significantly, as outdated statistics can lead to suboptimal query plans. It directly addresses the scenario of improving query performance by refreshing metadata.
About these practice questions
One of 267 original Databricks-DE-Pro practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Databricks exam blueprint
This Databricks-DE-Pro practice question is part of Courseiva's free Databricks certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the Databricks-DE-Pro exam.