hasura / hasura/graphql-engine

citus: support event triggers on local and reference tables

Open
#7,188 1 comment 0 reactions 0 assignees View on GitHub
a/eventing/data-triggers k/enhancement
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

Supporting event triggers on distributed tables is not straightforward on Citus. Ideally, we'll need to create our capture tables on all worker nodes. Depending on the kind of table, we'll need to create a trigger on the backing postgres table to insert into the capture table on the node on which the backing table resides.

The current preview version of Citus (in US east region) maintains a copy of a reference table on the coordinator node. If we scope this down to only support triggers on local and reference tables, we can get away by creating the capture tables only on the coordinator node. Event triggers on local tables work as expected and for reference tables, we just have to create the trigger on the coordinator's copy. This is from Microsoft's response:

```sql
select distinct
s.shardid
from pg_dist_shard_placement sp join pg_dist_shard s
on s.shardid=sp.shardid
where logicalrelid='category'::regclass;
```
(`category` is a reference table) would respond with something like:
```
shardid
---------
102008
```

The trigger on the reference table’s coordinator copy can then be created as follows:

```sql
CREATE TRIGGER event_log_capture AFTER INSERT OR DELETE OR UPDATE ON category_102008
FOR EACH ROW EXECUTE PROCEDURE event_log_capture();
```

Contributor guide

Open the contributing guide

Research direction

No repository files or tests are named. Start by reviewing the Citus behavior and SQL examples in the issue, including pg_dist_shard and the coordinator’s reference-table copy. Done means event triggers work for local and reference tables, with capture tables and triggers placed where those tables reside, without claiming distributed-table support.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgres
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.