Triggers on citus local tables cannot modify distributed tables
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
A variation of https://github.com/citusdata/citus/issues/4148. I think we do NOT trigger 2PC on citus local tables, hence the problem has changed:
First, create the citus local table and the triggers:
```SQL
CREATE TABLE distributed_table(value int);
SELECT create_distributed_table('distributed_table', 'value');
CREATE FUNCTION insert_42() RETURNS trigger AS $insert_42$
BEGIN
INSERT INTO distributed_table VALUES (42);
RETURN NEW;
END;
$insert_42$ LANGUAGE plpgsql;
CREATE TABLE citus_local_table (value int);
select citus_add_local_table_to_metadata('citus_local_table');
INSERT INTO citus_local_table SELECT i from generate_series(0,10000)i;
CREATE TRIGGER insert_42_trigger
AFTER DELETE ON citus_local_table
FOR EACH ROW EXECUTE FUNCTION insert_42();
```
Now, run the following tx from the coordintor, all works fine
```SQL
BEGIN;
DELETE FROM citus_local_table WHERE value = 1;
SELECT count(*) FROM distributed_table;
count
-------
1
(1 row)
ROLLBACK;
```
If you execute the same transaction from the worker, the impact of the trigger cannot be seen, because the trigger is executed from the workers. The changes becomes visible after the TX commits
```SQL
BEGIN;
DELETE FROM citus_local_table WHERE value = 1;
SELECT count(*) FROM distributed_table;
count
-------
0
(1 row)
COMMIT;
SELECT count(*) FROM distributed_table;
count
-------
1
(1 row)
```
Marking #3130 and
Contributor guide
Assessment
This issue has not been assessed yet.