{"record":{"id":"ff2aee5766ce0ce3","repo":"NationalSecurityAgency/ghidra","slug":"bad-vector-table-rowid-ff2aee","errorCode":null,"errorMessage":"Bad vector table rowid","messagePattern":"Bad vector table rowid","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2VectorTable.java","lineNumber":159,"sourceCode":"\t/**\n\t * Get vector details which correspond to specified vector ID\n\t * @param id vector ID\n\t * @return vector details\n\t * @throws SQLException if error occurs\n\t */\n\tpublic VectorResult queryVectorById(long id) throws SQLException {\n\n\t\tVectorStoreEntry entry = vectorStore.getVectorById(id);\n\t\tif (entry != null) {\n\t\t\treturn new VectorResult(id, entry.count(), 0, 0, entry.vec());\n\t\t}\n\n\t\tPreparedStatement s = select_by_rowid_stmt.prepareIfNeeded(\n\t\t\t() -> db.prepareStatement(\"SELECT id,count,vec FROM \" + TABLE_NAME + \" WHERE id = ?\"));\n\t\ts.setLong(1, id);\n\t\ttry (ResultSet rs = s.executeQuery()) {\n\t\t\tif (!rs.next()) {\n\t\t\t\tthrow new SQLException(\"Bad vector table rowid\");\n\t\t\t}\n\t\t\tchar[] vectorDecodeBuffer = Base64VectorFactory.allocateBuffer();\n\t\t\tVectorResult rowres;\n\t\t\ttry {\n\t\t\t\trowres = new VectorResult();\n\t\t\t\trowres.vectorid = rs.getLong(1);\n\t\t\t\trowres.hitcount = rs.getInt(2);\n\t\t\t\tReader r = new StringReader(rs.getString(3));\n\t\t\t\trowres.vec = vectorFactory.restoreVectorFromBase64(r, vectorDecodeBuffer);\n\t\t\t}\n\t\t\tcatch (final IOException e) {\n\t\t\t\tthrow new SQLException(e.getMessage()); // unexpected for StringReader\n\t\t\t}\n\t\t\treturn rowres;\n\t\t}\n\t}\n\n\t/**","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2VectorTable.java#L141-L177","documentation":"Thrown as an SQLException by H2VectorTable.queryVectorById() when a SELECT by rowid returns no rows. The method first checks the in-memory vectorStore cache; if not found, it queries the database. If the database also has no row with the given id, it throws this error. This means the vector ID does not exist in either the cache or the table.","triggerScenarios":"Occurs when queryVectorById(id) is called with an ID that has no matching row in h2_vectable AND is not in the vectorStore cache. This happens when: the ID is from a stale reference (vector was deleted), the ID was never inserted, or there is a data integrity gap between the description/metadata tables and the vector table.","commonSituations":"A function description references a vector ID that was deleted. Concurrent deletion of vectors while querying. Database migration that updated metadata but not vectors. Using an ID obtained from a different database instance.","solutions":["Verify the vector ID exists by calling readVectorMap() and checking membership.","Check for concurrent modifications — ensure no process is deleting vectors during the query.","If the ID references a deleted vector, update or remove the orphaned reference in the metadata/description tables.","Rebuild the database if widespread data integrity issues are found."],"exampleFix":"// before\nVectorResult res = vectorTable.queryVectorById(id); // throws\n\n// after\nMap<Long, VectorStoreEntry> valid = vectorTable.readVectors();\nif (!valid.containsKey(id)) {\n    Msg.warn(this, \"Vector ID \" + id + \" not found; skipping\");\n    return null;\n}\nVectorResult res = vectorTable.queryVectorById(id);","handlingStrategy":"validation","validationCode":"// Verify vector ID exists in cache or table before querying\nif (vectorStore.getVectorById(id) == null) {\n    try (PreparedStatement s = db.prepareStatement(\n            \"SELECT 1 FROM \" + TABLE_NAME + \" WHERE id = ?\")) {\n        s.setLong(1, id);\n        try (ResultSet rs = s.executeQuery()) {\n            if (!rs.next()) {\n                throw new IllegalArgumentException(\n                    \"Vector ID \" + id + \" does not exist\");\n            }\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return vectorTable.queryVectorById(id);\n} catch (SQLException e) {\n    if (e.getMessage().equals(\"Bad vector table rowid\")) {\n        // Vector doesn't exist; return null or handle gracefully\n        return null;\n    }\n    throw e;\n}","preventionTips":["Validate vector IDs against readVectorMap() before querying when IDs may be stale.","Ensure no concurrent deletions occur during queries.","Use transactions or connection isolation if multi-threaded access is required.","Treat repeated 'Bad vector table rowid' errors as a data integrity red flag."],"tags":["bsim","h2","vector","not-found","data-integrity"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}