{"record":{"id":"dace6974422b2dbf","repo":"risingwavelabs/risingwave","slug":"different-number-of-internal-tables-new-old","errorCode":null,"errorMessage":"Different number of internal tables. New: {}, Old: {}","messagePattern":"Different number of internal tables\\. New: (.+?), Old: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/src/stream/stream_graph/fragment.rs","lineNumber":1083,"sourceCode":"            );\n        }\n    }\n\n    /// Use a trivial algorithm to match the internal tables of the new graph for\n    /// `ALTER TABLE` or `ALTER SOURCE`.\n    pub fn fit_internal_tables_trivial(\n        &mut self,\n        mut old_internal_tables: Vec<Table>,\n    ) -> MetaResult<()> {\n        let mut new_internal_table_ids = Vec::new();\n        for fragment in self.fragments.values() {\n            for table in &fragment.extract_internal_tables() {\n                new_internal_table_ids.push(table.id);\n            }\n        }\n\n        if new_internal_table_ids.len() != old_internal_tables.len() {\n            bail!(\n                \"Different number of internal tables. New: {}, Old: {}\",\n                new_internal_table_ids.len(),\n                old_internal_tables.len()\n            );\n        }\n        old_internal_tables.sort_by_key(|t| t.id);\n        new_internal_table_ids.sort();\n\n        let internal_table_id_map = new_internal_table_ids\n            .into_iter()\n            .zip_eq_fast(old_internal_tables.into_iter())\n            .collect::<HashMap<_, _>>();\n\n        // TODO(alter-mv): unify this with `fit_internal_table_ids_with_mapping` after we\n        // confirm the behavior is the same.\n        for fragment in self.fragments.values_mut() {\n            stream_graph_visitor::visit_internal_tables(\n                &mut fragment.inner,","sourceCodeStart":1065,"sourceCodeEnd":1101,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/meta/src/stream/stream_graph/fragment.rs#L1065-L1101","documentation":"`fit_internal_tables_trivial` maps the new graph's internal tables onto the old job's internal tables by position after sorting by id. The trivial algorithm requires the ALTER to preserve the number of internal tables exactly; if the new graph needs a different count (e.g. a new column changed the plan and added/removed a state table), it refuses to fit them and fails the ALTER.","triggerScenarios":"ALTER TABLE/ALTER SOURCE (via build_replace_job) where the rewritten graph's `extract_internal_tables()` count differs from the old job's internal table list — e.g. adding a column changes the plan such that an extra hash-agg/join state table is required.","commonSituations":"Schema change on MVs containing aggregations or joins where the new plan's state tables differ from the old; RisingWave intentionally rejects rather than migrating state tables.","solutions":["Drop and recreate the MV after altering the table instead of relying on in-place schema change.","Check whether the ALTER changes the plan shape (e.g. new column used in a join/agg key) and adjust the statement.","Upgrade RisingWave: newer versions may use mapping-based fitting that tolerates plan changes."],"exampleFix":"-- before\nALTER TABLE t ADD COLUMN c INT; -- MV plan gains an extra internal table -> error\n-- after\nDROP MATERIALIZED VIEW mv;\nALTER TABLE t ADD COLUMN c INT;\nCREATE MV mv AS ...;","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// On this error, fall back to drop-and-recreate of the MV:\n// DROP MATERIALIZED VIEW mv; ALTER TABLE ...; CREATE MATERIALIZED VIEW mv AS ...;","preventionTips":["Avoid ALTER on MVs whose plan shape may change (aggs/joins keyed on altered columns).","Compare internal table counts (old vs new graph) before issuing the ALTER.","Prefer recreating MVs for non-trivial schema changes."],"tags":["meta-service","schema-change","internal-tables","streaming-graph"],"backgroundTag":"invalid-state-transition","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}