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

[Lake][Subgraph] Improve query structure (and maybe performance) #575

Closed
1 task
idiom-bytes opened this issue Jan 25, 2024 · 4 comments
Closed
1 task
Labels

Comments

@idiom-bytes
Copy link
Member

idiom-bytes commented Jan 25, 2024

Motivation

There are various queries inside subgraph/ that may perform less than optimal due to their structure. Nested where clauses may improve the performance or not.

Queries such as the one inside subgraph_payouts.py could perhaps be improved.

Examples

How to restructure predictPayouts such that we can implement an _in array[] where clause.

query{
  predictPayouts{
    payout
    prediction{
      slot{
        predictContract(where: {id_in:["0x18f54cc21b7a2fdd011bea06bba7801b280e3151"]}){
          token {
            id
          }
        }
      }
    }
  }
}

DoD:

  • Improved query structure and performance for the goals of updating lake/analytics
@idiom-bytes idiom-bytes changed the title [Lake] Improve lake/analytics query structure & performance [Lake][Subgraph] Improve query structure & performance Jan 25, 2024
@idiom-bytes idiom-bytes changed the title [Lake][Subgraph] Improve query structure & performance [Lake][Subgraph] Improve query structure & performance (maybe) Jan 25, 2024
@idiom-bytes idiom-bytes changed the title [Lake][Subgraph] Improve query structure & performance (maybe) [Lake][Subgraph] Improve query structure (and maybe performance) Jan 25, 2024
@idiom-bytes
Copy link
Member Author

Notes

Overall, we have low conviction around problems/improvements as a result of this update.
This is therefore low priority.

@idiom-bytes
Copy link
Member Author

idiom-bytes commented Jan 25, 2024

We can improve the fetch step by returning more of the expected records from predictPredictions. By doing this, we can reduce the need to fetch the predictPayouts table. We would still need to handle the predctTruevals.

If we can improve the number of fetches and compute further, consider increasing priority.
oceanprotocol/ocean-subgraph#760

query{
  predictPredictions(where:{ or: [{timestamp_gt:100},{payout_:{timestamp_gt:100}}]}){
    slot{
      id
    }
    user {
      id
    }
    stake
    payout{
      
      timestamp
      id
    }
  }
}

@kdetry
Copy link
Contributor

kdetry commented Jan 31, 2024

I spent some time and let me explain why the first example won't work.

Based on the provided GraphQL query, it seems that you want to filter predictPayouts based on a specific predictContract value. Tha query is not convenient for this goal


query {
  predictPayouts {
    payout
    prediction {
      slot {
        predictContract(where: {id_in: ["0x18f54cc21b7a2fdd011bea06bba7801b280e3151"]}) {
          token {
            id
          }
        }
      }
    }
  }
}

In this query:

  • The predictPayouts are being retrieved without any filtering at their level.
  • The filtering is applied at the predictContract level using where: {id_in: [...]}.
  • This means all predictPayouts are retrieved, but only the predictContract with the specified ID is filtered within each predictPayout.

The limitation here is that the filtering for predictContract does not directly filter the predictPayouts.

  • Instead, it only filters the predictContract within each predictPayout result.
  • the goal is to retrieve only those predictPayouts that have a specific predictContract, so, the query needs to be different, we have to put the parameter to the main "where" query.

I feel like we did a short talk about it but I couldn't be sure and I explained with text

@idiom-bytes
Copy link
Member Author

There are still low performance queries and other things that aren't optimal but i'm closing this issue and moving everything to #1299 for further review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants