Courseiva

CCNA Da Analyzing Queries Questions

39 questions · Da Analyzing Queries topic · All types, answers revealed

1
MCQhard

An analyst is reviewing a slow query and identifies that the 'FileScan' stage is taking most of the time. Which THREE factors could be causing this inefficiency?

A.The table contains a high number of small files.
B.The query lacks filters on partition columns.
C.The query uses a cross join.
D.The data is not Z-Ordered on filtered columns.
E.The query is using a User-Defined Function (UDF).
AnswerA, B, D

A high number of small files increases metadata processing time, as the system must open, read, and close many files to retrieve even a small amount of data. This 'small file problem' is a common cause of slow query performance and can be mitigated by using the OPTIMIZE command.

Why this answer

Slow FileScans usually point to I/O-related issues. If too many small files are present, the metadata overhead becomes significant. Without proper pruning, the system scans unnecessary data.

Z-Ordering or partitioning issues cause the engine to read more data than required. Addressing these factors is vital for analysts, as they directly impact the 'Data Skipping' efficiency of the Delta Lake engine, which is the cornerstone of high-performance analytics in Databricks.

Exam trap

Students often overlook metadata overhead caused by tiny files, focusing only on compute sizing instead of file management and partition pruning factors.

2
MCQeasy

Which feature in Databricks SQL allows an analyst to view the history and performance metrics of previously executed queries?

A.The Data Explorer.
B.The Query History.
C.The Cluster Metrics tab.
D.The Workspace Audit Logs.
AnswerB

Query History provides a centralized view of all queries executed in the workspace. It includes status, duration, user, and access to the Query Profile, which makes it the essential tool for tracking query performance, investigating failures, and analyzing the historical impact of changes to SQL queries and data models.

Why this answer

The Query History interface is the primary tool for reviewing past executions. It allows analysts to search, filter, and inspect the performance of queries run across the workspace. This is important for identifying long-running queries, diagnosing failures, and comparing performance over time, which supports the iterative process of optimizing data models and SQL code to ensure consistent, reliable, and performant data delivery for the organization.

Exam trap

Candidates confuse the Query History interface with the Delta Lake table history or workspace audit logs when searching for past execution metrics.

3
MCQhard

A data analyst is investigating a query that uses a window function with PARTITION BY and ORDER BY, and the query is slow. The analyst suspects that data skew is causing some partitions to be much larger than others. Which approach should the analyst take to diagnose the skew in the Query Profile?

A.Check the 'Shuffle Read Size' per task to see if some tasks read significantly more data than others.
B.Look at the 'Peak Execution Memory' to identify tasks using more memory.
C.Review the 'Number of Output Rows' for each task to see if some produce more rows.
D.Examine the 'Spill (Disk) Size' to see if any tasks spilled to disk.
AnswerA

In the Query Profile, the task-level metrics for a shuffle stage show the amount of data each task reads. If data is skewed, a few tasks will have much larger Shuffle Read Size than others, indicating that those partitions are handling more data. This is a direct way to identify skew in window functions, which often require shuffling data by the partition key.

Why this answer

Data skew in window functions is often revealed by uneven shuffle read sizes across tasks. The Query Profile provides task-level metrics, and a significant disparity in Shuffle Read Size indicates that some partitions are much larger, causing skew. This allows the analyst to confirm the skew and then apply mitigation techniques like salting or repartitioning.

Exam trap

The trap here is focusing on memory or spill metrics to diagnose skew, when the most direct indicator is the uneven distribution of data read during shuffle.

4
MCQmedium

A data analyst notices that a query involving a join between a large table and a small lookup table is performing poorly. The analyst wants to optimize the join performance without changing the underlying data. Which technique should they apply?

A.Add an explicit BROADCAST hint to the small table in the JOIN clause.
B.Increase the number of shuffle partitions to 2000.
C.Convert the large table to a Delta table with Z-Ordering.
D.Use the MERGE INTO statement instead of a standard JOIN.
AnswerA

The BROADCAST hint explicitly instructs the Spark catalyst optimizer to perform a broadcast hash join. This eliminates the need for a shuffle exchange, which is the most expensive part of a join, by duplicating the smaller dataset across all executor nodes for local lookup operations.

Why this answer

Broadcasting the small table forces the cluster to send the entire lookup table to every node in the cluster, avoiding a full shuffle of the large table. This technique significantly reduces network overhead during joins when one side fits in memory. Mastering join strategies is essential for analysts to write efficient SQL that minimizes cluster resource consumption and shortens execution times on large datasets.

Exam trap

Candidates often rely on the Catalyst optimizer to automatically broadcast every small table, failing to manually add explicit broadcast hints when needed.

5
Multi-Selectmedium

A data analyst is reviewing a Databricks SQL query that runs slowly and opens the Query Profile. The analyst wants to identify whether an individual task is disproportionately slow compared with its peers, indicating skew. Which TWO areas of the Query Profile should the analyst examine? (Choose two.)

Select 2 answers
A.The version of the Databricks Runtime used by the warehouse
B.The number of rows and bytes written by each shuffle partition
C.The SQL warehouse cluster size configured for the query
D.The total number of stages in the physical plan
E.The duration distribution of tasks within a single stage
AnswersB, E

Per-partition shuffle write sizes reveal imbalance directly: if one partition receives vastly more bytes or rows than its peers, the downstream task processing it will run long. Comparing these counts across partitions confirms skew at the shuffle boundary and points to the join or grouping key that is unevenly distributed.

Why this answer

Skew manifests as an individual task running far longer than its peers because one partition holds disproportionate data. Task duration distribution within a stage exposes the straggler, while per-partition shuffle write rows and bytes show the imbalanced partition that causes it. Together these two views confirm skew rather than a general resource shortage.

Exam trap

