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

fix: select join with subqueries should not tamper the subquery itself #138

Merged
merged 1 commit into from
Jul 15, 2021

Conversation

cyjake
Copy link
Owner

@cyjake cyjake commented Jul 15, 2021

Leoric tries to optimize join queries that have offset or limit by putting them into a subquery. If the subquery itself contains another Spell as subquery, such as:

Post
  .where({
    isPrivate: true,
    authorId: User.where({ stauts: 1 }),
  })
  .with('author')
  .limit(10);

will be formatted into following SQL:

SELECT posts.*, users.* 
  FROM (SELECT * FROM users WHERE is_private = 1 AND author_id IN (...) LIMIT 10);

This optimization should not tamp the subquery User.where({ status: 1 }) passed to Post.where({}.

@JimmyDaddy JimmyDaddy merged commit 7739011 into master Jul 15, 2021
@cyjake cyjake deleted the fix-subspell-pollution branch July 15, 2021 17:36
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