-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
services/horizon: Improve performance of claimable balances queries (#…
…4690) Add a new table `claimable_balance_claimants` which holds all claimants' destinations for corresponding claimable balances IDs. Also, improve other filters (by `sponsor` and `asset`) but adding better indexes for such queries. We noticed that "claimable balances for claimants" query (`/claimable_balances?claimant=...`) is very slow in Postgres 12. The reason, apart from possible changes to gin index on `claimants` field, is that the `claimable_balances` table size significantly increased in the last couple months.
- Loading branch information
Showing
15 changed files
with
463 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
services/horizon/internal/db2/history/claimable_balance_claimant_batch_insert_builder.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package history | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stellar/go/support/db" | ||
"github.com/stellar/go/xdr" | ||
) | ||
|
||
// ClaimableBalanceClaimantBatchInsertBuilder is used to insert transactions into the | ||
// history_transactions table | ||
type ClaimableBalanceClaimantBatchInsertBuilder interface { | ||
Add(ctx context.Context, claimableBalanceClaimant ClaimableBalanceClaimant) error | ||
Exec(ctx context.Context) error | ||
} | ||
|
||
// ClaimableBalanceClaimantBatchInsertBuilder is a simple wrapper around db.BatchInsertBuilder | ||
type claimableBalanceClaimantBatchInsertBuilder struct { | ||
encodingBuffer *xdr.EncodingBuffer | ||
builder db.BatchInsertBuilder | ||
} | ||
|
||
// NewClaimableBalanceClaimantBatchInsertBuilder constructs a new ClaimableBalanceClaimantBatchInsertBuilder instance | ||
func (q *Q) NewClaimableBalanceClaimantBatchInsertBuilder(maxBatchSize int) ClaimableBalanceClaimantBatchInsertBuilder { | ||
return &claimableBalanceClaimantBatchInsertBuilder{ | ||
encodingBuffer: xdr.NewEncodingBuffer(), | ||
builder: db.BatchInsertBuilder{ | ||
Table: q.GetTable("claimable_balance_claimants"), | ||
MaxBatchSize: maxBatchSize, | ||
Suffix: "ON CONFLICT (id, destination) DO UPDATE SET last_modified_ledger=EXCLUDED.last_modified_ledger", | ||
}, | ||
} | ||
} | ||
|
||
// Add adds a new transaction to the batch | ||
func (i *claimableBalanceClaimantBatchInsertBuilder) Add(ctx context.Context, claimableBalanceClaimant ClaimableBalanceClaimant) error { | ||
return i.builder.RowStruct(ctx, claimableBalanceClaimant) | ||
} | ||
|
||
func (i *claimableBalanceClaimantBatchInsertBuilder) Exec(ctx context.Context) error { | ||
return i.builder.Exec(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.