citusdata / citusdata/citus

Support triggers on reference tables with a coordinator replica

Open
#4,425 4 comments 7 reactions 0 assignees View on GitHub
enhancement sql
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

We support interactions such as joins and foreign keys between reference tables and local tables when the reference table has a replica on the coordinator. It may be reasonable to follow a similar model for triggers, such that the trigger is placed *only* on the local replica of the reference table and can interact directly with other local tables, as well as distributed tables.

That that means the trigger is not invoked on any of the replicas of the reference table. The main downside is that the operations in the trigger are not pushed down and the individual statements in the trigger incur additional network round trips; a large update may take hours. We could perhaps come up with a more specialized trigger type with restricted functionality at a later time as a performance optimization, or batch operations together if immediate response is not needed.

A specific challenge lies in supporting BEFORE triggers that modify the tuple. After such a trigger, the value of the tuple could be different than what we have in the distributed plan. One way to handle that would be to not execute the statement on the replicas directly, but instead add an additional trigger on the local replica that does the actual operation and comes after all other triggers (PostgreSQL executes them in alphabetical order).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.