Skip to content

Commit a65dd92

Browse files
committed
add composite index to gold_table
1 parent 0b05b8e commit a65dd92

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package _202509181400_goldTableCompositeIndex
2+
3+
import (
4+
"database/sql"
5+
6+
"github.com/Layr-Labs/sidecar/internal/config"
7+
"gorm.io/gorm"
8+
)
9+
10+
func (m *Migration) Down(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
11+
// Drop the composite index
12+
query := `drop index if exists idx_gold_table_composite;`
13+
14+
res := grm.Exec(query)
15+
if res.Error != nil {
16+
return res.Error
17+
}
18+
return nil
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package _202509181400_goldTableCompositeIndex
2+
3+
import (
4+
"database/sql"
5+
6+
"github.com/Layr-Labs/sidecar/internal/config"
7+
"gorm.io/gorm"
8+
)
9+
10+
type Migration struct {
11+
}
12+
13+
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
14+
// Create composite index optimized for the FetchRewardsForSnapshot query
15+
query := `create index concurrently if not exists idx_gold_table_composite on gold_table (snapshot, reward_hash, earner, token);`
16+
17+
res := grm.Exec(query)
18+
if res.Error != nil {
19+
return res.Error
20+
}
21+
return nil
22+
}
23+
24+
func (m *Migration) GetName() string {
25+
return "202509181400_goldTableCompositeIndex"
26+
}

pkg/postgres/migrations/migrator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import (
8181
_202506172149_snapshotUniqueConstraintsPartTwo "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202506172149_snapshotUniqueConstraintsPartTwo"
8282
_202507301346_taskMailboxTables "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202507301346_taskMailboxTables"
8383
_202507301421_crossChainRegistryTables "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202507301421_crossChainRegistryTables"
84+
_202509181400_goldTableCompositeIndex "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202509181400_goldTableCompositeIndex"
8485
)
8586

8687
// Migration interface defines the contract for database migrations.
@@ -203,6 +204,7 @@ func (m *Migrator) MigrateAll() error {
203204
&_202502180836_snapshotUniqueConstraints.Migration{},
204205
&_202503051449_addContractTypeColumn.Migration{},
205206
&_202503311108_goldRewardHashIndex.Migration{},
207+
&_202509181400_goldTableCompositeIndex.Migration{},
206208
&_202501241322_operatorDirectedOperatorSetRewardSubmissions.Migration{},
207209
&_202501241533_operatorSetSplits.Migration{},
208210
&_202501271727_operatorSetOperatorRegistrations.Migration{},

0 commit comments

Comments
 (0)