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

Optimise sub queries #10

Open
kirrg001 opened this issue Dec 5, 2018 · 1 comment
Open

Optimise sub queries #10

kirrg001 opened this issue Dec 5, 2018 · 1 comment
Labels
enhancement New feature or request performance

Comments

@kirrg001
Copy link
Contributor

kirrg001 commented Dec 5, 2018

mongo-knex generates for some cases multiple sub queries in the where clause e.g. for

$and: [{'tags.slug': 'en'}, {'tags.slug': 'de'}]

But there are some cases where we currently generate multiple sub queries, where we don't have to.

This issue should simply collect use cases over time to optimise the performance of the attached queries. I will leave a comment with a use case i discovered in a bit.

Just leave a comment if you discover or want to discuss a case 👍

@kirrg001 kirrg001 added enhancement New feature or request performance labels Dec 5, 2018
@kirrg001
Copy link
Contributor Author

kirrg001 commented Dec 5, 2018

const mongoJSON = {
    'tags.visibility': 'public',
    'tags.slug': {
        $ne: 'classic'
    }
};

(NOTE: ^ $and operator is default)

select * from `posts` 
where 
`posts`.`id` in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`visibility` in ('public')) 
and 
`posts`.`id` not in (select `posts_tags`.`post_id` from `posts_tags` inner join `tags` on `tags`.`id` = `posts_tags`.`tag_id` where `tags`.`slug` in ('classic'))

IMO this case can use one sub query, because we have two different columns (visibility and slug).

@daniellockyer daniellockyer transferred this issue from TryGhost/mongo-knex Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance
Projects
None yet
Development

No branches or pull requests

1 participant