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

[mtg-808] optimize select for show fungible display option #363

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kstepanovdev
Copy link
Contributor

The PR optimizes the search request via dropping OR condition if a search for all token types is requested. OR condition in such case provokes seq scan through the table.
To avoid this, UNION between two selects is used instead.

| TokenType::RegularNFT
| TokenType::CompressedNFT => {}
TokenType::All => {
query_builder.push(" UNION ALL ");
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need union all here? It might return you duplicate asset_ids, which doesn't look like expected behaviour. Although to be fair it should not receive duplicates in this union, I'd suggest using just the UNION here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not.

@@ -262,14 +296,11 @@ fn add_filter_clause<'a>(
TokenType::All => {
query_builder.push(" AND (assets_v3.ast_owner = ");
query_builder.push_bind(owner_address);
query_builder.push(" OR (fungible_tokens.fbt_owner = ");
query_builder.push_bind(owner_address);
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like the below if should also be dropped. As well as the whole join on fungible_tokens. Also @n00m4d might be working on a concurrent task with balances. I believe with your change and dropped join Vadim task will also be solved.

@kstepanovdev kstepanovdev force-pushed the fix/optimize-select-for-show_fungible-display-option branch 2 times, most recently from 6ea2016 to 24edbb4 Compare January 16, 2025 12:20
@kstepanovdev kstepanovdev force-pushed the fix/optimize-select-for-show_fungible-display-option branch from 24edbb4 to 9b02344 Compare January 16, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants