Skip to content

fix(core): Add maxfrontiersize to shortest path query #9382

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 8 commits into from
Apr 23, 2025

Conversation

harshil-goel
Copy link
Contributor

@harshil-goel harshil-goel commented Apr 15, 2025

Currently we use dijkstra's algorithm to find shortest path. Sometimes the heap could grow indefinitely, which would slow down the query significantly and cause dgraph to go out of memory. This would only happen in very specific instances depending upon the graph. To fix this, we are introducing a new argument, maxfrontiersize in shortest path query. This would limit the size of the heap fixing the issue.
New query would look like:

{ 
  path as shortest(from: 0x2, to: 0x5, numpaths:5, maxfrontiersize: 10000) {
  connected_to
    @facets(weight)
 }

Fixes: #9333

@harshil-goel harshil-goel requested a review from a team as a code owner April 15, 2025 09:55
@github-actions github-actions bot added area/testing Testing related issues area/querylang Issues related to the query language specification and implementation. area/core internal mechanisms go Pull requests that update Go code labels Apr 15, 2025
Copy link
Member

@mangalaman93 mangalaman93 left a comment

Choose a reason for hiding this comment

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

Please add a test for this change

Copy link

trunk-io bot commented Apr 15, 2025

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@matthewmcneely
Copy link
Member

@harshil-goel Is "heap" the best term for this? Is it the max number of nodes to be considered? Maybe "maxnodes"?

@harshil-goel
Copy link
Contributor Author

@mangalaman93 @matthewmcneely What term do you think works well:
maxFrontierSize - "Frontier" is a common term in graph search for the set of nodes to be explored next
pathExplorationLimit - Describes the purpose rather than the implementation
maxCandidatePaths - Indicates you're limiting the number of candidate paths under consideration

@matthewmcneely
Copy link
Member

I like "frontier size", that lines up nicely with terminology that I've encountered over the years.

@harshil-goel harshil-goel changed the title fix(core): Add maxheapsize to shortest path query fix(core): Add maxfrontiersize to shortest path query Apr 22, 2025
@harshil-goel harshil-goel force-pushed the harshil-goel/fix-kshort branch from d1d123e to 2c27f2e Compare April 22, 2025 12:43
@harshil-goel harshil-goel force-pushed the harshil-goel/fix-kshort branch from 2c27f2e to 1f23a30 Compare April 23, 2025 05:33
@mangalaman93 mangalaman93 enabled auto-merge (squash) April 23, 2025 06:52
@mangalaman93 mangalaman93 merged commit aeb48ae into main Apr 23, 2025
13 checks passed
@mangalaman93 mangalaman93 deleted the harshil-goel/fix-kshort branch April 23, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core internal mechanisms area/querylang Issues related to the query language specification and implementation. area/testing Testing related issues go Pull requests that update Go code
Development

Successfully merging this pull request may close these issues.

Possible Memoryleak with k shortest path
3 participants