Hybrid DML

更新时间:
复制 MD 格式

Hybrid DML is the next-generation write engine in Hologres. It unifies INSERT, UPDATE, and DELETE execution behind a single adaptive operator that picks the optimal join and deduplication strategy at runtime, eliminating out-of-memory failures when loading large tables.

Overview

What is Hybrid DML

Hybrid DML is a new write engine developed by Hologres for INSERT, INSERT ON CONFLICT, UPDATE, and DELETE operations. It consolidates write logic that was previously scattered across multiple operators into a single intelligent operator (DataSetHybridDMLNode) that adapts its join and deduplication strategy to the actual data volume at runtime, eliminating out-of-memory (OOM) failures when loading large tables.

In short:

  • Legacy DML: the query optimizer (QO) decides the join algorithm up front and the execution engine (SE) follows a fixed plan. When the data volume exceeds the optimizer's estimate, the query is prone to OOM.

  • Hybrid DML: the execution engine selects the join strategy adaptively based on real-time data volume, ensuring that the query never runs out of memory -- it may run slower, but it never fails.

Key benefits

Dimension

Legacy DML

Hybrid DML

Stability

Large-table loads may hit OOM.

Adaptive strategy switching guarantees no OOM.

Performance

Depends on optimizer estimates; inaccurate estimates degrade performance.

Adapts at runtime, delivering more predictable performance.

Usability

Requires a DBA to tune join strategies manually.

Selects the strategy automatically; no manual tuning needed.

Execution plan

Four separate DML operators produce complex plans.

A single unified operator keeps the plan simple.

Benefits

Improved stability

With the legacy DML engine, when both the source (for example, a MaxCompute foreign table) and the target table are large, the Hash Join hash table can exceed the memory limit and cause the query -- or even the worker -- to OOM.

Hybrid DML embeds an adaptive decision engine (Game Machine) that monitors memory usage in real time as data is written batch by batch:

  • Small data volume: uses Hash Join for the best performance.

  • Medium data volume: automatically swaps the Hash Join build side, placing the smaller dataset in the hash table.

  • Large data volume: automatically falls back to Sort-Merge Join, which spills to disk and guarantees no OOM.

Performance gains

Scenario

Outcome

Small-table load

Performance is on par with legacy DML (takes the Hash Join path).

Large-table load (previously OOM)

Completes successfully instead of failing. Throughput is roughly one-third that of Hash Join.

INSERT ON CONFLICT DO UPDATE (all-column update)

Triggers Blind Merge, skips the join, and delivers a significant speedup.

Dynamic Table incremental refresh

Routes through Hybrid DML by default, making incremental writes more efficient.

Usage

Enable and disable

No SQL changes are required. Continue using standard INSERT, UPDATE, and DELETE statements. Hybrid DML is toggled with a GUC parameter.

Note

Hybrid DML is enabled by default in Hologres V3.1 and later. No manual configuration is required.

-- Enable Hybrid DML (on by default in Hologres V3.1 and later)
SET hg_experimental_enable_hybrid_dml = on;

-- Disable Hybrid DML and fall back to the legacy DML engine
SET hg_experimental_enable_hybrid_dml = off;

Examples

-- Make sure Hybrid DML is enabled
SET hg_experimental_enable_hybrid_dml = on;

-- Plain load
INSERT INTO holo_table SELECT * FROM mc_table;

-- Upsert on primary key
INSERT INTO holo_table
SELECT * FROM source_table
ON CONFLICT (pk_col) DO UPDATE SET
    col1 = EXCLUDED.col1,
    col2 = EXCLUDED.col2;

-- Ignore conflicts
INSERT INTO holo_table
SELECT * FROM source_table
ON CONFLICT (pk_col) DO NOTHING;

-- Load from a Paimon foreign table
INSERT INTO holo_table SELECT * FROM paimon_table;

Core GUC parameters

Parameter

Type

Default

Description

hg_experimental_enable_hybrid_dml

bool

on (Hologres V3.1 and later)

Master switch for Hybrid DML.

hg_experimental_enable_update_pk_use_hybrid_dml

bool

off

Whether UPDATE statements that modify a primary key column use Hybrid DML. Off by default; the statement falls back to the legacy path.

hg_experimental_enable_runtime_filter_for_hybrid_dml

bool

on

Whether to use Runtime Filter (Bloom Filter) to accelerate Hash Join.

hg_experimental_hybrid_dml_join_mode

enum

auto

Override the join strategy. Adjust only when necessary.

