1#include "duckdb/catalog/catalog_entry/duck_table_entry.hpp"
2#include "duckdb/execution/operator/persistent/physical_delete.hpp"
3#include "duckdb/execution/physical_plan_generator.hpp"
4#include "duckdb/planner/expression/bound_reference_expression.hpp"
5#include "duckdb/planner/operator/logical_delete.hpp"
6#include "duckdb/catalog/duck_catalog.hpp"
7
8namespace duckdb {
9
10unique_ptr<PhysicalOperator> DuckCatalog::PlanDelete(ClientContext &context, LogicalDelete &op,
11 unique_ptr<PhysicalOperator> plan) {
12 // get the index of the row_id column
13 auto &bound_ref = op.expressions[0]->Cast<BoundReferenceExpression>();
14
15 auto del = make_uniq<PhysicalDelete>(args&: op.types, args&: op.table, args&: op.table.GetStorage(), args&: bound_ref.index,
16 args&: op.estimated_cardinality, args&: op.return_chunk);
17 del->children.push_back(x: std::move(plan));
18 return std::move(del);
19}
20
21unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalDelete &op) {
22 D_ASSERT(op.children.size() == 1);
23 D_ASSERT(op.expressions.size() == 1);
24 D_ASSERT(op.expressions[0]->type == ExpressionType::BOUND_REF);
25
26 auto plan = CreatePlan(op&: *op.children[0]);
27
28 dependencies.AddDependency(entry&: op.table);
29 return op.table.catalog.PlanDelete(context, op, plan: std::move(plan));
30}
31
32} // namespace duckdb
33