@@ -414,7 +414,9 @@ impl TableState {
414
414
target_block : & BlockPtr ,
415
415
) -> Result < Self , StoreError > {
416
416
#[ derive( QueryableByName ) ]
417
- struct MaxVid {
417
+ struct VidRange {
418
+ #[ diesel( sql_type = BigInt ) ]
419
+ min_vid : i64 ,
418
420
#[ diesel( sql_type = BigInt ) ]
419
421
max_vid : i64 ,
420
422
}
@@ -424,19 +426,21 @@ impl TableState {
424
426
} else {
425
427
"lower(block_range) <= $1"
426
428
} ;
427
- let target_vid = sql_query ( format ! (
428
- "select coalesce(max(vid), -1) as max_vid from {} where {}" ,
429
+ let ( next_vid, target_vid) = sql_query ( format ! (
430
+ "select coalesce(min(vid), 0) as min_vid, \
431
+ coalesce(max(vid), -1) as max_vid \
432
+ from {} where {}",
429
433
src. qualified_name. as_str( ) ,
430
434
max_block_clause
431
435
) )
432
436
. bind :: < Integer , _ > ( & target_block. number )
433
- . load :: < MaxVid > ( conn) ?
437
+ . load :: < VidRange > ( conn) ?
434
438
. first ( )
435
- . map ( |v| v . max_vid )
436
- . unwrap_or ( - 1 ) ;
439
+ . map ( |v| ( v . min_vid , v . max_vid ) )
440
+ . unwrap_or ( ( 0 , - 1 ) ) ;
437
441
438
442
Ok ( Self {
439
- batch : BatchCopy :: new ( src, dst, 0 , target_vid) ,
443
+ batch : BatchCopy :: new ( src, dst, next_vid , target_vid) ,
440
444
dst_site,
441
445
duration_ms : 0 ,
442
446
} )
0 commit comments