Skip to content

Commit

Permalink
store: Improve predictability of the time for each batch during pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
lutter committed Nov 9, 2022
1 parent 013c2c9 commit affe317
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions store/postgres/src/relational/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,20 @@ impl TablePair {
loop {
let start = Instant::now();
let LastVid { last_vid, rows } = conn.transaction(|| {
// The query limits the number of rows we look at in each
// batch, rather than the number of matching rows to make
// the timing for each batch independent of how many rows
// we actually need to copy. This has the downside that it
// will force a sequential scan, but limiting by the number
// of matching rows runs the risk of a batch taking
// unpredictably long if there are only very few matches.
sql_query(&format!(
"with cp as (insert into {dst}({column_list}) \
select {column_list} from {src} \
select {column_list} from ( \
select {column_list} from {src} \
where vid >= $3 \
order by vid \
limit $4) a \
where lower(block_range) <= $2 \
and coalesce(upper(block_range), 2147483647) > $1 \
and coalesce(upper(block_range), 2147483647) <= $2 \
Expand Down Expand Up @@ -153,9 +164,15 @@ impl TablePair {
loop {
let start = Instant::now();
let LastVid { rows, last_vid } = conn.transaction(|| {
// See the comment on the query in `copy_final_entities` for
// why this query is written this way
sql_query(&format!(
"with cp as (insert into {dst}({column_list}) \
select {column_list} from {src} \
select {column_list} from ( \
select {column_list} from {src} \
where vid >= $2 \
order by vid \
limit $3) a
where coalesce(upper(block_range), 2147483647) > $1 \
and block_range && int4range($1, null) \
and vid >= $2 \
Expand Down

0 comments on commit affe317

Please sign in to comment.