The trap here is blaming cluster size for a slow stage, when skew is a data distribution problem that adding executors cannot solve.

6
MCQeasy

When analyzing the execution plan of a query in Databricks SQL, what does a 'BroadcastHashJoin' node typically indicate?

A.The query is performing a cross join between two large tables.
B.The optimizer successfully avoided a network shuffle by sending a small table to all executors.
C.The query is failing because the join keys are not indexed.
D.The data is being read from multiple external storage locations simultaneously.
AnswerB

This join strategy is chosen when one side of the join is small enough to fit into memory on each worker node. By broadcasting this table, the engine eliminates the need to redistribute the larger table across the network, resulting in much faster execution and reduced cluster load.

Why this answer

A BroadcastHashJoin indicates that the query optimizer determined one table was small enough to be duplicated across all nodes. This avoids expensive shuffles by performing the join locally on each partition. Understanding execution plans allows analysts to verify if their queries are executing as intended and helps identify opportunities to apply hints or optimize join operations for better performance on large-scale distributed data processing tasks.

Exam trap

Candidates frequently mistake a BroadcastHashJoin for an indicator of data skew or network bottlenecks, when it actually represents an optimized join strategy.

7
MCQeasy

Which of the following is the primary purpose of examining the 'Query Profile' in Databricks SQL?

A.To change the permissions of the underlying table.
B.To visualize the execution steps and identify bottlenecks.
C.To automatically rewrite SQL for better performance.
D.To view the raw logs of the cluster driver.
AnswerB

The Query Profile provides a graphical representation of the physical query plan. It allows analysts to see the duration of individual operators, data volumes, and task metrics, making it easier to pinpoint specific stages that are causing slow execution or high resource utilization within a complex SQL statement.

Why this answer

The Query Profile is the central diagnostic tool for Databricks SQL. It provides a visual representation of how a query was executed, including the time spent in each stage and where bottlenecks occur. Mastering this tool is vital for data analysts because it transforms abstract performance issues into actionable insights, enabling them to reduce query latency, optimize costs, and effectively communicate performance bottlenecks to data engineers for backend architecture improvements.

Exam trap

Candidates often think the Query Profile is only for viewing the final output or query results, missing its primary value as a visual diagnostic tool for identifying execution bottlenecks.

8
MCQhard

A data analyst writes a complex Spark SQL query involving multiple window functions, CTEs, and aggregations. To debug the query performance, the analyst wants to inspect the logical optimization phases applied by the Catalyst optimizer. Which SQL command can the analyst use to view the unoptimized logical plan, optimized logical plan, and physical execution plan?

A.DESCRIBE EXTENDED table_name;
B.SHOW QUERY PLAN SELECT ...;
C.EXPLAIN EXTENDED SELECT ...;
D.ANALYZE TABLE table_name COMPUTE STATISTICS;
AnswerC

Prepending EXPLAIN EXTENDED to a SQL query instructs Spark to output all phases of query planning, including the parsed logical plan, analyzed logical plan, optimized logical plan, and physical execution plan, allowing analysts to thoroughly debug and analyze query behavior.

Why this answer

Spark SQL provides the EXPLAIN command to inspect the underlying plans generated by the Catalyst optimizer. By specifying the EXTENDED or FORMATTED modifier, analysts can review parsed logical plans, analyzed logical plans, optimized logical plans, and final physical execution plans.

Exam trap

Candidates often select the 'EXPLAIN' command alone, failing to realize that the basic command only provides the physical plan, omitting the critical logical optimization phases required for debugging complex queries.

9
MCQmedium

Refer to the exhibit. The execution plan shows a SortMergeJoin with two Exchange nodes. What is the primary cause of the performance impact here?

A.The join keys are not sorted, forcing a full scan of both tables.
B.The tables are being re-shuffled to align rows on the join key, causing network overhead.
C.The optimizer is unable to choose a broadcast join because both tables are too large.
D.The cluster is running out of memory due to the high number of partitions.
AnswerB

Exchange nodes in a Spark execution plan represent a shuffle, which involves moving data over the network to ensure that rows with the same join key are processed on the same node. This is a heavy operation that occurs when tables are not already partitioned by the join column.

Why this answer

The presence of two Exchange nodes indicates that the data is being repartitioned across the cluster to align join keys on the same worker nodes. This full shuffle is costly in terms of network I/O. Recognizing this pattern helps analysts understand why large joins can be slow and justifies investigating whether tables can be pre-partitioned to avoid these runtime exchanges.

Exam trap

Candidates often misinterpret Exchange nodes in execution plans as caching layers rather than recognizing them as heavy network shuffles during sort-merge joins.

10
MCQmedium

What is the primary benefit of using a 'Materialized View' in Databricks SQL for frequent, expensive queries?

A.It bypasses the need for Unity Catalog permissions.
B.It automatically scales the cluster to infinite size.
C.It stores precomputed results to improve read performance.
D.It eliminates the need for any data partitioning.
AnswerC

By storing the results of the query, a materialized view allows the engine to return data immediately without re-executing complex logic or aggregations. This is highly effective for dashboarding and reporting scenarios where the same complex query is run repeatedly by multiple users throughout the business day.

Why this answer

Materialized views precompute query results, allowing for faster read performance by storing the output rather than recalculating it on every request. This is critical for data analysts working with large, complex datasets, as it significantly reduces latency and compute costs for repetitive dashboards or reports. By shifting the workload from query time to refresh time, analysts can provide consistent and fast performance for their business stakeholders.

Exam trap

Candidates often confuse materialized views with standard views or caching mechanisms, assuming they update dynamically on every single read rather than being precomputed and periodically refreshed.

11
MCQmedium

A data analyst notices that a query involving a large join between two tables is consistently slow. The analyst suspects that one of the tables is significantly skewed. Which tool in the Databricks SQL query profile is most effective for confirming this skew?

