@@ -199,6 +199,8 @@ struct SampleState {
199199 left_len : usize ,
200200 right : Vec < Morsel > ,
201201 right_len : usize ,
202+ /// The number of rows each side may sample.
203+ limits : [ Arc < RelaxedCell < usize > > ; 2 ] ,
202204 /// The only side being read: the preferred build side of a join with runtime
203205 /// filters, until it ends or reaches the sample limit. A side that ends is
204206 /// complete, so its keys are published before the other side is read.
@@ -1048,11 +1050,24 @@ impl ComputeNode for SemiAntiJoinNode {
10481050 SemiAntiJoinState :: Sample ( sample_state) => {
10491051 send[ 0 ] = PortState :: Blocked ;
10501052 for ( idx, left) in [ ( 0 , true ) , ( 1 , false ) ] {
1053+ // While both sides are sampled, sampling stops once a side has
1054+ // `LOPSIDED_SAMPLE_FACTOR` times the rows of the other, done, side.
1055+ let lopsided =
1056+ sample_state. only_side . is_none ( ) && recv[ 1 - idx] == PortState :: Done ;
1057+ let limit = if lopsided {
1058+ let lopsided_limit = sample_state
1059+ . len ( !left)
1060+ . saturating_mul ( LOPSIDED_SAMPLE_FACTOR ) ;
1061+ self . params . sample_limit . min ( lopsided_limit)
1062+ } else {
1063+ self . params . sample_limit
1064+ } ;
1065+ sample_state. limits [ idx] . store ( limit) ;
10511066 if recv[ idx] == PortState :: Done {
10521067 continue ;
10531068 }
10541069 let open = sample_state. is_open ( left) ;
1055- recv[ idx] = if open && sample_state. len ( left) < self . params . sample_limit {
1070+ recv[ idx] = if open && sample_state. len ( left) < limit {
10561071 PortState :: Ready
10571072 } else {
10581073 PortState :: Blocked
@@ -1129,30 +1144,15 @@ impl ComputeNode for SemiAntiJoinNode {
11291144 match & mut self . state {
11301145 SemiAntiJoinState :: Sample ( sample_state) => {
11311146 assert ! ( send_ports[ 0 ] . is_none( ) ) ;
1132- // A side without a port is done, unless it is not being read.
1133- let final_len = |left : bool | {
1134- let idx = if left { 0 } else { 1 } ;
1135- let known = recv_ports[ idx] . is_none ( ) && sample_state. is_open ( left) ;
1136- let len = if known {
1137- sample_state. len ( left)
1138- } else {
1139- usize:: MAX
1140- } ;
1141- Arc :: new ( RelaxedCell :: from ( len) )
1142- } ;
1143- let left_final_len = final_len ( true ) ;
1144- let right_final_len = final_len ( false ) ;
1145-
11461147 if let Some ( left_recv) = recv_ports[ 0 ] . take ( ) {
11471148 join_handles. push ( scope. spawn_task (
11481149 TaskPriority :: High ,
11491150 sample_sink (
11501151 left_recv. serial ( ) ,
11511152 & mut sample_state. left ,
11521153 & mut sample_state. left_len ,
1153- left_final_len. clone ( ) ,
1154- right_final_len. clone ( ) ,
1155- self . params . sample_limit ,
1154+ sample_state. limits [ 0 ] . clone ( ) ,
1155+ sample_state. limits [ 1 ] . clone ( ) ,
11561156 ) ,
11571157 ) ) ;
11581158 }
@@ -1163,9 +1163,8 @@ impl ComputeNode for SemiAntiJoinNode {
11631163 right_recv. serial ( ) ,
11641164 & mut sample_state. right ,
11651165 & mut sample_state. right_len ,
1166- right_final_len,
1167- left_final_len,
1168- self . params . sample_limit ,
1166+ sample_state. limits [ 1 ] . clone ( ) ,
1167+ sample_state. limits [ 0 ] . clone ( ) ,
11691168 ) ,
11701169 ) ) ;
11711170 }
0 commit comments