Skip to content

imp/improved db queries#25910

Open
u12206050 wants to merge 9 commits intodirectus:mainfrom
u12206050:imp/improved-db-queries
Open

imp/improved db queries#25910
u12206050 wants to merge 9 commits intodirectus:mainfrom
u12206050:imp/improved-db-queries

Conversation

@u12206050
Copy link
Contributor

@u12206050 u12206050 commented Sep 28, 2025

  • Use context aware alias on queries (Also in another PR)
  • Use WHERE EXISTS instead of JOINS
    • If have to join, use info about schema to determine using inner vs left join

Scope

What's changed:

The sql being generated is focused on using operations the DB can optimise instead of LEFT JOINS, which the DB just can't optimise as good.

Potential Risks / Drawbacks

  • Since we drop left joins, doing SELECT * won't select the fields on the related collections, but since Directus does either specify exactly the fields, or fetches related items in a separate request, most users won't notice this except for the improved performance.

Tested Scenarios

  • Tested existing tests, only updating the alias and the change from join to exists.

Review Notes / Questions

  • I should probably go through this with someone on the team.

Checklist

  • Tested in a live production.

Fixes #25861

@u12206050 u12206050 requested a review from a team as a code owner September 28, 2025 19:52
@u12206050 u12206050 force-pushed the imp/improved-db-queries branch from b1ce469 to dc2020d Compare October 22, 2025 07:11
@u12206050 u12206050 requested a review from a team as a code owner October 22, 2025 07:11
@u12206050 u12206050 force-pushed the imp/improved-db-queries branch from dc2020d to 1186abf Compare October 25, 2025 11:10
@dstockton
Copy link
Contributor

Thanks for your contributions, I'm closing this stale PR. If you believe that's in error and the PR is passing tests, ready for review, please do re-open.

@dstockton dstockton closed this Jan 29, 2026
@u12206050
Copy link
Contributor Author

Last I checked it was passing tests and was ready for review. I am
Unable to open it again except for making a new one.
It is waiting on the directus team to review.

Has been working flawlessly in production for us the past 4months.

@dstockton dstockton reopened this Jan 30, 2026
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.

slow queries on roles with multiple related permissions

2 participants