Skip to content

A scenario for a data engineer · Senior and up

The MERGE takes two hours

Patch · Your teammate
Tuesday, 08:50

A nightly MERGE loads one day of events into a Delta table that holds three years, matching on event id alone. It reads almost every file in the table to look for matches.

What do you do?

Tap the one you would do. The answer opens below.

Show the best call

Add the event date to the match condition, so only the files for that day are searched.

The MERGE skips nearly the whole table and finishes in minutes.

Why

A MERGE has to find the rows that match. If the condition names only the key, any file might hold a match. Adding what you know, such as the dates the batch covers, lets Delta skip files that cannot match. It works best when the table is clustered or partitioned by that column.

Read it in the Databricks docs (opens in a new tab)

The other two

Works, at a price. Run it on a larger cluster with Photon.
Faster tonight, for more money, and slower again each month as the table grows.
A poor call. Switch to a plain append and remove duplicates in the reports.
The load is fast. The table now holds duplicates, and every reader has to deal with them.

The words in this scenario

MERGE.
One statement that compares new rows with a table by a key: rows that match are updated or deleted, rows that do not are inserted. In the docs (opens in a new tab)

Go deeper on brickster.ai

More scenarios

Had one like this at work? Send it to us: the best tickets come from real incidents.

Checked against the Databricks documentation on . brickster.ai is independent and is not affiliated with Databricks.