Skip to content

Commit

Permalink
Merge #35806
Browse files Browse the repository at this point in the history
35806: sql: speed up index backfill validation r=vivekmenezes a=vivekmenezes

use AS OF SYSTEM TIME TO reduce contention with
write traffic.

related to #34834

Release note: None

Co-authored-by: Vivek Menezes <[email protected]>
  • Loading branch information
craig[bot] and vivekmenezes committed Mar 15, 2019
2 parents 2695531 + bb75235 commit 04ef159
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/sql/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,14 @@ func (sc *SchemaChanger) validateForwardIndexes(
}()

row, err := newEvalCtx.InternalExecutor.QueryRow(ctx, "verify-idx-count", txn,
fmt.Sprintf(`SELECT count(*) FROM [%d AS t]@[%d]`, tableDesc.ID, idx.ID))
fmt.Sprintf(`SELECT count(1) FROM [%d AS t]@[%d] AS OF SYSTEM TIME %s`,
tableDesc.ID, idx.ID, readAsOf.AsOfSystemTime()))
if err != nil {
return err
}
idxLen := int64(tree.MustBeDInt(row[0]))

log.Infof(ctx, "index %s/%s row count = %d, took %s",
log.Infof(ctx, "validation: index %s/%s row count = %d, took %s",
tableDesc.Name, idx.Name, idxLen, timeutil.Since(start))

select {
Expand Down Expand Up @@ -887,13 +888,14 @@ func (sc *SchemaChanger) validateForwardIndexes(
start := timeutil.Now()
// Count the number of rows in the table.
cnt, err := evalCtx.InternalExecutor.QueryRow(ctx, "VERIFY INDEX", txn,
fmt.Sprintf(`SELECT count(1) FROM [%d AS t]`, tableDesc.ID))
fmt.Sprintf(`SELECT count(1) FROM [%d AS t] AS OF SYSTEM TIME %s`,
tableDesc.ID, readAsOf.AsOfSystemTime()))
if err != nil {
return err
}
tableRowCount = int64(tree.MustBeDInt(cnt[0]))
tableRowCountTime = timeutil.Since(start)
log.Infof(ctx, "table %s row count = %d, took %s",
log.Infof(ctx, "validation: table %s row count = %d, took %s",
tableDesc.Name, tableRowCount, tableRowCountTime)
return nil
})
Expand Down

0 comments on commit 04ef159

Please sign in to comment.