A.The Query History list view.
B.The SQL Query Profile 'Metrics' tab.
C.The Cluster Usage dashboard.
D.The Table details metadata panel.
AnswerB

The Query Profile metrics provide deep visibility into task-level statistics, including the minimum, maximum, and median rows processed per task. If the maximum row count significantly exceeds the median, it confirms data skew, allowing the analyst to implement partitioning strategies like salting to balance the workload across executors.

Why this answer

The Query Profile provides visual metrics to identify bottlenecks. By examining the 'Max vs Median' row count metrics per task, an analyst can see if specific executors are processing significantly more data than others, indicating skew. Understanding data distribution is critical in Databricks, as skew often leads to 'straggler' tasks that delay entire query execution, regardless of overall cluster size or compute power.

Exam trap

Candidates tend to look at cluster-level CPU utilization or overall duration metrics, missing task-level distribution details required to isolate specific data skew issues.

12
Multi-Selecthard

A data analyst is analyzing a slow-running Databricks SQL query. The analyst suspects that the query is suffering from excessive shuffling. Which two actions should the analyst take to reduce shuffle and improve performance? (Choose two.)

Select 2 answers
A.Repartition the large table on a high-cardinality column before the join.
B.Enable Adaptive Query Execution (AQE) to dynamically coalesce shuffle partitions.
C.Increase the number of shuffle partitions by setting spark.sql.shuffle.partitions to a very high value.
D.Use broadcast joins for small tables to avoid shuffling the large table.
E.Cache the large table in memory to avoid shuffling it in subsequent operations.
AnswersB, D

AQE can dynamically coalesce small shuffle partitions into larger ones, reducing the number of tasks and overhead. It also can optimize skew joins. Enabling AQE (spark.sql.adaptive.enabled=true) is a recommended practice to reduce shuffle-related inefficiencies, especially when partition sizes are uneven.

Why this answer

Enabling AQE allows dynamic coalescing of shuffle partitions and skew handling, reducing shuffle overhead. Using broadcast joins for small tables avoids shuffling the large table entirely. Both are effective strategies to minimize shuffle and improve query performance.

Exam trap

The trap here is thinking that increasing shuffle partitions or caching always helps; instead, AQE and broadcast joins are targeted at reducing shuffle volume and overhead.

13
MCQmedium

An analyst is optimizing a query that performs multiple aggregations on a Delta table. Which TWO actions can the analyst take to improve query performance via the SQL editor?

A.Use Z-Ordering on columns frequently used in WHERE filters.
B.Enable partition pruning by including partition columns in the WHERE clause.
C.Increase the cluster size to 'Large' for every query execution.
D.Force a Broadcast Join for all small tables.
E.Convert all tables to Parquet format.
AnswerA, B

Z-Ordering co-locates related data in the same set of files, significantly enhancing data skipping capabilities. By clustering data based on frequently filtered columns, the engine can ignore irrelevant files during query execution, leading to faster data retrieval and lower overall compute resource consumption for the query.

Why this answer

Improving performance requires reducing the amount of data read. Using partition pruning allows the engine to skip irrelevant files, while Z-Ordering improves data skipping by clustering related information together. These techniques are fundamental for Databricks SQL performance, as they minimize I/O overhead.

Mastering these adjustments allows analysts to write highly efficient code that scales effectively with growing datasets, reducing both latency and costs for the organization.

Exam trap

Candidates often suggest adding more compute resources or changing the cluster type as a first step, ignoring that query-level optimizations like pruning and Z-Ordering are far more effective.

14
MCQmedium

A data analyst runs a Databricks SQL query that joins a 50 GB fact_sales Delta table with a 200 MB dim_product Delta table. The query takes 15 minutes. The analyst runs EXPLAIN FORMATTED and sees a SortMergeJoin instead of a BroadcastHashJoin. The analyst has already confirmed that the small table is not being broadcast. Which action should the analyst take to improve performance?

A.Add a broadcast hint to the large fact table so it is replicated to all executors.
B.Increase spark.sql.autoBroadcastJoinThreshold to a value larger than 200 MB, such as 250 MB, so the small table can be broadcast.
C.Set spark.sql.autoBroadcastJoinThreshold to -1 to disable broadcasting and force a shuffle hash join.
D.Repartition both tables on the join key before the join to ensure co-located partitions.
AnswerB

The default auto broadcast join threshold is 10 MB, so a 200 MB table is not broadcast. Increasing the threshold above 200 MB allows Spark to broadcast the small table, converting the SortMergeJoin into a BroadcastHashJoin. This eliminates the shuffle of the large fact table and significantly improves performance.

Why this answer

Increasing the auto broadcast join threshold above the size of the small table enables Spark to broadcast it, converting the SortMergeJoin to a BroadcastHashJoin. This avoids shuffling the large fact table, which is the main cost. The default threshold is 10 MB, so a 200 MB table is not broadcast unless the threshold is raised.

Exam trap

The trap here is assuming that broadcast joins are automatically used for any small table, when in fact the default threshold is only 10 MB and must be increased for larger small tables.

15
MCQeasy

A data analyst writes a query in the Databricks SQL editor that returns an error stating the column cannot be resolved, even though the analyst is certain the column exists in the Delta table. The analyst wants to quickly confirm the actual column names and data types of the table before editing the query. Which approach is most efficient?

A.Run DESCRIBE TABLE on the table in the SQL editor
B.Open the table's Delta transaction log JSON files and read the schema
C.Query the table with SELECT * and inspect the result grid columns
D.Recreate the table with a CREATE OR REPLACE statement matching the intended schema
AnswerA

DESCRIBE TABLE returns the column names, data types, and comments for the table, letting the analyst verify exact spelling and casing without leaving the SQL editor. This is the fastest way to confirm the real schema and correct the unresolved column reference, since it queries the metastore metadata directly rather than scanning data.

