<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: From 40 Minutes to 8 minutes: Why We Dropped MERGE in Our SAP BW to Databricks Gold Layer in Community Articles</title>
    <link>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165319#M1422</link>
    <description>&lt;P&gt;Great work, keep posting!!&lt;/P&gt;</description>
    <pubDate>Tue, 11 Aug 2026 07:49:15 GMT</pubDate>
    <dc:creator>VinayKumarB</dc:creator>
    <dc:date>2026-08-11T07:49:15Z</dc:date>
    <item>
      <title>From 40 Minutes to 8 minutes: Why We Dropped MERGE in Our SAP BW to Databricks Gold Layer</title>
      <link>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165310#M1418</link>
      <description>&lt;H1&gt;Infra keeps getting faster, but the fix for a slow notebook is usually a config line, not a bigger cluster.&lt;/H1&gt;&lt;PRE&gt;One Spark Config, 32 Minutes Saved: Replacing MERGE with Dynamic Partition Overwrite&lt;/PRE&gt;&lt;P&gt;By &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/247254"&gt;@Phani_sannala&lt;/a&gt;&amp;nbsp;, co-authored with&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/85833"&gt;@sridharplv&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Our gold notebook processed a few million rows daily and took 40+ minutes. The bottleneck was not the cluster. It was MERGE.&lt;/P&gt;&lt;H2&gt;The insight: BW does not send changed rows, it sends slices&lt;/H2&gt;&lt;P&gt;SAP BW style extracts do not tell you "these 37 rows changed." They hand you the complete, restated fiscal period, top to bottom. If the source gives you the authoritative full slice, a row-level reconciliation tool is answering a question you never asked.&lt;/P&gt;&lt;H2&gt;What MERGE cost us&lt;/H2&gt;&lt;P&gt;The join. Every run, a shuffle-heavy join against the full target, just to rediscover what the source contract already told us.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The first version of every gold notebook ended the same way, because that’s what every tutorial and every instinct tells you to do with incremental loads:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MERGE INTO gold.working_capital t
USING staging s
ON  t.company_code  = s.company_code
AND t.fiscal_period = s.fiscal_period
AND t.doc_number    = s.doc_number
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *&lt;/LI-CODE&gt;&lt;P&gt;Write amplification. Rewriting every Parquet file that contains a touched row.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Reasonable. Defensive. Wrong for this workload.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Key fragility. SAP composite keys (ROCANCEL, record modes, language keys) are a minefield. Get the key slightly wrong and MERGE does not error. It silently duplicates or updates the wrong rows.&lt;/P&gt;&lt;H2&gt;The zombie row bug&lt;/H2&gt;&lt;P&gt;&lt;SPAN&gt;Cost and speed are annoying. This next one is a correctness bug, and it’s the strongest argument in the whole post.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Say your gold table holds this for period 006:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fiscal_period  doc_number  amount
-------------  ----------  ------
2026006        100         450   
2026006        101         250   
2026006        102         700&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Yesterday, document 102 was reversed in SAP. Today’s extract arrives with the complete restated period 006:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fiscal_period  doc_number  amount
-------------  ----------  ------
2026006        100         500   
2026006        101         250&lt;/LI-CODE&gt;&lt;P class=""&gt;Doc 100 got updated. Doc 101 is unchanged. And doc 102 is simply&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;absent&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;— the source’s way of saying it no longer exists.&lt;/P&gt;&lt;P class=""&gt;Now watch what MERGE does. It updates doc 100. It “updates” doc 101 to an identical value (wasted write). And doc 102? MERGE never even looks at it. MERGE only reasons about rows that&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;arrived&lt;/EM&gt;. Rows that vanished from the source are invisible to it. Doc 102 stays in your gold table forever — a zombie row — and your period total is now overstated by 700.&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN&gt;You can bolt on a&amp;nbsp;&lt;/SPAN&gt;WHEN NOT MATCHED BY SOURCE THEN DELETE&lt;SPAN&gt;&amp;nbsp;clause to handle this, but now you've made the expensive join even more expensive, and you'd better scope it perfectly to the incoming slices or you'll delete history you meant to keep. You're writing increasingly clever code to reimplement, badly, what partition overwrite gives you for free.&lt;/SPAN&gt;&lt;/P&gt;&lt;H2&gt;The fix: two lines&lt;/H2&gt;&lt;LI-CODE lang="markup"&gt;spark.conf.set("spark.sql.sources.partitionOverwriteMode", "dynamic")

