stac-utils / pgstac

Schema, functions and a python library for storing and accessing STAC collections and items in PostgreSQL
MIT License
153 stars 39 forks source link

Eliminate redundant partition stats update #283

Open drnextgis opened 4 months ago

drnextgis commented 4 months ago

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.

drnextgis commented 4 months ago

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?