Why this answer

DESCRIBE TABLE reads table metadata from the metastore and returns column names, data types, and comments without scanning data. That makes it the fastest, cheapest way to confirm exact spelling and casing so the analyst can fix the unresolved column reference in the query.

Exam trap

The trap here is running SELECT * to eyeball column names, which scans data and still hides declared types and comments.

16
MCQmedium

When analyzing query performance, what does a high 'Spill to Disk' metric indicate?

A.The query is successfully using the cache.
B.The cluster has insufficient memory for the operation.
C.The data is highly compressed.
D.The query is finished and writing results to the table.
AnswerB

Spilling happens when a transformation, such as a large-scale shuffle or aggregate, consumes more memory than allocated. The system temporarily moves data to disk to prevent an 'OutOfMemory' crash. This slows the query down significantly, suggesting that the memory allocation per executor should be increased or the query optimized.

Why this answer

Spilling to disk occurs when a query's operations, such as sorts or joins, exceed the available memory in the cluster's executors. This is a major performance bottleneck because disk I/O is exponentially slower than memory. Recognizing this indicator is crucial for analysts because it signals that the current cluster size or query logic needs adjustment to fit the workload comfortably within RAM, significantly improving query speed and stability.

Exam trap

Test-takers frequently attribute disk spilling to slow network latency or poor storage speeds rather than recognizing memory exhaustion.

17
MCQhard

Refer to the exhibit. An analyst examines the physical execution plan of a Spark SQL join query. Based on the provided plan output, which optimization strategy was automatically applied by Adaptive Query Execution (AQE)?

A.Dynamic partition pruning was used to eliminate scanning partitions on the orders table.
B.AQE dynamically converted a sort-merge join into a broadcast hash join based on runtime size statistics.
C.Skew join optimization was triggered to split the skewed partition keys into multiple sub-tasks.
D.The Catalyst optimizer pushed down aggregations past the join boundary to reduce intermediate data size.
AnswerB

Adaptive Query Execution evaluates runtime size metrics after executing child stages. When the size of the filtered 'products' table fell below the broadcast threshold, AQE replaced the costly sort-merge join with an efficient broadcast hash join, avoiding a heavy shuffle.

Why this answer

Adaptive Query Execution in Databricks dynamically optimizes query plans at runtime based on precise statistics gathered from completed shuffle stages. The exhibit clearly displays a BroadcastHashJoin where the right side of the join was converted from a sort-merge join into a broadcast join using a broadcast exchange stage.

Exam trap

Candidates often assume the optimizer always chooses the most efficient join method, failing to recognize the specific 'BroadcastHashJoin' signature in the plan as a result of runtime AQE optimizations.

18
Multi-Selecthard

A data analyst is investigating why a specific Spark SQL query takes an exceptionally long time to complete and exhibits signs of severe data skew. Which TWO metrics or behaviors in the Databricks Spark UI typically indicate that data skew is impacting the query? (Choose two)

Select 2 answers
A.The maximum task duration is drastically higher than the 75th and median task durations for a given stage.
B.The total number of input files scanned is zero because all data is successfully pruned by partition filters.
C.Specific tasks show high amounts of spill to disk for memory-heavy operations like aggregations and joins.
D.The driver node runs out of memory during the initial parsing phase before any execution stages are generated.
E.All tasks across all worker nodes complete in nearly identical timeframes with minimal variance.
AnswersA, C

A wide gap between the median task duration and the maximum task duration is a primary hallmark of data skew. Most tasks complete rapidly, but the stage cannot finish until the few tasks processing the skewed partition keys finish executing their workloads.

Why this answer

Data skew occurs when records are unevenly distributed across partitions, causing a few tasks to process the vast majority of data while others finish quickly. In the Spark UI, this manifests as a massive disparity between task duration percentiles and extremely high memory consumption or spill metrics on the tasks handling the skewed keys.

Exam trap

Students often mistake general cluster slowness for data skew, failing to check the specific percentile task duration gaps in the Spark UI.

19
MCQmedium

When reviewing a query profile, an analyst sees a 'Broadcast Hash Join'. What does this tell the analyst about the data being joined?

A.The join is extremely memory-intensive.
B.One of the tables is small enough to fit in memory.
C.The query is performing a cross join.
D.The data is skewed and needs re-partitioning.
AnswerB

The optimizer selects a broadcast join when it determines that one table is small enough to be replicated across all nodes. This avoids shuffling the larger table, which drastically speeds up execution. If the analyst sees this, it confirms the optimizer is leveraging the table size effectively.

Why this answer

A Broadcast Hash Join indicates that one side of the join is small enough to be sent to all executor nodes. This is an extremely efficient join type as it eliminates shuffling. For analysts, recognizing this confirms that the optimizer has successfully identified a small table, which is a positive performance indicator.

If a join is expected to be small but isn't broadcast, the analyst may need to check table statistics.

Exam trap

Candidates assume a Broadcast Hash Join means both tables are large, missing the fact that it is only triggered when one table is small.

20
MCQmedium

Why should an analyst use the 'EXPLAIN' command before running a complex SQL query on a very large dataset?

A.To bypass the authentication requirement for queries.
B.To view the projected cost in US Dollars.
C.To verify the query plan and identify inefficiencies.
D.To automatically apply Z-Ordering to the table.
AnswerC

EXPLAIN outputs the execution plan, showing how the engine intends to scan, join, and aggregate the data. Reviewing this allows analysts to see potential bottlenecks like full table scans or expensive shuffles. By identifying these early, they can adjust the query logic to be more performant before execution.

Why this answer

The EXPLAIN command provides the logical and physical execution plan without actually running the query. For analysts, this is a proactive safety and performance measure. It allows them to spot inefficient patterns, such as unexpected cross joins or massive data shuffles, before consuming expensive compute resources.

