diff --git a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql index 604f5e5d88cfb4e3cb5ba08aa17a1b40eddafd3e..cf13d616bfd0500aaf56364bc4cff81d8297d448 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql +++ b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql @@ -261,6 +261,7 @@ BEGIN VALUES (new_claim.resource_id, new_claim.status_id, new_claim.endtime, -new_claim.claim_size); -- with the two new delta entries, use the deltas table to rebuild the usages table from the claim's starttime onwards + --TODO: use an upper limit as well? When? PERFORM resource_allocation.rebuild_resource_usages_from_deltas_for_resource_of_status(new_claim.resource_id, new_claim.status_id, new_claim.starttime); SELECT * from clock_timestamp() into proc_end; @@ -431,11 +432,13 @@ DECLARE BEGIN SELECT * from clock_timestamp() into proc_start; + -- TODO: have a reference from delta table to claim_id? DELETE FROM resource_allocation.resource_usage_delta WHERE id = (SELECT id FROM resource_allocation.resource_usage_delta rud WHERE rud.resource_id = old_claim.resource_id AND rud.status_id = old_claim.status_id AND rud.moment = old_claim.starttime + AND rud.delta = old_claim.claim_size LIMIT 1); DELETE FROM resource_allocation.resource_usage_delta @@ -443,9 +446,11 @@ BEGIN WHERE rud.resource_id = old_claim.resource_id AND rud.status_id = old_claim.status_id AND rud.moment = old_claim.endtime + AND rud.delta = -old_claim.claim_size LIMIT 1); -- with the two removed delta entries, use the deltas table to rebuild the usages table from the claim's starttime onwards + --TODO: use an upper limit as well? When? PERFORM resource_allocation.rebuild_resource_usages_from_deltas_for_resource_of_status(old_claim.resource_id, old_claim.status_id, old_claim.starttime); SELECT * from clock_timestamp() into proc_end; @@ -548,6 +553,7 @@ DECLARE max_resource_usage_in_time_window resource_allocation.resource_usage; max_resource_at_or_before_starttime resource_allocation.resource_usage; BEGIN + --TODO: can this query be moved into if statement? SELECT * FROM resource_allocation.get_resource_usage_at_or_before(_resource_id, _claim_status_id, _lower, false, false, false) into max_resource_at_or_before_starttime; SELECT * FROM resource_allocation.resource_usage ru @@ -610,7 +616,7 @@ BEGIN --make a best guess by subtracting the current_claimed_usage from the total_capacity SELECT * from clock_timestamp() into proc_end; - RAISE NOTICE 'get_resource_claimable_capacity_between took %', proc_end - proc_start; + RAISE NOTICE 'get_resource_claimable_capacity_between_a took %', proc_end - proc_start; RETURN total_capacity - max_resource_usage_value; ELSE @@ -625,7 +631,7 @@ BEGIN SELECT usage FROM resource_allocation.get_current_resource_usage(_resource_id, claimed_status_id) INTO current_claimed_usage; SELECT * from clock_timestamp() into proc_end; - RAISE NOTICE 'get_resource_claimable_capacity_between took %', proc_end - proc_start; + RAISE NOTICE 'get_resource_claimable_capacity_between_b took %', proc_end - proc_start; IF current_claimed_usage IS NULL THEN RETURN available_capacity + current_claimed_usage - max_resource_usage_value; @@ -725,8 +731,11 @@ DECLARE claim_has_conflicts boolean; proc_start timestamp with time zone; proc_end timestamp with time zone; + part_start timestamp with time zone; + part_end timestamp with time zone; BEGIN SELECT * from clock_timestamp() into proc_start; + SELECT * from clock_timestamp() into part_start; --order of following steps is important, do not reorder the steps IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN @@ -767,6 +776,10 @@ BEGIN END IF; END IF; + SELECT * from clock_timestamp() into part_end; + RAISE NOTICE 'before_claim_insertupdatedelete1 took %', part_end - part_start; + SELECT * from clock_timestamp() into part_start; + IF TG_OP = 'UPDATE' OR TG_OP = 'DELETE' THEN --update the resource usages affected by this claim --do this before we check for conflicts, because this claim might be shifted for example @@ -774,6 +787,10 @@ BEGIN PERFORM resource_allocation.process_old_claim_outof_resource_usages(OLD); END IF; + SELECT * from clock_timestamp() into part_end; + RAISE NOTICE 'before_claim_insertupdatedelete2 took %', part_end - part_start; + SELECT * from clock_timestamp() into part_start; + --only check claim if status and/or claim_size and/or start/end time changed IF TG_OP = 'INSERT' OR (TG_OP = 'UPDATE' AND (OLD.status_id <> NEW.status_id OR OLD.claim_size <> NEW.claim_size OR @@ -800,12 +817,13 @@ BEGIN END IF; END IF; - IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN - --update the resource usages affected by this claim - PERFORM resource_allocation.process_new_claim_into_resource_usages(NEW); - END IF; + --update the resource usages affected by this claim + PERFORM resource_allocation.process_new_claim_into_resource_usages(NEW); END IF; + SELECT * from clock_timestamp() into part_end; + RAISE NOTICE 'before_claim_insertupdatedelete3 took %', part_end - part_start; + SELECT * from clock_timestamp() into proc_end; RAISE NOTICE 'before_claim_insertupdatedelete took %', proc_end - proc_start;