Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pkg/dotc1z/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,21 @@ func backfillGrantExpansionColumn(ctx context.Context, db *goqu.Database, tableN
// GrantExpandable annotation (if present), and populate the expansion column.
// Non-expandable grants get an empty-blob sentinel to avoid re-processing,
// which is cleaned up to NULL at the end.
//
// Uses cursor-based pagination (g.id > ?) so each query jumps to unprocessed
// rows via the primary key index instead of rescanning from the start.
var lastID int64
for {
rows, err := db.QueryContext(ctx, fmt.Sprintf(
`SELECT g.id, g.data FROM %s g
JOIN %s sr ON g.sync_id = sr.sync_id
WHERE g.expansion IS NULL
WHERE g.id > ?
AND g.expansion IS NULL
AND sr.supports_diff = 0
ORDER BY g.id
LIMIT 1000`,
tableName, syncRuns.Name(),
))
), lastID)
if err != nil {
return err
}
Expand Down Expand Up @@ -402,6 +408,8 @@ func backfillGrantExpansionColumn(ctx context.Context, db *goqu.Database, tableN
break
}

lastID = batch[len(batch)-1].id

tx, err := db.BeginTx(ctx, nil)
if err != nil {
return err
Expand Down
Loading