@@ -20,8 +20,10 @@ defmodule Electric.Shapes.Consumer.EventHandler.Subqueries.IndexChanges do
2020
2121 For a negated (`NOT IN`) subquery:
2222 - Adding values to the index *narrows* the filter (fewer rows match).
23- - So a move-in does **not** update the index at enqueue time (keeping the
24- filter broad); the add is deferred until **complete**.
23+ - So a dependency move-in does **not** update the index at enqueue time
24+ (keeping the filter broad); the add is deferred until **complete**.
25+ - A dependency move-out broadens the filter by removing the value from the
26+ index immediately, and that removal remains correct after the splice.
2527
2628 ## Effect tables
2729
@@ -31,8 +33,8 @@ defmodule Electric.Shapes.Consumer.EventHandler.Subqueries.IndexChanges do
3133 |------------|----------|---------------------------|
3234 | move_in | positive | AddToSubqueryIndex |
3335 | move_in | negated | *(none)* |
34- | move_out | positive | RemoveFromSubqueryIndex |
35- | move_out | negated | *(none)* |
36+ | move_out | positive | *(none)* |
37+ | move_out | negated | RemoveFromSubqueryIndex |
3638
3739 ### When complete (splice finished, or immediate for non-buffering cases)
3840
@@ -58,9 +60,11 @@ defmodule Electric.Shapes.Consumer.EventHandler.Subqueries.IndexChanges do
5860 @ type move :: { :move_in | :move_out , non_neg_integer ( ) , list ( ) }
5961
6062 @ doc """
61- Returns index effects to apply when a dependency move event is first enqueued .
63+ Returns index effects to apply when a dependency move event starts buffering .
6264
63- Used by buffering cases to broaden the filter before the move-in query runs.
65+ Used only by buffering cases to broaden the filter before the move-in query
66+ runs. Calling this for an immediate (non-buffering) move is a bug in the
67+ caller.
6468 """
6569 @ spec effects_for_enqueue ( DnfPlan . t ( ) , move ( ) , [ String . t ( ) ] ) ::
6670 [ Effect.AddToSubqueryIndex . t ( ) | Effect.RemoveFromSubqueryIndex . t ( ) ]
@@ -77,10 +81,7 @@ defmodule Electric.Shapes.Consumer.EventHandler.Subqueries.IndexChanges do
7781 }
7882 ]
7983
80- { :negated , :move_in } ->
81- [ ]
82-
83- { :positive , :move_out } ->
84+ { :negated , :move_out } ->
8485 [
8586 % Effect.RemoveFromSubqueryIndex {
8687 dep_index: dep_index ,
@@ -89,8 +90,9 @@ defmodule Electric.Shapes.Consumer.EventHandler.Subqueries.IndexChanges do
8990 }
9091 ]
9192
92- { :negated , :move_out } ->
93- [ ]
93+ other ->
94+ raise ArgumentError ,
95+ "effects_for_enqueue/3 only supports buffering cases, got #{ inspect ( other ) } "
9496 end
9597 end
9698
0 commit comments