Быстрое удаление из базы данных Postgres - PullRequest
1 голос
/ 11 апреля 2019

В настоящее время у меня есть база данных (postgres 10.7), которая содержит 180 таблиц. Каждая таблица напрямую или косвенно связана с основной таблицей projects через внешние ключи (с ON UPDATE CASCADE, ON DELETE CASCADE). При удалении записи из таблицы project это иногда может занять несколько минут, а иногда даже часов, в зависимости от того, сколько данных связано с этим проектом.

Мне интересно, какой самый лучший и быстрый способ - удалить из таблицы projects.

В настоящее время я просто удаляю следующее:

SET CONSTRAINTS ALL DEFERRED;
DELETE FROM projects WHERE id=project_id;

Я пробовал с и без порции SET CONSTRAINTS & ndash; это не произвело никакого эффекта. К сожалению для нас, TRUNCATE CASCADE не будет работать, так как мы хотим удалить только один проект, а иногда и несколько, но никогда не все из них. У нас также есть индексы для внешних ключей, чтобы попытаться помочь ему.

Вывод команды EXPLAIN (полноразмерный проект):

"Delete on projects  (cost=0.00..1.01 rows=1 width=6) (actual time=0.777..0.777 rows=0 loops=1)"
"  Buffers: shared hit=2 read=1 dirtied=1"
"  ->  Seq Scan on projects  (cost=0.00..1.01 rows=1 width=6) (actual time=0.040..0.040 rows=1 loops=1)"
"        Buffers: shared read=1"
"Planning time: 7.545 ms"
"Trigger for constraint activity_filter_scenarios_project_fkey on projects: time=8.286 calls=1"
"Trigger for constraint added_dependency_scenarios_project_fkey on projects: time=2.769 calls=1"
"Trigger for constraint cap_flexing_sets_project_fkey on projects: time=3.028 calls=1"
"Trigger for constraint dependency_layer_scenarios_project_id_fkey on projects: time=3.391 calls=1"
"Trigger for constraint distributions_project_fkey on projects: time=1.519 calls=1"
"Trigger for constraint execution_queue_projectid_fkey on projects: time=6.041 calls=1"
"Trigger for constraint exf_imports_project_fkey on projects: time=29.521 calls=1"
"Trigger for constraint field_definitions_project_fkey on projects: time=4.295 calls=1"
"Trigger for constraint financial_scenarios_project_fkey on projects: time=4.157 calls=1"
"Trigger for constraint geos_full_solutions_project_fkey on projects: time=2.131 calls=1"
"Trigger for constraint geos_stope_scenarios_project_fkey on projects: time=1.218 calls=1"
"Trigger for constraint geosequencing_scenarios_project_fkey on projects: time=2.556 calls=1"
"Trigger for constraint geosequencing_stability_settings_project_fkey on projects: time=1.191 calls=1"
"Trigger for constraint gosp_scenarios_project_fkey on projects: time=0.992 calls=1"
"Trigger for constraint graph_requests_template_project_fkey on projects: time=2.211 calls=1"
"Trigger for constraint guidance_formula_sets_project_fkey on projects: time=5.801 calls=1"
"Trigger for constraint horizon_scenarios_project_fkey on projects: time=2.336 calls=1"
"Trigger for constraint max_lag_settings_project_id_fkey on projects: time=4.591 calls=1"
"Trigger for constraint mine_scenarios_project_fkey on projects: time=4.309 calls=1"
"Trigger for constraint project_history_project_fkey on projects: time=4.586 calls=1"
"Trigger for constraint run_configurations_project_fkey on projects: time=3.074 calls=1"
"Trigger for constraint run_settings_project_fkey on projects: time=2.468 calls=1"
"Trigger for constraint schedule_reevaluation_requests_project_fkey on projects: time=0.442 calls=1"
"Trigger for constraint seeds_project_fkey on projects: time=20.746 calls=1"
"Trigger for constraint stockpiles_project_fkey on projects: time=0.416 calls=1"
"Trigger for constraint tasks_project_fkey on projects: time=197.922 calls=1"
"Trigger for constraint ventilation_advanced_requirements_project_fkey on projects: time=0.336 calls=1"
"Trigger for constraint ventilation_advanced_scenarios_project_fkey on projects: time=0.255 calls=1"
"Trigger for constraint ventilation_requirement_configurations_project_fkey on projects: time=0.284 calls=1"
"Trigger for constraint ventilation_scenarios_project_fkey on projects: time=1.945 calls=1"
"Trigger for constraint activity_filter_operations_activity_filter_scenario_fkey on activity_filter_scenarios: time=75.510 calls=3"
"Trigger for constraint cap_analysis_requests_activity_filter_scenario_fkey on activity_filter_scenarios: time=6.031 calls=3"
"Trigger for constraint mine_scenarios_activity_filter_scenario_fkey on activity_filter_scenarios: time=0.200 calls=3"
"Trigger for constraint execution_queue_run_seed_fkey on execution_queue: time=0.818 calls=13"
"Trigger for constraint residual_requests_execution_id_fkey on execution_queue: time=2.147 calls=13"
"Trigger for constraint rm_o_attain_config_runid_fkey on execution_queue: time=1.494 calls=13"
"Trigger for constraint rm_o_attain_target_dates_runid_fkey on execution_queue: time=4.166 calls=13"
"Trigger for constraint rm_o_complete_runid_fkey on execution_queue: time=4.813 calls=13"
"Trigger for constraint rm_o_config_runid_fkey on execution_queue: time=12738.872 calls=13"
"Trigger for constraint rm_o_dependencymap_runid_fkey on execution_queue: time=980.347 calls=13"
"Trigger for constraint rm_o_generation_stats_runid_fkey on execution_queue: time=11.286 calls=13"
"Trigger for constraint rm_o_horizon_realization_scenarios_run_id_fkey on execution_queue: time=3.534 calls=13"
"Trigger for constraint rm_o_reset_stats_runid_fkey on execution_queue: time=6.277 calls=13"
"Trigger for constraint rm_o_run_config_runid_fkey on execution_queue: time=2.846 calls=13"
"Trigger for constraint rm_o_run_stats_runid_fkey on execution_queue: time=3.249 calls=13"
"Trigger for constraint rm_o_schedule_stats_runid_fkey on execution_queue: time=1.299 calls=13"
"Trigger for constraint rm_o_top_resets_runid_fkey on execution_queue: time=2.010 calls=13"
"Trigger for constraint rm_o_top_schedules_runid_fkey on execution_queue: time=4.507 calls=13"
"Trigger execution_queue_delete_trigger on execution_queue: time=26.856 calls=13"
"Trigger for constraint dependencies_exf_import_fkey on exf_imports: time=320.650 calls=1"
"Trigger for constraint imported_fields_exf_import_fkey on exf_imports: time=6.302 calls=1"
"Trigger for constraint production_rate_tables_exf_import_fkey on exf_imports: time=2.985 calls=1"
"Trigger for constraint resources_exf_import_fkey on exf_imports: time=8.282 calls=1"
"Trigger for constraint tasks_exf_import_fkey on exf_imports: time=7.571 calls=1"
"Trigger for constraint activity_filter_operations_length_field_fkey on field_definitions: time=0.607 calls=26"
"Trigger for constraint activity_filter_operations_weight_field_fkey on field_definitions: time=0.532 calls=26"
"Trigger for constraint attribute_capacity_scenarios_attribute_field_fkey on field_definitions: time=4.029 calls=26"
"Trigger for constraint blending_constraints_first_element_fkey on field_definitions: time=3.867 calls=26"
"Trigger for constraint blending_constraints_second_element_fkey on field_definitions: time=0.505 calls=26"
"Trigger for constraint cap_analysis_request_field_definitions_field_def_fkey on field_definitions: time=2.177 calls=26"
"Trigger for constraint capacity_condition_scenario_groups_text_field_definition_fkey on field_definitions: time=3.894 calls=26"
"Trigger for constraint capacity_definitions_field_definition_fkey on field_definitions: time=9.777 calls=26"
"Trigger for constraint contaminants_contaminant_field_fkey on field_definitions: time=4.365 calls=26"
"Trigger for constraint equipment_equipment_field_fkey on field_definitions: time=8.113 calls=26"
"Trigger for constraint equipment_movement_costs_movement_field_fkey on field_definitions: time=2.051 calls=26"
"Trigger for constraint financial_scenarios_precalculated_revenue_fkey on field_definitions: time=0.611 calls=26"
"Trigger for constraint other_properties_property_field_fkey on field_definitions: time=10.417 calls=26"
"Trigger for constraint plants_plant_field_fkey on field_definitions: time=11.845 calls=26"
"Trigger for constraint point_capital_profiles_field_definition_fkey on field_definitions: time=4.204 calls=26"
"Trigger for constraint price_profiles_field_definition_fkey on field_definitions: time=7.214 calls=26"
"Trigger for constraint products_grade_field_fkey on field_definitions: time=59.582 calls=26"
"Trigger for constraint sustaining_capital_profiles_field_definition_fkey on field_definitions: time=2.062 calls=26"
"Trigger for constraint financial_scenario_expenditure_triggers_financial_scenario_fkey on financial_scenarios: time=2.437 calls=1"
"Trigger for constraint mine_scenarios_financial_scenario_fkey on financial_scenarios: time=0.138 calls=1"
"Trigger for constraint guidance_formula_set_entries_guidance_formula_set_fkey on guidance_formula_sets: time=9.255 calls=6"
"Trigger for constraint run_configurations_guidance_formula_set_fkey on guidance_formula_sets: time=0.365 calls=6"
"Trigger for constraint cap_analysis_requests_max_lag_fkey on max_lag_settings: time=0.132 calls=1"
"Trigger for constraint max_lag_setting_entries_setting_id_fkey on max_lag_settings: time=21.339 calls=1"
"Trigger for constraint run_settings_max_lag_settings_fkey on max_lag_settings: time=0.391 calls=1"
"Trigger for constraint mine_scenario_attribute_capacities_mine_scenario_fkey on mine_scenarios: time=3.052 calls=2"
"Trigger for constraint mine_scenario_capacity_definitions_mine_scenario_fkey on mine_scenarios: time=12.044 calls=2"
"Trigger for constraint mine_scenario_contaminants_mine_scenario_fkey on mine_scenarios: time=4.243 calls=2"
"Trigger for constraint mine_scenario_equipment_mine_scenario_fkey on mine_scenarios: time=9.233 calls=2"
"Trigger for constraint mine_scenario_other_properties_mine_scenario_fkey on mine_scenarios: time=5.192 calls=2"
"Trigger for constraint mine_scenario_plants_mine_scenario_fkey on mine_scenarios: time=39.163 calls=2"
"Trigger for constraint mine_scenario_products_mine_scenario_fkey on mine_scenarios: time=11.046 calls=2"
"Trigger for constraint run_configurations_mine_scenario_fkey on mine_scenarios: time=0.309 calls=2"
"Trigger for constraint geosequencing_scenario_run_configuration_run_configuration_fkey on run_configurations: time=0.873 calls=11"
"Trigger for constraint gosp_run_configurations_run_configuration_fkey on run_configurations: time=0.705 calls=11"
"Trigger for constraint horizon_run_configurations_run_configuration_fkey on run_configurations: time=0.715 calls=11"
"Trigger for constraint ventilation_run_configurations_run_configuration_fkey on run_configurations: time=0.942 calls=11"
"Trigger for constraint attain_run_settings_run_settings_fkey on run_settings: time=15.667 calls=9"
"Trigger for constraint run_configurations_run_settings_fkey on run_settings: time=0.674 calls=9"
"Trigger for constraint run_configurations_seed_fkey on seeds: time=0.275 calls=2"
"Trigger for constraint capacity_triggers_task_fkey on tasks: time=258.381 calls=35236"
"Trigger for constraint dependencies_from_task_fkey on tasks: time=212.529 calls=35236"
"Trigger for constraint dependencies_to_task_fkey on tasks: time=197.221 calls=35236"
"Trigger for constraint financial_scenario_expenditure_triggers_task_fkey on tasks: time=257.965 calls=35236"
"Trigger for constraint geosequencing_dependencies_from_task_fkey on tasks: time=260.043 calls=35236"
"Trigger for constraint geosequencing_dependencies_to_task_fkey on tasks: time=244.659 calls=35236"
"Trigger for constraint geosequencing_scenario_subtask_dependencies_from_task_fkey on tasks: time=254.873 calls=35236"
"Trigger for constraint geosequencing_scenario_subtask_dependencies_to_task_fkey on tasks: time=246.340 calls=35236"
"Trigger for constraint max_lag_setting_entries_from_task_fkey on tasks: time=188.897 calls=35236"
"Trigger for constraint max_lag_setting_entries_to_task_fkey on tasks: time=173.290 calls=35236"
"Trigger for constraint plant_recovery_factor_profiles_task_fkey on tasks: time=292.398 calls=35236"
"Trigger for constraint production_field_values_task_fkey on tasks: time=390.591 calls=35236"
"Trigger for constraint task_distributions_task_fkey on tasks: time=358.768 calls=35236"
"Trigger for constraint task_resource_associations_task_fkey on tasks: time=174.215 calls=35236"
"Trigger for constraint text_field_values_task_fkey on tasks: time=471.291 calls=35236"
"Trigger for constraint ventilation_advanced_scenario_activities_activity_fkey on tasks: time=327.614 calls=35236"
"Trigger for constraint ventilation_regulators_task_fkey on tasks: time=257.876 calls=35236"
"Trigger for constraint ventilation_scenario_districts_task_fkey on tasks: time=252.948 calls=35236"
"Trigger for constraint activity_filter_operation_equip_activity_filter_operation_fkey1 on activity_filter_operations: time=5.147 calls=52"
"Trigger for constraint activity_filter_operation_equipm_activity_filter_operation_fkey on activity_filter_operations: time=4.241 calls=52"
"Trigger for constraint activity_filter_operation_field_lookups_filter_operation_fkey on activity_filter_operations: time=4.153 calls=52"
"Trigger for constraint activity_filter_operation_proper_activity_filter_operation_fkey on activity_filter_operations: time=7.740 calls=52"
"Trigger for constraint attain_activity_filter_operations_filter_operation_fkey on activity_filter_operations: time=14.577 calls=52"
"Trigger for constraint rm_o_gosp_realization_scenarios_reset_id_fkey on rm_o_reset_stats: time=2.566 calls=19"
"Trigger for constraint rm_o_top_resets_reset_id_fkey on rm_o_reset_stats: time=0.475 calls=19"
"Trigger rm_o_reset_stats_trigger on rm_o_reset_stats: time=1.611 calls=19"
"Trigger rm_o_run_stats_trigger on rm_o_run_stats: time=1.936 calls=13"
"Trigger for constraint graph_requests_solution_fkey on rm_o_schedule_stats: time=7.944 calls=70"
"Trigger for constraint horizon_scenario_schedules_schedule_fkey on rm_o_schedule_stats: time=2.137 calls=70"
"Trigger for constraint residual_request_results_schedule_id_fkey on rm_o_schedule_stats: time=2.776 calls=70"
"Trigger for constraint rm_o_airway_airflowdpm_solution_id_fkey on rm_o_schedule_stats: time=3.301 calls=70"
"Trigger for constraint rm_o_gosp_schedule_stats_stats_id_fkey on rm_o_schedule_stats: time=2.227 calls=70"
"Trigger for constraint rm_o_regulator_settings_solution_id_fkey on rm_o_schedule_stats: time=2.724 calls=70"
"Trigger for constraint rm_o_resource_usage_instance_splits_solution_fkey on rm_o_schedule_stats: time=15620.727 calls=70"
"Trigger for constraint rm_o_resource_usage_schedule_id_fkey on rm_o_schedule_stats: time=67.761 calls=70"
"Trigger for constraint rm_o_top_schedules_schedule_id_fkey on rm_o_schedule_stats: time=1.412 calls=70"
"Trigger for constraint schedule_geo_stability_evaluations_schedule_id_fkey on rm_o_schedule_stats: time=1.232 calls=70"
"Trigger for constraint schedule_reevaluation_request_schedules_solution_fkey on rm_o_schedule_stats: time=1.189 calls=70"
"Trigger for constraint schedule_reevaluation_result_scores_solution_fkey on rm_o_schedule_stats: time=1.165 calls=70"
"Trigger for constraint scheduledactivities_solution_id_fkey on rm_o_schedule_stats: time=17489.740 calls=70"
"Trigger for constraint activity_filter_operation_field_lookups_field_fkey on imported_fields: time=0.549 calls=20"
"Trigger for constraint added_dependencies_criterion_fkey on imported_fields: time=3.868 calls=20"
"Trigger for constraint added_dependencies_domain_fkey on imported_fields: time=0.342 calls=20"
"Trigger for constraint attain_run_settings_start_date_field_fkey on imported_fields: time=0.377 calls=20"
"Trigger for constraint field_definitions_imported_field_fkey on imported_fields: time=0.411 calls=20"
"Trigger for constraint geosequencing_scenario_subtask_configu_subtask_group_field_fkey on imported_fields: time=3.296 calls=20"
"Trigger for constraint geosequencing_scenario_subtask_configur_subtask_type_field_fkey on imported_fields: time=0.371 calls=20"
"Trigger for constraint geosequencing_scenario_subtask_filter_operati_filter_field_fkey on imported_fields: time=2.967 calls=20"
"Trigger for constraint geosequencing_stability_settings_text_field_definition_fkey on imported_fields: time=0.468 calls=20"
"Trigger for constraint grade_distributions_confidence_field_fkey on imported_fields: time=2.396 calls=20"
"Trigger for constraint guidance_formula_set_entries_mine_area_field_fkey on imported_fields: time=0.400 calls=20"
"Trigger for constraint guidance_formula_set_entries_rank_field_fkey on imported_fields: time=0.328 calls=20"
"Trigger for constraint max_lag_settings_text_field_id_fkey on imported_fields: time=0.356 calls=20"
"Trigger for constraint production_field_values_imported_field_fkey on imported_fields: time=12.350 calls=20"
"Trigger for constraint rm_o_attain_config_datefield_fkey on imported_fields: time=0.539 calls=20"
"Trigger for constraint run_settings_pin_marker_field_fkey on imported_fields: time=0.415 calls=20"
"Trigger for constraint saved_grade_realization_sets_product_field_fkey on imported_fields: time=0.745 calls=20"
"Trigger for constraint saved_realization_sets_product_field_fkey on imported_fields: time=0.603 calls=20"
"Trigger for constraint text_field_values_imported_field_fkey on imported_fields: time=22.514 calls=20"
"Trigger for constraint ventilation_advanced_scenarios_text_field_id_fkey on imported_fields: time=0.461 calls=20"
"Trigger for constraint equipment_resource_fkey on resources: time=0.504 calls=27"
"Trigger for constraint plants_resource_fkey on resources: time=0.404 calls=27"
"Trigger for constraint resource_availability_resource_fkey on resources: time=3.674 calls=27"
"Trigger for constraint resource_travel_data_resource_fkey on resources: time=3.485 calls=27"
"Trigger for constraint task_resource_associations_resource_fkey on resources: time=0.394 calls=27"
"Trigger for constraint mine_scenario_products_price_profile_fkey on price_profiles: time=0.113 calls=1"
"Trigger for constraint gosp_scenario_variables_product_fkey on products: time=1.283 calls=1"
"Trigger for constraint guidance_formula_set_entries_driving_product_fkey on products: time=0.074 calls=1"
"Trigger for constraint horizon_scenario_variables_product_fkey on products: time=1.319 calls=1"
"Trigger for constraint mine_scenario_products_product_fkey on products: time=0.071 calls=1"
"Trigger for constraint plant_blending_product_fkey on products: time=1.267 calls=1"
"Trigger for constraint plant_recovery_factor_profiles_product_fkey on products: time=0.093 calls=1"
"Trigger for constraint attribute_capacity_definitions_capacity_definition_fkey on capacity_definitions: time=1.561 calls=29"
"Trigger for constraint capacity_condition_scenarios_capacity_definition_fkey on capacity_definitions: time=5.234 calls=29"
"Trigger for constraint capacity_entries_capacity_definition_fkey on capacity_definitions: time=4.683 calls=29"
"Trigger for constraint capacity_flexing_capacity_definition_fkey on capacity_definitions: time=2.011 calls=29"
"Trigger for constraint capacity_triggers_capacity_definition_fkey on capacity_definitions: time=0.487 calls=29"
"Trigger for constraint mine_scenario_capacity_definitions_capacity_definition_fkey on capacity_definitions: time=0.398 calls=29"
"Trigger for constraint activity_filter_operation_equipment_groups_equipment_fkey on equipment: time=0.339 calls=15"
"Trigger for constraint equipment_maintenance_schedules_equipment_fkey on equipment: time=3.512 calls=15"
"Trigger for constraint equipment_movement_costs_equipment_fkey on equipment: time=0.328 calls=15"
"Trigger for constraint mine_scenario_equipment_equipment_fkey on equipment: time=0.311 calls=15"
"Trigger for constraint ventilation_advanced_requirements_entries_equipment_id_fkey on equipment: time=0.764 calls=15"
"Trigger for constraint ventilation_requirement_configuration_entries_equipment_fkey on equipment: time=0.533 calls=15"
"Trigger for constraint mine_scenario_equipment_sustaining_capital_profile_fkey on sustaining_capital_profiles: time=0.082 calls=1"
"Trigger for constraint mine_scenario_plants_sustaining_capital_profile_fkey on sustaining_capital_profiles: time=0.091 calls=1"
"Trigger for constraint sustaining_capital_profile_entr_sustaining_capital_profile_fkey on sustaining_capital_profiles: time=2.879 calls=1"
"Trigger for constraint activity_filter_operations_associated_plant_fkey on plants: time=0.195 calls=1"
"Trigger for constraint blending_configurations_plant_fkey on plants: time=3.046 calls=1"
"Trigger for constraint mine_scenario_plants_plant_fkey on plants: time=0.097 calls=1"
"Trigger for constraint plant_blending_plant_fkey on plants: time=0.063 calls=1"
"Trigger for constraint plant_recovery_factor_profiles_plant_fkey on plants: time=0.064 calls=1"
"Trigger for constraint plant_stockpiles_plant_fkey on plants: time=2.354 calls=1"
"Trigger for constraint activity_filter_operation_property_costs_property_fkey on other_properties: time=0.103 calls=1"
"Trigger for constraint mine_scenario_other_properties_other_property_fkey on other_properties: time=0.095 calls=1"
"Trigger for constraint mine_scenario_plant_recovery_factor_pr_mine_scenario_plant_fkey on mine_scenario_plants: time=4.542 calls=2"
"Trigger for constraint activity_filter_operation_equipment_groups_set_fkey on activity_filter_operation_equipment_sets: time=0.611 calls=47"
"Trigger for constraint rm_o_resource_instance_usage_usage_id_fkey on rm_o_resource_usage: time=120582.094 calls=770"
"Trigger for constraint rm_o_resource_usage_instance_splits_usage_id_fkey on rm_o_resource_usage: time=766.449 calls=770"
"Trigger for constraint scheduledactivitysplits_scheduled_id_fkey on scheduledactivities: time=20247.656 calls=2466520"
"Trigger for constraint gosp_graph_requests_request_id_fkey on graph_requests: time=3.064 calls=8"
"Trigger for constraint graph_result_activities_graph_request_fkey on graph_requests: time=2685.696 calls=8"
"Trigger for constraint graph_results_graph_request_fkey on graph_requests: time=14.874 calls=8"
"Trigger for constraint schedule_reevaluation_report_requests_request_id_fkey on graph_requests: time=5.249 calls=8"
"Trigger graph_requests_remove_trigger on graph_requests: time=1.159 calls=8"
"Trigger for constraint mine_scenario_plant_recovery_facto_recovery_factor_profile_fkey on plant_recovery_factor_profiles: time=0.223 calls=2"
"Trigger for constraint equipment_capacity_entry_quantities_capacity_entry_fkey on capacity_entries: time=8.177 calls=34"
"Trigger for constraint capacity_condition_scenario_groups_condition_scenario_fkey on capacity_condition_scenarios: time=0.132 calls=1"
"Trigger for constraint mine_scenario_capacity_definitions_condition_scenario_fkey on capacity_condition_scenarios: time=0.076 calls=1"
"Trigger for constraint graph_result_values_results_id_fkey on graph_results: time=425.842 calls=544"
"Execution time: 197948.209 ms"

1 Ответ

2 голосов
/ 11 апреля 2019

Это довольно много триггеров!

Некоторые записи выглядят так, как будто вы не проиндексировали все внешние ключи.Вот несколько примеров:

Trigger for constraint rm_o_resource_instance_usage_usage_id_fkey on rm_o_resource_usage: time=10825.136 calls=76
Trigger for constraint graph_result_activities_graph_request_fkey on graph_requests: time=120.998 calls=10
Trigger for constraint rm_o_resource_usage_instance_splits_usage_id_fkey on rm_o_resource_usage: time=2659.464 calls=76
Trigger for constraint rm_o_resource_usage_instance_splits_solution_fkey on rm_o_schedule_stats: time=1698.600 calls=14

Но львиная доля времени тратится на эти два триггера на tasks:

Trigger for constraint max_lag_setting_entries_from_task_fkey on tasks: time=88356.439 calls=99876
Trigger for constraint max_lag_setting_entries_to_task_fkey on tasks: time=91443.464 calls=99876

Они также не индексируются,Как еще может быть, что они занимают намного больше времени, чем все другие триггеры на tasks?

...