-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Over-aggressive optimisation can lead to generating non-optimal query…
… plans (#2623) When there is multiple valid choices for multiple paths of a query, the number of theoretically possible ends up a cartesian product so it explodes fairly quickly, and generating too many plans can be very costly. To manage this in general, we generate the possible plans incrementally and in an order that is likely to yield "good" plans early, and use the cost of previously computed plan to possibly cut early further computation. The code doing this was however not optimal as we weren't using that potential of early exit as aggressively as we could. This commit fixes that. Further, when building plans, after we've computed all the possible options to get to a particular leaf of the query being plan, we're applying an heuristic that checks if an option is guaranteed to be always better than another one (and remove the latter one if so), which the goal of reducing the number of actual full plan we need to evaluate. But the implementation of that heuristic was incorrect: while it was correctly removing options that we did meant to remove, it was also sometimes removing options that really should be kept. This resulted in planning sometimes not produce the most optimal possible plan. This commit fixes that heuristic to only exclude what can be safely excluded.
- Loading branch information
Sylvain Lebresne
authored
Jun 13, 2023
1 parent
3299d52
commit 2a97f37
Showing
5 changed files
with
447 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@apollo/query-planner": patch | ||
"@apollo/query-graphs": patch | ||
--- | ||
|
||
Fix query planner heuristic that could lead to ignoring some valid option and yielding a non-optimal query plan. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.