{"record":{"id":"9a4e264347bc7dc9","repo":"clockworklabs/SpacetimeDB","slug":"error-table-s-not-found-for-multi-column-index","errorCode":null,"errorMessage":"ERROR: Table '%s' not found for multi-column index '%s'\n","messagePattern":"ERROR: Table '(.+?)' not found for multi-column index '(.+?)'\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bindings-cpp/include/spacetimedb/internal/v9_builder.h","lineNumber":534,"sourceCode":"        table->sequences.push_back(std::move(seq_def));\n        \n        //fprintf(stdout, \"DEBUG: Added AutoInc sequence for %s.%s\\n\", \n        //        table_name.c_str(), field_name.c_str());\n    }\n}\n\n// Template implementation for AddMultiColumnIndex\ntemplate<typename T>\nvoid V9Builder::AddMultiColumnIndex(const std::string& table_name,\n                                    const std::string& index_name,\n                                    const std::vector<std::string>& field_names) {\n    //fprintf(stdout, \"DEBUG: Adding multi-column index '%s' to table '%s' with %zu fields\\n\", \n    //        index_name.c_str(), table_name.c_str(), field_names.size());\n    \n    // Find the existing table\n    RawTableDefV9* table = findTableByName(table_name);\n    if (!table) {\n        fprintf(stderr, \"ERROR: Table '%s' not found for multi-column index '%s'\\n\",\n                table_name.c_str(), index_name.c_str());\n        return;\n    }\n    \n    // Get field descriptors to find the field index\n    SpacetimeDB::field_registrar<T>::register_fields();\n    auto& descriptor_map = SpacetimeDB::get_table_descriptors();\n    auto it = descriptor_map.find(&typeid(T));\n    if (it == descriptor_map.end()) {\n        fprintf(stderr, \"ERROR: No field descriptors found for table %s\\n\", table_name.c_str());\n        return;\n    }\n    \n    const auto& field_descs = it->second.fields;\n    std::vector<uint16_t> field_indexes;\n    \n    // Find field indices for each field name\n    for (const std::string& field_name : field_names) {","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-cpp/include/spacetimedb/internal/v9_builder.h#L516-L552","documentation":"V9Builder::AddMultiColumnIndex first resolves the target table by name via findTableByName; when no registered RawTableDefV9 has that exact name, it prints this error and returns, so the composite btree index is never created. The module still publishes — the performance/lookup characteristics are simply missing, which usually surfaces later as full-table scans.","triggerScenarios":"The multi-column index annotation names a table that is not registered under that exact string: typo or casing mismatch versus the table macro, registration ordering across translation units (index macro instantiated before the table macro's static object), or a table rename that missed the index annotation.","commonSituations":"Renaming tables during a schema refactor; keeping index declarations in a separate file that initializes first; copy-pasting index macros between modules; mixing v9-style and v10-style macros so the table lands in a different builder.","solutions":["Make the table name string in the multi-index annotation byte-identical to the table macro's name (case-sensitive)","Keep the table registration and its multi-column index in the same translation unit to avoid static-init ordering problems","Search the module for duplicate/overwriting table registrations of the same name","After republishing, inspect the table's index list to confirm the composite index exists"],"exampleFix":"// before\nST_TABLE(messages, ...);\nST_MULTI_INDEX(msgs, by_sender_room, sender_id, room_id);  // wrong table name\n// after\nST_MULTI_INDEX(messages, by_sender_room, sender_id, room_id);","handlingStrategy":"validation","validationCode":"#include <spacetimedb/internal/v9_builder.h>\nbool TableIsRegistered(const std::string& name) {\n    for (const auto& t : SpacetimeDB::Internal::GetV9Module().tables)\n        if (t.name == name) return true;\n    return false;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define multi-index annotations adjacent to the table macro with the same name token","After renames, grep all index annotations for the old table name","Verify the composite index exists in the published schema, not just that the module built"],"tags":["spacetimedb","cpp","schema","multi-column-index","table-not-found","v9-builder"],"backgroundTag":"schema-table-not-found","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}