feat(sync-service): Clean up publication filters
Closes https://github.com/electric-sql/electric/issues/1774
This work started to introduce column filters (see https://github.com/electric-sql/electric/issues/1831) but ended up on a road block because of us using REPLICA IDENTITY FULL - however the work also takes care of cleaning up filters.
- Introduced singular process for updating publication - we were locking on it before anyway, might as well linearise it ourselves.
- Process maintains reference counted structure for the filters per relation, including where clauses and filtered columns, in order to produce correct overall filters per relation
- Update to the publication is debounced to allow batching together many shape creations
- Every update does a complete rewrite of the publication filters so they are maintained clean - but also introduced a
remove_shapecall so that if electric remains with no shapes it should also have no subscriptions to tables.
TODOs
- [x] Write tests for
PublicationManager - [x] Write procedure for recovering in-memory state from
shape_status.list_shapesinrecover_shapes - [ ] Split where clauses at top-level
ANDs to improve filter optimality (suggested be @icehaunter ) - [edit: not doing this now, as we can be smart about this an do even more "merging" of where clauses likex = 1andx = 2tox in (1, 2)- separate PR]
Regarding https://github.com/electric-sql/electric/issues/1831 - we need to figure out when we need REPLICA IDENTITY FULL and make it so that it is only set when necessary (and column filters are removed in that case)
Once we determine if we can afford not to use REPLICA IDENTITY FULL at all times then we should be able to do column filtering easily with these changes.
benchmark this
Benchmark results, triggered for f8edd
concurrent shape creation completed
OLD

NEW
benchmark this
Benchmark results, triggered for 8d697
- write fanout completed
- diverse shape fanout completed
- concurrent shape creation completed
- many shapes one client latency completed
- unrelated shapes one client latency completed