Skip to content

feat: Optimize simple queries #3135

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

Merged
merged 5 commits into from
Apr 16, 2024
Merged

Conversation

Arkhas
Copy link
Contributor

@Arkhas Arkhas commented Apr 12, 2024

The issues was for simple queries with complexe wheres, a sub query was used resulting in the following query :

select count(*)
from (select "users".*
      from "users"
      where (select "title"
             from "posts"
             where "posts"."user_id" = "users"."id"
             order by "created_at" asc
    ) = ?
) count_row_table

resulting into an uneccessary temporary table, the query we would like to have would be this one :

select count(*)
from "users"
where (select "title"
       from "posts"
       where "posts"."user_id" = "users"."id"
       order by "created_at" asc
) = ?

On our app, the gains were massive, one of our datables would just timeout and with this change it load now in less than 5 seconds

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@yajra
Copy link
Owner

yajra commented Apr 13, 2024

I guess this PR also fixes #3133. @abdulrhmansouda would you be able to review? Thanks!

@abdulrhmansouda
Copy link

I fixed this problem when I changed the isComplexQuery function #3133.
and it's ready. you can review it.

@yajra
Copy link
Owner

yajra commented Apr 13, 2024

Please run composer pr on your local machine to fix the linting. I haven't figured out yet how to automate in PR. Thanks!

Copy link
Owner

@yajra yajra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good so far.

Please fix the code style using composer pint or composer pr to run all quality tools. It will make the PR easier to review.

Thanks!

@yajra yajra changed the title Optimize simple queries feat: Optimize simple queries Apr 16, 2024
@yajra yajra merged commit 9aa5173 into yajra:master Apr 16, 2024
5 of 7 checks passed
@yajra
Copy link
Owner

yajra commented Apr 16, 2024

Released on v11.1.0, 🚀 thanks!

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

Successfully merging this pull request may close these issues.

3 participants