Skip to content

Commit

Permalink
ttljob: add hint to use PK in delete query
Browse files Browse the repository at this point in the history
This will help avoid choosing a plan that scans a secondary index, which
can lead to many KV rows being scanned and also lead to contention.

Release note (bug fix): Fixed a bug that could cause DELETE queries sent
by the row-level TTL job to use a secondary index rather than the
primary index to find the rows to delete. This could lead to some DELETE
operations taking a much longer time than they should. This bug was
present since v22.2.0.
  • Loading branch information
rafiss committed Jan 25, 2024
1 parent 6085a47 commit 9720131
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/sql/ttl/ttljob/ttljob_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (t *ttlProcessor) work(ctx context.Context) error {
return errors.Wrapf(err, "error fetching table relation name for TTL")
}

relationName = tn.FQString()
relationName = tn.FQString() + "@" + lexbase.EscapeSQLIdent(primaryIndexDesc.Name)
return nil
}); err != nil {
return err
Expand Down

0 comments on commit 9720131

Please sign in to comment.