Skip to content

Commit 229d95e

Browse files
committed
store: Start copies at the minimum vid, not just at 0
1 parent 01e6dd5 commit 229d95e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

store/postgres/src/copy.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ impl TableState {
414414
target_block: &BlockPtr,
415415
) -> Result<Self, StoreError> {
416416
#[derive(QueryableByName)]
417-
struct MaxVid {
417+
struct VidRange {
418+
#[diesel(sql_type = BigInt)]
419+
min_vid: i64,
418420
#[diesel(sql_type = BigInt)]
419421
max_vid: i64,
420422
}
@@ -424,19 +426,21 @@ impl TableState {
424426
} else {
425427
"lower(block_range) <= $1"
426428
};
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 {}",
429433
src.qualified_name.as_str(),
430434
max_block_clause
431435
))
432436
.bind::<Integer, _>(&target_block.number)
433-
.load::<MaxVid>(conn)?
437+
.load::<VidRange>(conn)?
434438
.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));
437441

438442
Ok(Self {
439-
batch: BatchCopy::new(src, dst, 0, target_vid),
443+
batch: BatchCopy::new(src, dst, next_vid, target_vid),
440444
dst_site,
441445
duration_ms: 0,
442446
})

0 commit comments

Comments
 (0)