This practice is essential for cost control and ensuring that queries are optimized for the scale of the underlying production data.

Exam trap

Candidates assume EXPLAIN is only for debugging errors, ignoring its critical role in performance tuning and cost estimation by revealing the underlying execution plan before runtime.

21
MCQmedium

An analyst is optimizing a dashboard that queries a Delta table partitioned by 'event_date'. The query filters on 'event_date' and 'user_id', but is still slow. What is the most effective next step to improve query speed?

A.Enable Liquid Clustering on the 'user_id' column.
B.Change the table format to Parquet to improve scan performance.
C.Increase the cluster's driver node memory.
D.Rewrite the query to use a subquery instead of a JOIN.
AnswerA

Liquid Clustering allows the table to automatically organize data based on query patterns, including 'user_id'. It replaces traditional partitioning and Z-Ordering with a more flexible, adaptive approach that improves performance for high-cardinality filters by clustering relevant data together without requiring manual management of partition columns or Z-Order schemes.

Why this answer

Partitioning by date is good for coarse pruning, but if 'user_id' is the primary filter, the engine still scans all files within the selected dates. Z-Ordering by 'user_id' creates data skipping metadata that allows the engine to skip files not containing the specific user, drastically reducing data read volume. This is a critical optimization for high-cardinality columns used in frequent point-lookups.

Exam trap

Candidates often suggest adding more compute or changing partition columns. They fail to realize that Z-Ordering or Liquid Clustering is required to optimize high-cardinality columns not used in partitioning.

22
MCQmedium

A data analyst needs to inspect the logical and physical execution plans of a slow Spark SQL query to understand how filters and joins are being evaluated. Which command should the analyst execute in a Databricks notebook cell?

A.DESCRIBE EXTENDED table_name;
B.EXPLAIN EXTENDED SELECT * FROM table_name WHERE condition;
C.SHOW QUERY PLAN FOR SELECT * FROM table_name WHERE condition;
D.ANALYZE TABLE table_name COMPUTE STATISTICS FOR COLUMNS;
AnswerB

EXPLAIN EXTENDED generates a comprehensive breakdown of the query lifecycle, showing the logical optimizations and physical operators chosen by the Catalyst optimizer. This insight is vital for diagnosing performance bottlenecks and verifying predicate pushdown.

Why this answer

The EXPLAIN command in Spark SQL outputs the execution plans, including parsed logical plan, analyzed logical plan, optimized logical plan, and physical plan. Analyzing these plans helps data analysts identify inefficient join strategies, missing predicate pushdown, and unnecessary full table scans.

Exam trap

Candidates confuse the simple EXPLAIN command with EXPLAIN EXTENDED, failing to realize that the latter is required to see the full logical and physical plan details needed for deep analysis.

23
Multi-Selecthard

A data analyst is reviewing the Query Profile in Databricks SQL for a query that spills data to disk during a sort operation. Which two metrics should the analyst examine to confirm and diagnose the spill? (Choose two.)

Select 2 answers
A.Spill (Disk) Size
B.Number of Output Rows
C.Total Time Spent in Shuffle
D.Shuffle Read Size
E.Peak Execution Memory
AnswersA, E

Spill (Disk) Size is a metric in the Query Profile that specifically reports the amount of data written to disk due to memory overflow during operations like sort or aggregation. A non-zero value confirms that spilling occurred. The analyst should examine this metric to verify the spill and its magnitude, which helps in tuning memory configurations or query logic.

Why this answer

Spill (Disk) Size directly quantifies data written to disk due to memory overflow, confirming spill. Peak Execution Memory indicates memory pressure that causes spill. Together, they diagnose spill during sort.

Other metrics like shuffle read size or output rows do not directly measure spill and are less relevant for this specific issue.

Exam trap

The trap here is confusing shuffle-related metrics with spill metrics; spill is a distinct phenomenon that can occur without shuffles and is measured by specific spill counters.

24
MCQmedium

A data analyst runs an Apache Spark SQL query against a Delta Lake table and notices that partition pruning is not occurring despite filtering on the partitioned column 'region'. The table definition shows 'region' is stored as a string, but the query passes an integer value. How does this type mismatch impact query execution?

A.Spark automatically casts the column to match the filter type without impacting performance.
B.The query fails immediately with a TypeMismatch analysis exception before any jobs are launched.
C.Catalyst fails to match directory paths to filter values, forcing a full table scan across all partitions.
D.Delta Lake automatically rewrites the underlying table schema to match the incoming query filter type.
AnswerC

When data types do not align precisely between the filter predicate and the partition schema definition, the Catalyst optimizer cannot safely evaluate directory paths against static partition filters. Consequently, the query engine bypasses partition pruning and reads all files, leading to significantly degraded performance.

Why this answer

Type mismatches between predicate filters and partition columns prevent catalyst optimization from pushing down partition filters. Spark attempts implicit casting, which often invalidates static partition pruning mechanisms, forcing the engine to scan every single data file across all partitions, drastically increasing input data volume and slowing down query execution performance.

Exam trap

Candidates overlook data types in filter predicates, assuming implicit casting always preserves partition pruning and optimization efficiencies.

25
MCQmedium

A data analyst runs a Databricks SQL query that joins a 40 GB Delta table to a 12 GB Delta table and the Query Profile shows two Exchange nodes surrounding a SortMergeJoin. The analyst wants to confirm whether the shuffle is the dominant cost before rewriting the query. Which Query Profile metric should the analyst inspect first to quantify the shuffle's impact?

A.Peak memory usage of the driver process
B.Rows read from the smaller table's scan operator
C.Number of files scanned in the Delta table directory
D.Shuffle write bytes and shuffle read bytes on the Exchange nodes
AnswerD

