From 300385ac8d9edaf2b4a472238caf19a8ab31516a Mon Sep 17 00:00:00 2001 From: Michael Mior Date: Fri, 11 Sep 2015 11:52:07 -0400 Subject: [PATCH] Add delete to manual execution plans --- lib/nose/plans/execution_plan.rb | 15 +++++++++++++++ plans/rubis_expert.rb | 1 + 2 files changed, 16 insertions(+) diff --git a/lib/nose/plans/execution_plan.rb b/lib/nose/plans/execution_plan.rb index eb89179f..4f47b722 100644 --- a/lib/nose/plans/execution_plan.rb +++ b/lib/nose/plans/execution_plan.rb @@ -241,6 +241,21 @@ def Insert(index_key, *fields) @update_steps << step end + # Add a new deletion step from an index + def Delete(index_key) + @index = @schema.indexes[index_key] + + step = Plans::DeletePlanStep.new @index + + # Get cardinality from last step of each support query plan + # as in UpdatePlanner#find_plans_for_update + cardinalities = @query_plans.map { |p| p.steps.last.state.cardinality } + cardinality = cardinalities.inject(1, &:*) + step.state = OpenStruct.new cardinality: cardinality + + @update_steps << step + end + # rubocop:enable MethodName end end diff --git a/plans/rubis_expert.rb b/plans/rubis_expert.rb index 54e66b5f..a303ee84 100644 --- a/plans/rubis_expert.rb +++ b/plans/rubis_expert.rb @@ -168,6 +168,7 @@ Param items.id, :== Param items.end_date, :== Insert 'items_with_category', items.id, categories.id, items.quantity + Delete 'items_by_category' Insert 'items_by_category', categories.id, items.end_date, items.id end