citusdata / citus

Distributed PostgreSQL as an extension
https://www.citusdata.com
GNU Affero General Public License v3.0
10.56k stars 668 forks source link

Create Trigger / Drop Trigger on distributed tables #906

Open ozgune opened 8 years ago

ozgune commented 8 years ago

We currently don't have native support built-in for distributed tables. Users who want to use triggers do so by manually creating them on a distributed table's shards on the worker nodes.

I'm opening this issue to track adding CREATE TRIGGER and DROP TRIGGER support on distributed tables. I'm also listing a few use-cases that relate to trigger support below.

  1. Propagate CREATE TRIGGER to all shards and shard placements: This could for example be useful in the context of full text search.
  2. Propagate CREATE TRIGGER to all shards but only one of the shard placements: #228 and the mailing list update there talks about an example usage.
  3. Propagate CREATE TRIGGER to pass along a notification: For example, an IoT database may need to alarm if the underlying sensor reports that the battery's charge rate < 5%.
  4. Ingest from source table to colocated destination table: In this example, the source table stores raw events, and the destination table has aggregated stats. The user creates a trigger to roll up raw events from the source table, and put them into the destination table.
marcocitus commented 3 years ago

Phase 1 for enabling triggers on distributed tables:

For reference tables, we will somehow need to distinguish between two types of triggers:

The two types are mutually exclusive and it's not clear which is preferable or how to let the user pick.

marcocitus commented 3 years ago

A common scenario for triggers it insert into an event log when the table is modified. In most case the even log will not be co-located with the source table. It will in many cases be bigger than the source table, so it should be distributed.

An option could be to introduce a specialized table type where inserts are always local. Alternatively, we should support nested transactions and ensure that subsequent commands do not read from the table or read only via the owner of the nested transaction.