Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: Optimize sub-queries for assets/apps against a given address. #1615

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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++
}

Check warning on line 1808 in idb/postgres/postgres.go

View check run for this annotation

Codecov / codecov/patch

idb/postgres/postgres.go#L1805-L1808

Added lines #L1805 - L1808 were not covered by tests
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)

Check warning on line 1813 in idb/postgres/postgres.go

View check run for this annotation

Codecov / codecov/patch

idb/postgres/postgres.go#L1813

Added line #L1813 was not covered by tests
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)

Check warning on line 1823 in idb/postgres/postgres.go

View check run for this annotation

Codecov / codecov/patch

idb/postgres/postgres.go#L1816-L1823

Added lines #L1816 - L1823 were not covered by tests
}
// filters against main account table
if len(opts.GreaterThanAddress) > 0 {
Expand Down
Loading