{"record":{"id":"b37ac600ac92cadc","repo":"dgraph-io/dgraph","slug":"exceeded-query-edge-limit-v-found-v-edges","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/recurse.go","lineNumber":156,"sourceCode":"\t\t// modify the exec and attach child nodes.\n\t\tvar out []*SubGraph\n\t\tvar exp []*SubGraph\n\t\tfor _, sg := range exec {\n\t\t\tif sg.UnknownAttr {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif len(sg.DestUIDs.Uids) == 0 {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif exp, err = expandChildren(ctx, sg, startChildren); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tout = append(out, exp...)\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\treturn errors.Errorf(\"Exceeded query edge limit = %v. Found %v edges.\",\n\t\t\t\tx.Config.LimitQueryEdge, numEdges)\n\t\t}\n\n\t\tif len(out) == 0 {\n\t\t\treturn nil\n\t\t}\n\t\texec = out\n\t}\n}\n\n// expandChildren adds child nodes to a SubGraph with no children, expanding them if necessary.\nfunc expandChildren(ctx context.Context, sg *SubGraph, children []*SubGraph) ([]*SubGraph, error) {\n\tif len(sg.Children) > 0 {\n\t\treturn nil, errors.New(\"Subgraph should not have any children\")\n\t}\n\t// Add children and expand if necessary\n\tsg.Children = append(sg.Children, children...)\n\texpandedChildren, err := expandSubgraph(ctx, sg)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/recurse.go#L138-L174","documentation":"Recurse queries expand outward from root nodes up to a depth. If the total number of edges traversed exceeds x.Config.LimitQueryEdge (default 1,000,000), Dgraph aborts the query to protect the server. It is a resource-protection limit, not a data error.","triggerScenarios":"A recurse { ... } query whose traversal touches more edges than the limit-query-edge config: starting from high-degree root nodes, deep recursion without a depth bound, or large datasets with dense connectivity.","commonSituations":"Running recurse from a node with thousands of neighbors, forgetting to set depth: N on huge graphs, defaults changed in self-hosted configs, or per-node limits (query-edge limit) set lower than dataset size.","solutions":["Bound the recursion with an explicit depth, e.g. recurse(depth: 3)","Narrow the root set with a filter/root function to reduce starting nodes","Raise the limit in server config (limit{\"query-edge\": N}) if the server can afford more memory","Restructure the query: use shortest-path or specific predicates instead of full expand-all (_all_directives or expand(_all_))"],"exampleFix":"// before: unbounded recurse over everything\n{\n  me(func: eq(name, \"alice\")) @recurse {\n    expand(_all_)\n  }\n}\n// after: bounded depth and selected predicates\n{\n  me(func: eq(name, \"alice\")) @recurse(depth: 3) {\n    friend\n    name\n  }\n}","handlingStrategy":"validation","validationCode":"// Compute expected traversal size before running recurse\nmaxDepth := 3\nif estimateEdgesFromRoot(rootUIDs, maxDepth) > 1_000_000 {\n    return errors.New(\"recurse would exceed query-edge limit; add depth bound or filter\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := txn.Query(ctx, dql)\nif err != nil && strings.Contains(err.Error(), \"Exceeded query edge limit\") {\n    // retry with reduced depth or narrowed root set\n    dql = reduceDepth(dql)\n    resp, err = txn.Query(ctx, dql)\n}","preventionTips":["Always specify an explicit depth on @recurse for large graphs","Filter the root set before recursing","Tune limit{\"query-edge\"} to match your dataset and memory budget","Prefer expand of named predicates over expand(_all_)"],"tags":["recurse","limits","resource-protection","dgraph"],"backgroundTag":"query-limit-exceeded","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}