Skip to content

Commit

Permalink
Optimize indexes (#65)
Browse files Browse the repository at this point in the history
The existing `blocks_size_created_status` index did not work well with
packing queries, so it is replaced by `blocks_pack_status_index` which
proved to work better after some experiments.

In addition we are adding `blocks_deleted_false_index` to optimize on
some queries that select blocks that have not been deleted yet.
  • Loading branch information
kaloyan-raev committed Jan 23, 2023
1 parent 28ac123 commit 28db659
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ func (db *DB) Migration() *migrate.Migration {
`CREATE INDEX IF NOT EXISTS blocks_size_created_status_index ON blocks ( size, created, pack_status )`,
},
},
{
DB: &db.DB,
Description: "Improve indexes",
Version: 2,
Action: migrate.SQL{
`DROP INDEX IF EXISTS blocks_size_created_status_index`,
`CREATE INDEX IF NOT EXISTS blocks_pack_status_index ON blocks ( pack_status ) INCLUDE ( size, created )`,
`CREATE INDEX IF NOT EXISTS blocks_deleted_false_index ON blocks ( deleted ) WHERE deleted = false`,
},
},
},
}
}
Expand Down

0 comments on commit 28db659

Please sign in to comment.