Skip to content

Commit a41f9f5

Browse files
committed
fix(db): improve performance of the GetValidatorDutiesInfo sql query
1 parent e9d3915 commit a41f9f5

File tree

1 file changed

+6
-3
lines changed
  • backend/pkg/commons/db

1 file changed

+6
-3
lines changed

backend/pkg/commons/db/db.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,12 +2229,15 @@ func GetValidatorDutiesInfo(startSlot uint64) ([]types.ValidatorDutyInfo, error)
22292229
blocks.status,
22302230
COALESCE(blocks.exec_block_number, 0) AS exec_block_number,
22312231
blocks.syncaggregate_bits,
2232-
blocks_attestations.validators,
2233-
blocks_attestations.slot AS attested_slot,
2232+
a.validators,
2233+
a.slot AS attested_slot,
22342234
blocks.proposerslashingscount,
22352235
blocks.attesterslashingscount
22362236
FROM blocks
2237-
LEFT JOIN blocks_attestations ON blocks.slot = blocks_attestations.block_slot
2237+
-- joining against a subquery instead of blocks_attestations for performance-reasons
2238+
LEFT JOIN (
2239+
SELECT block_slot, slot, validators from blocks_attestations where block_slot >= $1
2240+
) a ON blocks.slot = a.block_slot
22382241
WHERE blocks.slot >= $1
22392242
`, startSlot)
22402243

0 commit comments

Comments
 (0)