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 issue on nested o2m reading #11873
Comments
This is known and in the works here: #11246 The short answer to the long question "Obviously so many unions is going to be small, why not just:" is limits. We want to fetch The union query approach alleviated that, by being able to have a |
Could we conditionally change the query based on the presence of the limit parameter? |
Ok I understand. Chunking the queries could help, although this entire issue for using UNION seems to be due to a high number of child records if I understand correctly. In which case it is probably not ideal to run a query without filtering, since you will anyways end up with performance issues down the line. Thanks though. |
Absolutely, that's the problem here 😄 We want to fetch up to
However, in SQL when doing a SELECT * FROM example WHERE IN parent_id (1, 2) LIMIT 3 will only fetch 3 items total, instead of the 3 items per parent. If we were to double the limit based on the amount of parents: SELECT * FROM example WHERE IN parent_id (1, 2) LIMIT 6 you would end up with:
as the limit is on the total set of nested items (before "stitching"). At first (in a previous alpha), we would fetch all related o2m items into memory, and then apply the limit in javascript. This obviously causes some performance issues in memory, as you can end up loading a virtually endless amount of records into memory. This wasn't as big of a deal when you had a couple thousand items to stitch, but would really cause trouble when you're talking larger data sets. My proposed fix on the PR is effectively reverting to the previous setup, but doing it in a way that doesn't require loading the whole related table into memory at once. Instead, we can batch over the rows in the table in chunks of |
Preflight Checklist
Describe the Bug
Using directus
items
api and requesting specific fields on a relationship such as in the case of:Person here being a relation on this particular collection. I was wondering why it was slow and was shocked to find the query being executed against the database looked like this:
Obviously so many unions is going to be small, why not just
To Reproduce
Setup a collection with a relationship (M2O) to another collection.
Make an api request to that collection with a similar query as shown above.
You might need to monitor your database for queries or console log the queries being executed using trace in ENV
Errors Shown
Actually have been getting 500 errors if I have too high a limit.
What version of Directus are you using?
9.5.2
What version of Node.js are you using?
16.4.0
What database are you using?
mysql 8
What browser are you using?
chrome
What operating system are you using?
linux
How are you deploying Directus?
GCP
The text was updated successfully, but these errors were encountered: