{"record":{"id":"8bb9077a57230c19","repo":"risingwavelabs/risingwave","slug":"table-or-source-specified-in-backfill-order-i","errorCode":null,"errorMessage":"Table or source '{}' specified in backfill_order is not used in the query","messagePattern":"Table or source '(.+?)' specified in backfill_order is not used in the query","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/frontend/src/optimizer/backfill_order_strategy.rs","lineNumber":321,"sourceCode":"    }\n\n    pub(super) fn plan_fixed_strategy(\n        session: &SessionImpl,\n        orders: Vec<(ObjectName, ObjectName)>,\n        plan: StreamPlanRef,\n    ) -> Result<HashMap<RelationId, HashSet<RelationId>>> {\n        // Collect all scanned relation IDs from the plan.\n        let scanned_relation_ids = collect_scanned_relation_ids(session, plan);\n\n        let mut order: HashMap<RelationId, HashSet<RelationId>> = HashMap::new();\n        for (start_name, end_name) in orders {\n            let start_relation_id = bind_backfill_relation_id_by_name(session, start_name.clone())?;\n            let end_relation_id = bind_backfill_relation_id_by_name(session, end_name.clone())?;\n\n            // Validate that both relations are present in the query plan\n            let Some(start_scanned_relation_ids) = scanned_relation_ids.get(&start_relation_id)\n            else {\n                bail!(\n                    \"Table or source '{}' specified in backfill_order is not used in the query\",\n                    start_name\n                );\n            };\n            let Some(end_scanned_relation_ids) = scanned_relation_ids.get(&end_relation_id) else {\n                bail!(\n                    \"Table or source '{}' specified in backfill_order is not used in the query\",\n                    end_name\n                );\n            };\n\n            for start_scanned_relation_id in start_scanned_relation_ids {\n                order\n                    .entry(*start_scanned_relation_id)\n                    .or_default()\n                    .extend(end_scanned_relation_ids.iter().copied());\n            }\n        }","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/optimizer/backfill_order_strategy.rs#L303-L339","documentation":"When building a fixed backfill order, plan_fixed_strategy resolves the `start` relation of each backfill_order pair and validates that its relation id appears among the relation ids actually scanned by the query. If the named table/source is not part of the query plan, creation fails with this error.","triggerScenarios":"Creating a materialized view with a backfill_order option whose start (or end) table/source name does not correspond to any relation referenced by the MV query.","commonSituations":"Copy-pasted backfill_order clauses from another MV, renamed or dropped tables, listing intermediate tables that the planner optimized away, or referencing a source that the query no longer reads.","solutions":["Check every name in backfill_order against the tables/sources actually used in the MV query.","Remove or fix the unused relation in the backfill_order clause.","If the table was intentionally removed from the query, update backfill_order to reference only present relations.","Re-check table names for typos and exact case."],"exampleFix":"// before\nCREATE MATERIALIZED VIEW mv AS SELECT ... FROM t1 JOIN t2\nWITH (backfill_order = 't3 -> t1');\n// after\nCREATE MATERIALIZED VIEW mv AS SELECT ... FROM t1 JOIN t2\nWITH (backfill_order = 't1 -> t2');","handlingStrategy":"validation","validationCode":"-- confirm the start relation appears in the MV query before creating\nSELECT * FROM rw_catalog.rw_tables WHERE name = 't1';\n-- and ensure t1 is referenced in the CREATE MATERIALIZED VIEW statement","typeGuard":null,"tryCatchPattern":"match create_mv_result {\n    Err(e) if e.to_string().contains(\"specified in backfill_order is not used\") => {\n        eprintln!(\"Fix backfill_order: reference only relations in the query\");\n    }\n    other => other?,\n}","preventionTips":["Derive backfill_order from the tables actually listed in the query's FROM/JOIN clauses.","Keep query text and backfill_order in the same migration/PR so they change together.","Test MV creation on a dev cluster before production DDL."],"tags":["sql","materialized-view","backfill","validation"],"backgroundTag":"invalid-argument-value","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"}