df.write.insertInto("gold.working_capital", overwrite=True)&lt;/LI-CODE&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;What we gained&lt;/H2&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Speed&lt;/STRONG&gt;. 40+ minutes to under 8, on the same cluster. The reconciliation join is simply absent from the plan.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Correctness&lt;/STRONG&gt; by construction. No zombie rows, no dependency on getting an SAP composite key exactly right.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Idempotency&lt;/STRONG&gt; for free. Job dies halfway? Rerun it. The same partitions are overwritten and you land in the same end state.&lt;/P&gt;&lt;H2&gt;The honest fine print&lt;/H2&gt;&lt;P&gt;1. Slices must be complete. A partial extract will happily overwrite a full partition with 100 rows. Add a row-count sanity check so it fails loudly instead of deleting quietly.&lt;/P&gt;&lt;P&gt;2. insertInto matches columns by position, not by name. Reorder a select upstream and it will silently write revenue into the quantity column. Pin the final select to the target column order and assert the schema before the write.&lt;/P&gt;&lt;P&gt;3. Partition grain must match delivery grain. Partition by how the source delivers, not by what feels natural for queries.&lt;/P&gt;&lt;P&gt;4. replaceWhere works too. We preferred dynamic partition overwrite because the partitions to replace are inferred from the data, not from a predicate we would have to construct and keep correct every run.&lt;/P&gt;&lt;H2&gt;Takeaway&lt;/H2&gt;&lt;P&gt;MERGE is a great tool. It became a problem only because it was the default, applied without asking how the source actually delivers data. Before picking a write pattern, characterize the delivery pattern. Row-level CDC belongs to MERGE. Full-slice delivery belongs to partition overwrite.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2026 06:44:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165310#M1418</guid>
      <dc:creator>Phani_sannala</dc:creator>
      <dc:date>2026-08-11T06:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: From 40 Minutes to 8 minutes: Why We Dropped MERGE in Our SAP BW to Databricks Gold Layer</title>
      <link>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165312#M1419</link>
      <description>&lt;P&gt;Good one! Really useful insight.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2026 07:01:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165312#M1419</guid>
      <dc:creator>NikithaNalubala</dc:creator>
      <dc:date>2026-08-11T07:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: From 40 Minutes to 8 minutes: Why We Dropped MERGE in Our SAP BW to Databricks Gold Layer</title>
      <link>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165316#M1420</link>
      <description>&lt;P&gt;Great perspective! Choosing the right approach makes a huge difference.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2026 07:17:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165316#M1420</guid>
      <dc:creator>KarthikeyaBanda</dc:creator>
      <dc:date>2026-08-11T07:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: From 40 Minutes to 8 minutes: Why We Dropped MERGE in Our SAP BW to Databricks Gold Layer</title>
      <link>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165317#M1421</link>
      <description>&lt;DIV&gt;Great example of challenging conventional patterns. Sometimes the biggest performance gains come not from scaling infrastructure, but from rethinking the logic itself. 40 mins to 8 mins is a remarkable outcome.&lt;/DIV&gt;</description>
      <pubDate>Tue, 11 Aug 2026 07:42:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165317#M1421</guid>
      <dc:creator>sridhar_dbx</dc:creator>
      <dc:date>2026-08-11T07:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: From 40 Minutes to 8 minutes: Why We Dropped MERGE in Our SAP BW to Databricks Gold Layer</title>
      <link>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165319#M1422</link>
      <description>&lt;P&gt;Great work, keep posting!!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2026 07:49:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165319#M1422</guid>
      <dc:creator>VinayKumarB</dc:creator>
      <dc:date>2026-08-11T07:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: From 40 Minutes to 8 minutes: Why We Dropped MERGE in Our SAP BW to Databricks Gold Layer</title>
      <link>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165791#M1436</link>
      <description>&lt;P&gt;The zombie row bug is the real argument here reframing this from "MERGE is slow" to "MERGE is silently wrong for full-slice delivery" is what makes it land. Only thing I'd stress: dynamic partition overwrite is exactly as safe as your completeness check. Lose that row-count guard and you've swapped a slow-but-safe join for a fast-but-silent reload. The risk moves, it doesn't vanish. Great writeup.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2026 11:14:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/from-40-minutes-to-8-minutes-why-we-dropped-merge-in-our-sap-bw/m-p/165791#M1436</guid>
      <dc:creator>ozaaditya</dc:creator>
      <dc:date>2026-08-17T11:14:56Z</dc:date>
    </item>
  </channel>
</rss>

