Skip to content

Commit

Permalink
Optimize sub-queries for assets/apps against a given address. (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalouf authored Jun 6, 2024
1 parent b019536 commit 26b4eff
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1799,13 +1799,28 @@ func (db *IndexerDb) buildAccountQuery(opts idb.AccountQueryOptions, countOnly b
whereArgs = append(whereArgs, *opts.AssetLT)
partNumber++
}

// We want to limit the size of the results in this query to what could actually be needed
if len(opts.GreaterThanAddress) > 0 {
aq += fmt.Sprintf(" AND addr > $%d", partNumber)
whereArgs = append(whereArgs, opts.GreaterThanAddress)
partNumber++
}
aq = "qasf AS (" + aq + ")"
withClauses = append(withClauses, aq)
}
if opts.HasAppID != 0 {
withClauses = append(withClauses, fmt.Sprintf("qapf AS (SELECT addr FROM account_app WHERE app = $%d)", partNumber))
aq := fmt.Sprintf("SELECT addr FROM account_app WHERE app = $%d", partNumber)
whereArgs = append(whereArgs, opts.HasAppID)
partNumber++

if len(opts.GreaterThanAddress) > 0 {
aq += fmt.Sprintf(" AND addr > $%d", partNumber)
whereArgs = append(whereArgs, opts.GreaterThanAddress)
partNumber++
}
aq = "qapf AS (" + aq + ")"
withClauses = append(withClauses, aq)
}
// filters against main account table
if len(opts.GreaterThanAddress) > 0 {
Expand Down

0 comments on commit 26b4eff

Please sign in to comment.