The Exchange nodes are the shuffle boundaries, so their shuffle write and read byte counts directly measure how much data Spark serialized, spilled, and pulled across the network. These values quantify the redistribution cost that dominates a SortMergeJoin with two Exchanges, letting the analyst confirm whether shuffle volume is the bottleneck before rewriting the query.

Why this answer

The Exchange operators are the shuffle stages that redistribute rows by join key before the SortMergeJoin, so their shuffle write and read byte counts are the direct measurement of redistribution cost. Inspecting those byte totals tells the analyst whether the shuffle dominates runtime and justifies alternatives such as broadcast join or pre-partitioning.

Exam trap

The trap here is assuming any single operator's row count explains join slowness, when the Exchange byte metrics are what actually size the shuffle.

26
MCQmedium

A data analyst runs a query against a large Delta table partitioned by date. The query filters on a timestamp column rather than the date partition column. How does Databricks handle this query execution?

A.The query automatically re-partitions the Delta table on the fly to match the timestamp filter.
B.The engine evaluates the timestamp column to prune partitions directly mapped to timestamps.
C.The query optimizer performs a full scan of all partitions because partition pruning requires filters on the exact partition columns.
D.Databricks converts the timestamp into the partition column format and successfully prunes partitions.
AnswerC

Partition pruning is strictly tied to the columns specified in the PARTITIONED BY clause. Without a direct equality or range filter on those specific partition columns, the query engine must scan every file in the storage directory.

Why this answer

Databricks performs partition pruning based on the partition columns defined in the table metadata. When filtering on a timestamp column that differs from the partition column, the query engine cannot prune partitions effectively, resulting in a full table scan of all files unless liquid clustering or secondary indexing is applied. This optimization is critical for maintaining high query performance on large datasets.

Exam trap

Candidates assume the query optimizer can automatically derive partition pruning from any datetime attribute, missing that filters must target the exact partition column.

27
MCQmedium

A data analyst is troubleshooting a slow-running SQL query against a massive Delta table in Databricks. The query frequently scans the entire table despite filtering on a high-cardinality timestamp column. Which approach will most effectively reduce the data scanned by eliminating full-table reads?

A.Run an OPTIMIZE command with a ZORDER BY clause on the timestamp column to co-locate related data and improve data skipping.
B.Increase the cluster size to a driver instance with more memory to hold the entire uncompressed Delta table in cache.
C.Execute a VACUUM command with a retention threshold of zero hours to purge old data files immediately.
D.Convert the Delta table format to standard Parquet files to take advantage of native Apache Spark partitioning.
AnswerA

Z-Ordering clusters data with similar values into the same file spaces. This enables the Delta Lake file-skipping mechanism to bypass irrelevant files entirely when queries apply range filters on the target timestamp column, directly lowering overall scan volume and query duration.

Why this answer

Z-Ordering co-locates related data based on specified columns, significantly improving data skipping for queries with equality or range filters. When combined with correct partitioning, it minimizes the amount of data scanned from cloud storage, drastically reducing query latency and execution costs in Databricks environments.

Exam trap

Candidates often suggest partitioning by high-cardinality columns like timestamps, which is a major anti-pattern that creates too many small files and metadata overhead, drastically hurting performance.

28
MCQeasy

A data analyst runs a query in Databricks SQL that returns the total sales per region. The query is slow, and the analyst notices that the execution plan shows a full table scan on a large Delta table. The analyst wants to reduce the amount of data read. Which action is most likely to improve performance?

A.Use a broadcast hint to force a broadcast join.
B.Cache the table using CACHE TABLE before running the query.
C.Add a WHERE clause on a partitioned column to enable partition pruning.
D.Increase the cluster size to add more worker nodes.
AnswerC

If the table is partitioned on a column used in a filter, adding a WHERE clause on that column allows Delta to skip entire partitions. This reduces the data read from the full table scan to only relevant partitions, directly addressing the slow performance caused by scanning all data.

Why this answer

Partition pruning is the most direct way to reduce data read. By filtering on a partitioned column, Delta Lake can skip partitions that do not match the filter, turning a full table scan into a targeted read. Other options do not reduce the volume of data read or are inapplicable to an aggregation query.

Exam trap

The trap here is focusing on cluster resources or caching instead of addressing the fundamental issue: reading unnecessary data due to lack of partition pruning.

29
MCQhard

An analyst is troubleshooting a query that hangs indefinitely during a join. Which TWO metrics in the Query Profile should the analyst examine to diagnose the issue?

A.Shuffle Read/Write bytes.
B.Maximum vs Median rows per task.
C.The number of users logged into the workspace.
D.The total number of tables in the schema.
E.The total size of the database logs.
AnswerA, B

High shuffle bytes indicate that large amounts of data are being exchanged across the network nodes. If a query hangs, it may be due to this massive data movement exceeding the cluster's network or I/O bandwidth, suggesting a need to reduce the data volume or optimize the join strategy.

Why this answer

When a join hangs, it is often due to massive data movement (shuffle) or extreme data skew. Monitoring the shuffle size helps determine if the network or I/O is saturated. Checking the 'Max vs Median' row count helps identify skew.

These metrics are the most reliable indicators of join failure, enabling analysts to decide whether to adjust join keys, use broadcast hints, or address underlying data distribution issues.

Exam trap

Candidates often look at general cluster metrics like total memory instead of join-specific indicators such as shuffle bytes and row disparities.

30
MCQmedium

A data analyst is querying a large Delta table containing billions of rows of clickstream data. The table is frequently queried using a timestamp column. To optimize range queries on this timestamp, which Delta Lake feature should the table builder implement?

A.Enabling column mapping to allow renaming columns without rewriting underlying parquet files.
B.Applying Z-Order clustering on the timestamp column to improve multi-dimensional data skipping.
C.Setting the file size compaction threshold to the maximum allowable limit of 1 gigabyte.
D.Adding an explicit check constraint on the timestamp column to reject future dates.
AnswerB

