Eliminate redundant partition stats update
The update_partition_stats_q function is being invoked from load_partition in the pypgstac. However, this function is also being automatically triggered by changes to the items table:
postgis=> \dS items;
...
Triggers:
items_after_delete_trigger AFTER UPDATE ON items REFERENCING NEW TABLE AS newdata FOR EACH STATEMENT EXECUTE FUNCTION partition_after_triggerfunc()
items_after_insert_trigger AFTER INSERT ON items REFERENCING NEW TABLE AS newdata FOR EACH STATEMENT EXECUTE FUNCTION partition_after_triggerfunc()
items_after_update_trigger AFTER DELETE ON items REFERENCING OLD TABLE AS newdata FOR EACH STATEMENT EXECUTE FUNCTION partition_after_triggerfunc()
Reference to the trigger definitions.
Is this redundant? If so, we should consider removing the redundant call from load_partition.
There is a difference between these two invocations: in one case, the function is called with istrigger set to False, and in the other, it is set to True. This affects the execution of update_partition_stats because certain parts of the function are skipped when istrigger is True, while the rest of the function still runs. Therefore, the point that the same piece of code executes twice remains valid.
@bitner, could you please elaborate on why the "Modifying Constraints" part is skipped when update_partition_stats is called with istrigger set to True?