Values supported by hg_experimental_hybrid_dml_join_mode:

Value

Behavior

When to use

auto

Adaptive selection (recommended).

Almost all workloads.

force_spill

Forces Sort-Merge Join with spill-to-disk.

Extremely tight memory or debugging.

auto_hash_join

Forces Hash Join; build side is selected automatically.

You have confirmed the data volume will not cause OOM.

probe_source_hash_join

Forces the source data to be the probe side; the target table builds the hash table.

The target table is relatively small.

probe_target_hash_join

Forces the target table to be the probe side; the source data builds the hash table.

The source data is relatively small.

Note

Best practice: keep auto mode so the engine adapts on its own.

Version behavior

Defaults by version

Version

Default behavior

Description

Hologres V3.0 and earlier

Hybrid DML is not supported.

Only the legacy DML engine is available.

Hologres V3.1 and later

Hybrid DML is enabled by default.

No manual configuration required; all DML statements take the Hybrid path.

Feature support matrix

Feature

Hologres V3.0 and earlier

Hologres V3.1 and later

Plain INSERT

Not supported

Enabled by default

INSERT ON CONFLICT DO UPDATE

Not supported

Enabled by default

INSERT ON CONFLICT DO NOTHING

Not supported

Enabled by default

DELETE

Not supported

Enabled by default

UPDATE (non-primary-key columns)

Not supported

Enabled by default

UPDATE (primary key columns)

Not supported

Requires hg_experimental_enable_update_pk_use_hybrid_dml

Blind Merge optimization

Not supported

Triggered automatically for all-column UPDATE

Dynamic Table incremental refresh

Legacy path

Uses Hybrid DML by default

Runtime Filter acceleration

Not supported

Enabled by default

Sort-Merge Join fallback

Not supported

Triggered automatically for large-table loads

Verify whether Hybrid DML is in use

Use EXPLAIN to inspect the execution plan:

EXPLAIN INSERT INTO holo_table SELECT * FROM source_table;
  • Hybrid DML plan: contains a DataSetHybridDMLNode node.

  • Legacy DML plan: contains DataSetInsertNode, DataSetDeleteNode, DataSetUpdateNode, or DataSetMergeNode.

For a more detailed plan in Protobuf format:

EXPLAIN (FORMAT PB) INSERT INTO holo_table SELECT * FROM source_table;

How it works (for DBAs)

Adaptive join decision flow

The adaptive decision engine in Hybrid DML makes its choice in real time as data is written. The flow is as follows:

hybrid_dml_adaptive_join_flow_en

Key decision points:

  1. Source data smaller than target: buffer the source in a Buffer Table. After end-of-stream (EOS), build the hash table from the source and probe the target -- RIGHT OUTER JOIN.

  2. Target table smaller than source: build the hash table by scanning the target, then probe with the source -- LEFT OUTER JOIN.

  3. Memory insufficient: fall back to Sort-Merge Join. Each side is sorted independently, then merged. The operator spills to disk, so it never OOMs.

Runtime Filter acceleration

When Hash Join is selected and the source data is the build side, Hybrid DML generates Runtime Filters automatically:

  • Rowgroup Filter: converts the source primary key values into an IN-list filter and pushes it down to the target table's storage layer, skipping irrelevant row groups.

  • Bloom Filter: builds a Bloom Filter on the primary key column to prune non-matching rows early when scanning the target table.

Default trigger thresholds:

  • Target table contains at least 10,000 rows.

  • Source row count is less than 0.3 times the target row count.

Blind Merge optimization

An INSERT ON CONFLICT DO UPDATE statement triggers Blind Merge and skips the join with the target table entirely when all of the following conditions are met:

  1. The UPDATE SET clause covers every non-primary-key column.

  2. Primary key columns appear in the SET clause only as identity expressions (for example, pk = EXCLUDED.pk).

  3. No subqueries or other complex expressions are used.

The reasoning behind Blind Merge: when every column will be overwritten anyway, the engine can skip reading the existing values from the target table and write the new row directly.

Limits and constraints

Functional limits

Limit

Description

Offline writes only

Fixed Plan (online point query and point write) is not supported.

UPDATE on primary key columns

Does not use Hybrid DML by default. Enable hg_experimental_enable_update_pk_use_hybrid_dml to opt in.

ON CONFLICT with subqueries

If the ON CONFLICT DO UPDATE SET clause contains a subquery or PQE expression, the statement falls back to the legacy DML path automatically.

INSERT OVERWRITE