Z-Ordering algorithmically rearranges data within Delta parquet files to collocate similar values. This significantly tightens minimum and maximum statistics stored in the Delta transaction log, enabling the data skipping mechanism to bypass irrelevant files during range queries.

Why this answer

Delta Lake features like Z-Ordering colocate related information in the same set of files based on specified columns. However, for efficient range filtering on high-cardinality timestamps, Liquid Clustering or traditional Z-Ordering combined with proper partitioning or data skipping statistics ensures the engine reads minimal files.

Exam trap

Exam takers frequently confuse standard partition columns with Z-Order clustering, forgetting that multi-dimensional data skipping relies on specific clustering strategies.

31
MCQmedium

When analyzing query execution metrics in Databricks, what does 'Task Duration' represent?

A.The time taken to compile the SQL query.
B.The time elapsed for a single core to process a task.
C.The total time the cluster was running.
D.The latency added by network overhead only.
AnswerB

Task Duration reflects the time spent by a specific core on a specific partition of the data. By comparing the durations across different tasks, an analyst can detect stragglers. If most tasks finish quickly but one takes much longer, it indicates an imbalance in data partitioning or workload distribution.

Why this answer

Task Duration measures the time taken by individual executor nodes to perform their assigned portion of the work. It is distinct from total query time because it highlights parallel execution efficiency. Understanding this is vital because if one task is much longer than others, it indicates data skew or uneven distribution, helping analysts identify the root cause of performance bottlenecks that are hidden within the overall query execution time.

Exam trap

Candidates often confuse task duration with total wall-clock query execution time or cluster uptime, misunderstanding that it tracks individual core processing duration.

32
MCQeasy

An analyst is writing a query in Databricks and needs to reference a temporary view that is scoped only to their current interactive notebook session. Which command or syntax ensures the view is automatically dropped when the session ends?

A.CREATE GLOBAL TEMP VIEW view_name AS SELECT ...
B.CREATE TABLE view_name AS SELECT ...
C.CREATE TEMP VIEW view_name AS SELECT ...
D.CREATE MANAGED VIEW view_name AS SELECT ...
AnswerC

Creating a standard temporary view binds its existence directly to the current SparkSession. It provides a convenient way to encapsulate complex subqueries and joins for the duration of an interactive notebook session without writing permanent metadata to the catalog.

Why this answer

Spark SQL supports various view scopes for different collaboration needs. A standard temporary view is tied to the lifecycle of the active SparkSession. Once the notebook session terminates, the temporary view is automatically cleaned up, preventing namespace pollution in shared database catalogs.

Exam trap

Candidates often confuse 'TEMP VIEW' with 'GLOBAL TEMP VIEW', incorrectly believing that a standard temporary view is visible across different Spark sessions or notebooks, which leads to 'table not found' errors.

33
MCQhard

A data analyst runs a query on a Delta table with a WHERE clause on a timestamp column, but the query scans the entire table. The analyst checks the table's metadata and sees that the column is not a partition column but is frequently used in filters. The analyst wants to enable data skipping to avoid full scans. Which action should the analyst take?

A.Set spark.sql.parquet.filterPushdown to true to enable filter pushdown on the timestamp column.
B.Run OPTIMIZE with ZORDER on the timestamp column to co-locate related data and improve data skipping.
C.Convert the table to a partitioned table using the timestamp column as the partition key.
D.Enable Delta Lake change data feed on the table to track changes to the timestamp column.
AnswerB

Z-ordering on a frequently filtered column rearranges data files so that related values are clustered together. This allows Delta Lake to skip files using min/max statistics, even if the column is not a partition. Running OPTIMIZE with ZORDER on the timestamp column will improve data skipping for queries filtering on that column.

Why this answer

Z-ordering on a frequently filtered column clusters data so that min/max statistics can be used to skip files. This is ideal for high-cardinality columns like timestamps where partitioning would create too many small files. OPTIMIZE with ZORDER rearranges data without changing the table structure.

Exam trap

The trap here is confusing partitioning with Z-ordering; partitioning on a timestamp column creates many small partitions, while Z-ordering provides data skipping without partitioning overhead.

34
Multi-Selecthard

An analyst is reviewing a slow-running query and wants to identify potential bottlenecks. Which TWO of the following metrics in the Databricks SQL query profile are most indicative of inefficient data distribution?

Select 2 answers
A.Shuffle Read/Write bytes are significantly higher than the input data size.
B.The 'Scan' node shows high throughput and low execution time.
C.Task duration distribution shows one task taking much longer than others.
D.The query shows a high number of file metadata operations.
E.The query plan indicates a broadcast hash join is being used.
AnswersA, C

High shuffle volumes compared to input data often suggest unnecessary data movement or poor join strategies. If the shuffle size is much larger than the original input, the query is likely re-distributing data inefficiently, which adds substantial network latency and increases the risk of executor memory errors.

Why this answer

Data skew and excessive shuffling are primary causes of performance degradation. High 'Shuffle Read' and 'Shuffle Write' values indicate large amounts of data moving across the network, while skewed task durations signal that one executor is doing significantly more work than others. Identifying these metrics early allows analysts to apply techniques like salting keys or partitioning to balance the workload across the cluster.

Exam trap

Candidates often look only at total query execution time instead of specific distributed metrics like shuffle read/write bytes and skewed task durations to diagnose bottlenecks.

35
MCQmedium

A data analyst notices that a query performing a join between a large fact table and a small dimension table is slow. The analyst wants to ensure that the small table is broadcasted to all executors to avoid a shuffle. Which configuration should the analyst adjust to increase the likelihood of a broadcast join?

A.spark.sql.autoBroadcastJoinThreshold
B.spark.sql.adaptive.enabled
C.spark.sql.shuffle.partitions
D.spark.sql.broadcastTimeout
AnswerA

