{"record":{"id":"06ef5146ca894e3b","repo":"dgraph-io/dgraph","slug":"exceeded-query-edge-limit-v-found-v-edges-06ef51","errorCode":null,"errorMessage":"Exceeded query edge limit = %v. Found %v edges.","messagePattern":"Exceeded query edge limit = (.+?)\\. Found (.+?) edges\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/shortest.go","lineNumber":233,"sourceCode":"\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// TODO - This simplify overrides the adjacency matrix. What happens if the\n\t\t\t\t\t\t// cost along the second attribute is more than that along the first.\n\t\t\t\t\t\tadjacencyMap[fromUID][toUID] = mapItem{\n\t\t\t\t\t\t\tcost:  cost,\n\t\t\t\t\t\t\tfacet: facet,\n\t\t\t\t\t\t\tattr:  subgraph.Attr,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnumEdges++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif numEdges > x.Config.LimitQueryEdge {\n\t\t\t// If we've seen too many edges, stop the query.\n\t\t\trch <- errors.Errorf(\"Exceeded query edge limit = %v. Found %v edges.\",\n\t\t\t\tx.Config.LimitMutationsNquad, numEdges)\n\t\t\treturn\n\t\t}\n\n\t\t// modify the exec and attach child nodes.\n\t\tvar out []*SubGraph\n\t\tfor _, subgraph := range exec {\n\t\t\tif len(subgraph.DestUIDs.Uids) == 0 {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\trch <- ctx.Err()\n\t\t\t\treturn\n\t\t\tdefault:\n\t\t\t\tfor _, child := range sg.Children {\n\t\t\t\t\ttemp := new(SubGraph)\n\t\t\t\t\ttemp.copyFiltersRecurse(child)","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/shortest.go#L215-L251","documentation":"Dgraph's shortest-path / k-shortest-path query walks edges breadth-first and aborts once the number of traversed edges exceeds the query edge limit (Config.LimitQueryEdge), a safety cap preventing unbounded graph exploration from exhausting memory/CPU. Note the message reports the mutated-nquads config value (LimitMutationsNquad) instead of LimitQueryEdge — a known cosmetic bug — but the enforced limit is the edge limit. The query is cancelled and this error returned to the client.","triggerScenarios":"Running a shortest/k-shortest path query (from/to with a `shortest` block) whose exploration touches more edges than allowed by the --query_edge limit (LimitQueryEdge in Config), e.g. a broad graph expansion before the destination is found.","commonSituations":"Shortest-path queries over highly connected graphs (social graphs, massive fan-out at intermediate hops); default or reduced --query_edge limits in production; a typo'd or very distant `to` node causing wide traversal; running with graph_path/limit directives that expand many edges per hop.","solutions":["Reduce traversal breadth: use `limit` / stronger predicates in the `from`/`to` blocks and on intermediate hops so fewer edges are expanded.","Raise the server limit: increase --query_edge (LimitQueryEdge) in Dgraph's configuration and restart Alpha.","Narrow the query: pin down intermediate nodes or use n-depth paths to constrain the search space.","Split the query: run the shortest path between closer endpoints or compute in stages in application code."],"exampleFix":"// before (DQL)\n{ q(func: uid(0x1)) { shortest(to: uid(0x2)) { friend } } }\n// after: constrain expansion\n{ q(func: uid(0x1)) {\n    shortest(to: uid(0x2), numpaths: 1) {\n      friend @filter(gt(since, \"2020-01-01\"))\n    }\n  }\n}","handlingStrategy":"validation","validationCode":"// Before issuing a shortest-path query, estimate breadth and cap hops\nconst q = `{ q(func: uid(${from})) { shortest(to: uid(${to}), depth: ${depth}) { friend } } }`;\nif (depth > 5) throw new Error('depth too large for query_edge limit');\nawait dgraph.NewTxn().Query(ctx, q);","typeGuard":null,"tryCatchPattern":"try {\n  await txn.Query(ctx, shortestPathQuery);\n} catch (e) {\n  if (String(e).includes('Exceeded query edge limit')) {\n    // retry with tighter filters/lower depth or raise --query_edge\n  }\n  throw e;\n}","preventionTips":["Add @filter and limit clauses inside shortest-path blocks to bound expansion","Keep --query_edge sized to your graph's fan-out; monitor for this error as a capacity signal","Prefer numpaths: 1 unless k paths are truly needed","Split long-range path queries into staged hops"],"tags":["dgraph","query-limits","shortest-path","configuration"],"backgroundTag":"query-edge-limit-exceeded","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}