Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit bf4eb26

Browse files
fix: Add Exists method to dbworker Store to avoid COUNT(*) (#64297)
Running `COUNT(*)` on hot tables like lsif_indexes on Sourcegraph.com shows up on profiles when the number of executors is bumped to 30+, and when the table has 100K+ jobs. So avoid `COUNT(*)` where possible.
1 parent 99f7d97 commit bf4eb26

File tree

6 files changed

+274
-58
lines changed

6 files changed

+274
-58
lines changed

cmd/frontend/internal/executorqueue/handler/multihandler.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,19 @@ func (m *MultiHandler) SelectNonEmptyQueues(ctx context.Context, queueNames []st
282282
var nonEmptyQueues []string
283283
for _, queue := range queueNames {
284284
var err error
285-
var count int
285+
var isNonEmpty bool
286+
statesBitset := dbworkerstore.StateQueued | dbworkerstore.StateErrored
286287
switch queue {
287288
case m.BatchesQueueHandler.Name:
288-
count, err = m.BatchesQueueHandler.Store.QueuedCount(ctx, false)
289+
isNonEmpty, err = m.BatchesQueueHandler.Store.Exists(ctx, statesBitset)
289290
case m.AutoIndexQueueHandler.Name:
290-
count, err = m.AutoIndexQueueHandler.Store.QueuedCount(ctx, false)
291+
isNonEmpty, err = m.AutoIndexQueueHandler.Store.Exists(ctx, statesBitset)
291292
}
292293
if err != nil {
293294
m.logger.Error("fetching queue size", log.Error(err), log.String("queue", queue))
294295
return nil, err
295296
}
296-
if count != 0 {
297+
if isNonEmpty {
297298
nonEmptyQueues = append(nonEmptyQueues, queue)
298299
}
299300
}

0 commit comments

Comments
 (0)