This configuration sets the maximum size (in bytes) of a table that can be broadcasted in a join. By increasing this threshold, the analyst allows larger tables to be considered for broadcast, which can eliminate the shuffle of the large table. In this scenario, if the small dimension table's size is below the threshold, it will be broadcasted, improving join performance.

Why this answer

The key to encouraging a broadcast join is to ensure the small table's size is below the autoBroadcastJoinThreshold. By increasing this threshold, the analyst allows Spark to consider the small table for broadcast, eliminating the shuffle of the large table and significantly speeding up the join.

Exam trap

The trap here is thinking that enabling adaptive query execution alone guarantees a broadcast join, when it still depends on the autoBroadcastJoinThreshold setting.

36
MCQmedium

An analyst executes a query that joins a large fact table with a small dimension table in Databricks. The analyst wants to force the Catalyst optimizer to broadcast the small dimension table to avoid an expensive shuffle join. Which standard Spark SQL hint should be included in the query text?

A./*+ MERGE(dimension_table) */
B./*+ SHUFFLE_HASH(dimension_table) */
C./*+ BROADCAST(dimension_table) */
D./*+ CACHE(dimension_table) */
AnswerC

The BROADCAST hint explicitly requests that the Catalyst optimizer send a copy of the specified table to all worker nodes in the cluster. This enables a broadcast hash join, completely eliminating the network shuffle phase and improving performance for joins involving small tables.

Why this answer

Query hints allow analysts to provide explicit instructions to the Catalyst optimizer regarding physical execution plans. The MAPJOIN or BROADCAST hint directs the engine to broadcast the smaller table to all worker nodes, eliminating the need for a costly shuffle exchange across the network and greatly accelerating join execution performance.

Exam trap

Candidates frequently mistake generic Spark configuration settings for SQL-specific hints, or they attempt to use incorrect syntax like '/*+ BROADCASTJOIN */' instead of the standard '/*+ BROADCAST(table) */' syntax.

37
MCQmedium

A data analyst runs a Databricks SQL query on a Delta table that has 500,000 small files. The query applies a filter on a high-cardinality column but still scans all files, resulting in slow performance. The analyst wants to reduce the number of files scanned without changing the query logic. Which action should the analyst take?

A.Set spark.sql.adaptive.enabled to false to force a static execution plan.
B.Run OPTIMIZE on the table to compact small files and improve data skipping.
C.Increase the driver node size to handle the large number of files.
D.Add a Z-ORDER BY clause to the query to sort results by the filtered column.
AnswerB

OPTIMIZE compacts small files into larger ones and collects statistics, which enables Delta data skipping. With 500,000 small files, the query must open each file; compaction reduces file count and allows the engine to skip files based on min/max statistics, directly improving scan performance without altering query logic.

Why this answer

Compacting small files with OPTIMIZE reduces the number of files that must be opened and enables Delta data skipping through collected statistics. This directly addresses the root cause: too many small files causing excessive I/O. Other options either disable useful optimizations, misuse syntax, or only mask the problem without reducing file count.

Exam trap

The trap here is assuming that increasing cluster resources or altering query syntax will solve a small-file problem, when the real fix is file compaction and statistics collection.

38
MCQhard

Refer to the exhibit. A data analyst reviews a physical execution plan where a table is scanned and shuffled multiple times in succession during a self-join operation. What underlying anti-pattern in the query construction likely caused this redundant exchange?

A.The analyst applied a broadcast hint to a table that exceeded the broadcast size configuration threshold.
B.The table was referenced multiple times in complex join logic without caching, causing Spark to recompute its lineage.
C.The partition column data type mismatch forced Catalyst to duplicate the partition directories.
D.Automatic table compaction via OPTIMIZE was running concurrently during the execution phase.
AnswerB

Repeated references to the same table without caching force Spark to re-read and re-shuffle its lineage for each join branch. Persisting or caching the table breaks this recomputation, eliminating the redundant exchanges visible in the physical plan.

Why this answer

Redundant exchanges and scans in an execution plan often occur when a DataFrame or table is referenced multiple times in complex joins or transformations without being cached or persisted. Spark recomputes the lineage from storage for each reference, leading to duplicate scans and shuffles.

Exam trap

Candidates often blame external factors like cluster configuration for performance issues, overlooking the fundamental Spark behavior where un-cached DataFrames are recomputed from their source lineage upon every reference.

39
MCQhard

A data analyst runs a query that joins a fact table to a dimension table and groups by a dimension attribute. The Query Profile shows a BroadcastHashJoin, yet the query still takes much longer than expected and one stage shows a single task consuming most of its runtime. The dimension table is small, so the analyst suspects the bottleneck is elsewhere. Which explanation best fits the evidence?

A.The grouping key is skewed, so one task in the aggregation stage processes far more rows than the others
B.The fact table lacks statistics, causing Spark to choose a nested loop join
C.The broadcast of the small table is failing and silently falling back to a sort-merge join
D.The dimension table is too large to broadcast and must be repartitioned before joining
AnswerA

A BroadcastHashJoin eliminates shuffle for the join, so the remaining bottleneck is likely the post-join aggregation. If one dimension attribute value is extremely common, the group-by partitions unevenly and a single task handles most rows, producing exactly the long-running straggler task the profile shows despite the efficient join.

Why this answer

Because the broadcast join removes shuffle from the join itself, the remaining slow stage with one dominant task is the aggregation. An unevenly distributed grouping key concentrates most rows into one partition, so that task runs far longer than its peers. Addressing the skew in the group-by, not the join, is what improves runtime.

Exam trap

The trap here is assuming the slow join is the culprit, when an efficient broadcast join can coexist with a skewed aggregation downstream.

Ready to test yourself?

Try a timed practice session using only Da Analyzing Queries questions.