France-ioi / AlgoreaBackend

Backend for the new Algorea platform
MIT License
1 stars 2 forks source link

Speed up slow query `start-result-path`. #1074

Closed GeoffreyHuck closed 2 months ago

GeoffreyHuck commented 2 months ago

We check the permissions before instead of inside the big query.

The use of WITH... to check the permissions made the whole query slow. This is weird because the query to check the permissions itself is very fast, but it looks it messes with the optimizer in some way.

Another problem appeared as the query got very big (8 items in the path), it would spend a lot of time in state=statistics. Removing the WITH... altogether before fixes it (probably the algorithm to determine the order to do the JOINs gets very slow when there are many JOINs + WITH).

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (9c1b170) to head (eaf2596).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1074 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 236 236 Lines 14311 14318 +7 ========================================= + Hits 14311 14318 +7 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.