|
18 | 18 | #include "duckdb/planner/expression/bound_columnref_expression.hpp" |
19 | 19 | #include "duckdb/planner/operator/logical_delete.hpp" |
20 | 20 | #include "duckdb/planner/operator/logical_insert.hpp" |
| 21 | +#include "duckdb/planner/operator/logical_merge_into.hpp" |
21 | 22 | #include "duckdb/planner/operator/logical_projection.hpp" |
22 | 23 | #include "duckdb/planner/operator/logical_simple.hpp" |
23 | 24 | #include "duckdb/planner/operator/logical_update.hpp" |
@@ -297,13 +298,15 @@ void RefreshInsertRule::RefreshInsertRuleFunction(OptimizerExtensionInput &input |
297 | 298 | return; |
298 | 299 | } |
299 | 300 |
|
300 | | - auto dml = root; |
| 301 | + auto dml_owner = &plan; |
| 302 | + auto dml = dml_owner->get(); |
301 | 303 | while (dml->type != LogicalOperatorType::LOGICAL_INSERT && dml->type != LogicalOperatorType::LOGICAL_DELETE && |
302 | | - dml->type != LogicalOperatorType::LOGICAL_UPDATE) { |
| 304 | + dml->type != LogicalOperatorType::LOGICAL_UPDATE && dml->type != LogicalOperatorType::LOGICAL_MERGE_INTO) { |
303 | 305 | if (dml->children.size() != 1) { |
304 | 306 | return; |
305 | 307 | } |
306 | | - dml = dml->children[0].get(); |
| 308 | + dml_owner = &dml->children[0]; |
| 309 | + dml = dml_owner->get(); |
307 | 310 | } |
308 | 311 |
|
309 | 312 | switch (dml->type) { |
@@ -361,6 +364,19 @@ void RefreshInsertRule::RefreshInsertRuleFunction(OptimizerExtensionInput &input |
361 | 364 | OPENIVM_DEBUG_PRINT("[INSERT RULE] transactional UPDATE delta capture for '%s'\n", table_name.c_str()); |
362 | 365 | break; |
363 | 366 | } |
| 367 | + case LogicalOperatorType::LOGICAL_MERGE_INTO: { |
| 368 | + auto &merge = dml->Cast<LogicalMergeInto>(); |
| 369 | + const auto &table_name = merge.table.name; |
| 370 | + auto delta_table = TryGetTrackedDeltaTable(input.context, merge.table); |
| 371 | + if (!delta_table) { |
| 372 | + return; |
| 373 | + } |
| 374 | + auto capture = make_uniq<LogicalTransactionalMergeDeltaCapture>(merge.table, *delta_table); |
| 375 | + capture->children.push_back(std::move(*dml_owner)); |
| 376 | + *dml_owner = std::move(capture); |
| 377 | + OPENIVM_DEBUG_PRINT("[INSERT RULE] transactional MERGE action delta capture for '%s'\n", table_name.c_str()); |
| 378 | + break; |
| 379 | + } |
364 | 380 | default: |
365 | 381 | return; |
366 | 382 | } |
|
0 commit comments