Source-side deduplication supports only Throw (for tables with a primary key) and None (for tables without a primary key). KeepLast is not supported.

Performance expectations

Scenario

Expected performance

Small data volume (fits in memory)

On par with the legacy DML Hash Join path.

Large data volume (triggers Sort-Merge Join)

Throughput is roughly one-third that of Hash Join, but the query is guaranteed not to OOM.

Blind Merge scenarios

Faster than legacy DML (the join is skipped).

Compatibility

  • No impact on other features: Hybrid DML and the legacy DML engine are fully isolated. Turning off the GUC parameter reverts to legacy behavior.

  • No breaking changes: SQL syntax is unchanged and the feature is transparent to applications.

  • Forward compatible: workloads that ran on earlier versions continue to behave the same way.

Monitoring and troubleshooting

Reading the execution plan

EXPLAIN INSERT INTO target_table
SELECT * FROM source_table
ON CONFLICT (pk) DO UPDATE SET col1 = EXCLUDED.col1;

Hybrid DML plan (example):

Insert on target_table
  ->  DataSetHybridDMLNode       -- Hybrid DML operator
        Join Strategy: Auto       -- Adaptive join
        Dedup Action: Throw       -- Source-side dedup policy
        Memory Quota: 2048 MB     -- Memory quota
        Runtime Filter: Enabled   -- Runtime Filter on
        ->  Seq Scan on source_table

Legacy DML plan (for comparison):

Insert on target_table
  ->  DataSetInsertNode          -- Legacy Insert operator
        ->  Hash Left Join       -- Fixed join strategy
              ->  Seq Scan on source_table
              ->  Seq Scan on target_table

Key differences:

  • Hybrid DML produces a single-layer operator with the join strategy embedded inside.

  • Legacy DML uses a standalone Join operator whose strategy is locked in by the optimizer.

Inspect the actual join strategy

Use EXPLAIN (FORMAT PB) to view the detailed Protobuf plan, which includes:

  • The join strategy actually selected (join_strategy field).

  • The source-side deduplication action (source_deduplicate.action field).

  • Runtime Filter settings (runtime_filter_options field).

  • Memory quota (memory_quota field).

Best practices

Day-to-day usage

  1. Keep the defaults: Hologres V3.1 and later enable Hybrid DML by default. Keep join_mode set to auto; no tuning is required for the vast majority of workloads.

  2. Large-table loads need no extra work: you no longer have to estimate data volumes to pick a join strategy.

  3. Dynamic Table workloads: incremental refresh uses Hybrid DML by default; no additional configuration required.

Performance tuning

Scenario

Recommendation

Large-table load is slow despite sufficient memory

Increase hg_experimental_hybrid_dml_memory_quota_mb (for example, to 4096 or 8192) so that more data can stay on the Hash Join path.

Source data is known to contain no duplicates

Set hg_disable_dml_source_deduplication = on to skip the dedup check.

All-column update

Make sure the UPDATE SET clause covers every non-primary-key column so that Blind Merge is triggered.

Fallback procedure

If you run into a Hybrid DML issue, you can revert at any time:

-- Session-level fallback
SET hg_experimental_enable_hybrid_dml = off;

-- Database-level fallback (requires superuser privileges; takes effect for new connections)
ALTER DATABASE dbname SET hg_experimental_enable_hybrid_dml = off;

After the fallback, all DML statements run on the legacy DML engine. No SQL changes are required.

Appendix: Full GUC reference

Parameter

Type

Default

Scope

Description

hg_experimental_enable_hybrid_dml

bool

on

session / database

Master switch for Hybrid DML.

hg_experimental_hybrid_dml_join_mode

enum

auto

session

Join strategy override.

hg_experimental_enable_update_pk_use_hybrid_dml

bool

off

session

Whether UPDATE on a primary key column uses Hybrid DML.

hg_experimental_enable_runtime_filter_for_hybrid_dml

bool

on

session

Whether to enable Runtime Filter.

hg_experimental_extract_hybrid_dml_filter

bool

on

session

Whether the optimizer extracts Hybrid DML filter conditions.

hg_experimental_hybrid_dml_game_machine_cpu_time_weight

int

70

0-100

CPU time weight in the adaptive cost model.

hg_disable_dml_source_deduplication

bool

off

session

Disable source-side deduplication.

hg_experimental_disable_insert_update_blind_merge

bool

off

session

Blind Merge toggle for ordinary tables.

hg_incremental_dynamic_table_use_hybrid_dml

bool

on

session

Use Hybrid DML for Dynamic Table incremental refresh.