{"record":{"id":"4e422fbaff4ba40e","repo":"dgraph-io/dgraph","slug":"length-of-facetsmatrix-and-uidmatrix-mismatch-d","errorCode":null,"errorMessage":"Length of facetsMatrix and uidMatrix mismatch: %d vs %d","messagePattern":"Length of facetsMatrix and uidMatrix mismatch: (.+?) vs (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/outputnode.go","lineNumber":1380,"sourceCode":"\t\tif pc.IsInternal() {\n\t\t\tif pc.Params.Expand != \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif pc.Params.Normalize && pc.Params.Alias == \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif err := pc.addInternalNode(enc, uid, dst); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tif len(pc.uidMatrix) == 0 {\n\t\t\t// Can happen in recurse query.\n\t\t\tcontinue\n\t\t}\n\t\tif len(pc.facetsMatrix) > 0 && len(pc.facetsMatrix) != len(pc.uidMatrix) {\n\t\t\treturn errors.Errorf(\"Length of facetsMatrix and uidMatrix mismatch: %d vs %d\",\n\t\t\t\tlen(pc.facetsMatrix), len(pc.uidMatrix))\n\t\t}\n\n\t\tidx := algo.IndexOf(pc.SrcUIDs, uid)\n\t\tif idx < 0 {\n\t\t\tcontinue\n\t\t}\n\t\tif pc.Params.IsGroupBy {\n\t\t\tif len(pc.GroupbyRes) <= idx {\n\t\t\t\treturn errors.Errorf(\"Unexpected length while adding Groupby. Idx: [%v], len: [%v]\",\n\t\t\t\t\tidx, len(pc.GroupbyRes))\n\t\t\t}\n\t\t\tif err := pc.addGroupby(enc, dst, pc.GroupbyRes[idx], pc.fieldName()); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n","sourceCodeStart":1362,"sourceCodeEnd":1398,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/outputnode.go#L1362-L1398","documentation":"While converting query output to RDF (toRDF/preTraverse), each UID in the path must have matching entries in both uidMatrix and facetsMatrix. A non-empty facetsMatrix whose length differs from uidMatrix indicates internal state corruption or a code path that populated facets without corresponding UID rows.","triggerScenarios":"A facets query path where facetsMatrix was appended but uidMatrix skipped/shortened (the source notes it can happen in recurse queries when len(uidMatrix)==0 is skipped but partial mismatch remains), passed to rdf conversion at outputnode.go:1380.","commonSituations":"Recurse queries with facets; bugs in specific Dgraph versions' facet handling; mixing facets on reverse edges where the matrix population diverges.","solutions":["Upgrade Dgraph — several facet/recurse matrix mismatches were fixed in later releases","Remove or isolate the facet portion of the query to confirm it triggers the mismatch, then report with repro","Restructure: fetch facets in a separate simpler query without recurse","If programmatically building the SubGraph, ensure facetsMatrix rows are appended 1:1 with uidMatrix rows"],"exampleFix":"// before\n{\n  q(func: uid(0x1)) @recurse {\n    friend @facets\n  }\n}\n// after (workaround)\n{\n  q(func: uid(0x1)) {\n    friend @facets\n  }\n}","handlingStrategy":"try-catch","validationCode":"// avoid the trigger: don't request facets on recurse paths\nif (/@recurse/.test(q) && /@facets/.test(q)) throw new Error('facets with recurse unsupported; split query');","typeGuard":null,"tryCatchPattern":"try {\n  return await dgraph.query(q);\n} catch (e) {\n  if (String(e).includes('facetsMatrix and uidMatrix mismatch')) {\n    return await dgraph.query(stripFacets(q)); // retry without @facets\n  }\n  throw e;\n}","preventionTips":["Don't combine @recurse with @facets on known-affected versions","Upgrade Dgraph; several facet matrix bugs were fixed in later releases","Fetch facets in a separate non-recursive query keyed by uid","Report repros: mismatch indicates internal state inconsistency"],"tags":["dgraph","facets","recurse","internal-state"],"backgroundTag":"facets-matrix-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}