ccip icon indicating copy to clipboard operation
ccip copied to clipboard

Add id column as PRIMARY KEY for evm.logs & evm.log_poller_blocks

Open reductionista opened this issue 1 year ago • 1 comments

Problem:

The query for pruning expired logs with a max limit set was taking longer than it should. This was part due to needing to join on an awkward combination combination of columns due to their being no single primary key.

Solution:

  • Add id column as PRIMARY KEY for evm.logs & evm.log_poller_blocks
  • Join on id column instead of previous primary keys
  • Replace all SELECT *'s with helper functions for selecting all columns
  • Refactor nestedBlockQuery into withConfs, and make a bit more use of it## Motivation

While adding the id column, we can't just remove the old primary key because the index on it was helping to accelerate some queries. Instead of just resurrecting it as-is, I took the opportunity to clean up several of the indices on the logs & blocks table. Some indexed columns (eg created_at) were never actually being used, while others were not ordered in the most optimal way for accelerating the queries we have. Also, at least one of them was redundant with the primary key just in a different order.

reductionista avatar Sep 14 '24 02:09 reductionista

Quality Gate failed Quality Gate failed

Failed conditions
42.2% Coverage on New Code (required ≥ 75%)

See analysis details on SonarQube

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Nov 10 '24 00:11 github-actions[bot]

This PR was closed because it has been stalled for 10 days with no activity.

github-actions[bot] avatar Nov 21 '24 00:11 github-actions[bot]