Skip to content

Commit

Permalink
satellitedb: add wallet address index to storjscan_wallet table
Browse files Browse the repository at this point in the history
Adding an index to the wallet address field of the storjscan wallet table to improve query performance. This should prevent having to do a full table scan when we query for one or more wallet addresses for a given user in our queries.

Change-Id: Ic1b5d06c2258489e5464d186fed5270172f8cba5
  • Loading branch information
dlamarmorgan authored and Storj Robot committed Aug 15, 2022
1 parent 1f06387 commit ac24150
Show file tree
Hide file tree
Showing 7 changed files with 766 additions and 2 deletions.
2 changes: 2 additions & 0 deletions satellite/satellitedb/dbx/satellitedb.dbx
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,8 @@ model storjscan_wallet (
field user_id blob
field wallet_address blob
field created_at timestamp ( autoinsert )

index ( fields wallet_address )
)

create storjscan_wallet ( noreturn )
Expand Down
2 changes: 2 additions & 0 deletions satellite/satellitedb/dbx/satellitedb.dbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ CREATE INDEX storagenode_payments_node_id_period_index ON storagenode_payments (
CREATE INDEX storagenode_paystubs_node_id_index ON storagenode_paystubs ( node_id ) ;
CREATE INDEX storagenode_storage_tallies_node_id_index ON storagenode_storage_tallies ( node_id ) ;
CREATE INDEX storjscan_payments_block_number_log_index_index ON storjscan_payments ( block_number, log_index ) ;
CREATE INDEX storjscan_wallets_wallet_address_index ON storjscan_wallets ( wallet_address ) ;
CREATE INDEX webapp_sessions_user_id_index ON webapp_sessions ( user_id ) ;
CREATE UNIQUE INDEX credits_earned_user_id_offer_id ON user_credits ( id, offer_id ) ;`
}
Expand Down Expand Up @@ -1577,6 +1578,7 @@ CREATE INDEX storagenode_payments_node_id_period_index ON storagenode_payments (
CREATE INDEX storagenode_paystubs_node_id_index ON storagenode_paystubs ( node_id ) ;
CREATE INDEX storagenode_storage_tallies_node_id_index ON storagenode_storage_tallies ( node_id ) ;
CREATE INDEX storjscan_payments_block_number_log_index_index ON storjscan_payments ( block_number, log_index ) ;
CREATE INDEX storjscan_wallets_wallet_address_index ON storjscan_wallets ( wallet_address ) ;
CREATE INDEX webapp_sessions_user_id_index ON webapp_sessions ( user_id ) ;
CREATE UNIQUE INDEX credits_earned_user_id_offer_id ON user_credits ( id, offer_id ) ;`
}
Expand Down
1 change: 1 addition & 0 deletions satellite/satellitedb/dbx/satellitedb.dbx.pgx.sql
Original file line number Diff line number Diff line change
Expand Up @@ -578,5 +578,6 @@ CREATE INDEX storagenode_payments_node_id_period_index ON storagenode_payments (
CREATE INDEX storagenode_paystubs_node_id_index ON storagenode_paystubs ( node_id ) ;
CREATE INDEX storagenode_storage_tallies_node_id_index ON storagenode_storage_tallies ( node_id ) ;
CREATE INDEX storjscan_payments_block_number_log_index_index ON storjscan_payments ( block_number, log_index ) ;
CREATE INDEX storjscan_wallets_wallet_address_index ON storjscan_wallets ( wallet_address ) ;
CREATE INDEX webapp_sessions_user_id_index ON webapp_sessions ( user_id ) ;
CREATE UNIQUE INDEX credits_earned_user_id_offer_id ON user_credits ( id, offer_id ) ;
1 change: 1 addition & 0 deletions satellite/satellitedb/dbx/satellitedb.dbx.pgxcockroach.sql
Original file line number Diff line number Diff line change
Expand Up @@ -578,5 +578,6 @@ CREATE INDEX storagenode_payments_node_id_period_index ON storagenode_payments (
CREATE INDEX storagenode_paystubs_node_id_index ON storagenode_paystubs ( node_id ) ;
CREATE INDEX storagenode_storage_tallies_node_id_index ON storagenode_storage_tallies ( node_id ) ;
CREATE INDEX storjscan_payments_block_number_log_index_index ON storjscan_payments ( block_number, log_index ) ;
CREATE INDEX storjscan_wallets_wallet_address_index ON storjscan_wallets ( wallet_address ) ;
CREATE INDEX webapp_sessions_user_id_index ON webapp_sessions ( user_id ) ;
CREATE UNIQUE INDEX credits_earned_user_id_offer_id ON user_credits ( id, offer_id ) ;
9 changes: 9 additions & 0 deletions satellite/satellitedb/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,15 @@ func (db *satelliteDB) PostgresMigration() *migrate.Migration {
`ALTER TABLE projects ADD COLUMN salt bytea;`,
},
},
{
DB: &db.migrationDB,
Description: "create new index on wallet address to improve queries.",
Version: 207,
SeparateTx: true,
Action: migrate.SQL{
`CREATE INDEX IF NOT EXISTS storjscan_wallets_wallet_address_index ON storjscan_wallets ( wallet_address );`,
},
},
// NB: after updating testdata in `testdata`, run
// `go generate` to update `migratez.go`.
},
Expand Down
5 changes: 3 additions & 2 deletions satellite/satellitedb/migratez.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (db *satelliteDB) testMigration() *migrate.Migration {
{
DB: &db.migrationDB,
Description: "Testing setup",
Version: 206,
Version: 207,
Action: migrate.SQL{`-- AUTOGENERATED BY storj.io/dbx
-- DO NOT EDIT
CREATE TABLE accounting_rollups (
Expand Down Expand Up @@ -269,7 +269,7 @@ CREATE TABLE projects (
partner_id bytea,
user_agent bytea,
owner_id bytea NOT NULL,
salt bytea,
salt bytea,
created_at timestamp with time zone NOT NULL,
PRIMARY KEY ( id )
);
Expand Down Expand Up @@ -597,6 +597,7 @@ CREATE INDEX storagenode_payments_node_id_period_index ON storagenode_payments (
CREATE INDEX storagenode_paystubs_node_id_index ON storagenode_paystubs ( node_id ) ;
CREATE INDEX storagenode_storage_tallies_node_id_index ON storagenode_storage_tallies ( node_id ) ;
CREATE INDEX storjscan_payments_block_number_log_index_index ON storjscan_payments ( block_number, log_index ) ;
CREATE INDEX storjscan_wallets_wallet_address_index ON storjscan_wallets ( wallet_address ) ;
CREATE INDEX webapp_sessions_user_id_index ON webapp_sessions ( user_id ) ;
CREATE UNIQUE INDEX credits_earned_user_id_offer_id ON user_credits ( id, offer_id ) ;
Expand Down
Loading

1 comment on commit ac24150

@storjrobot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Storj Community Forum (official). There might be relevant details there:

https://forum.storj.io/t/release-preparation-v1-62/19444/1

Please sign in to comment.