{"record":{"id":"02a8b2c3c17d1310","repo":"risingwavelabs/risingwave","slug":"inequal-condition-from-the-same-side-should-be-pus","errorCode":null,"errorMessage":"inequal condition from the same side should be push down in optimizer","messagePattern":"inequal condition from the same side should be push down in optimizer","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/frontend/src/optimizer/plan_node/logical_join.rs","lineNumber":1581,"sourceCode":"        let batch_join = BatchHashJoin::new(logical_join, asof_desc);\n        Ok(batch_join.into())\n    }\n\n    pub fn get_inequality_desc_from_predicate(\n        predicate: Condition,\n        left_input_len: usize,\n    ) -> Result<AsOfJoinDesc> {\n        let expr: ExprImpl = predicate.into();\n        if let Some((left_input_ref, expr_type, right_input_ref)) = expr.as_comparison_cond() {\n            if left_input_ref.index() < left_input_len && right_input_ref.index() >= left_input_len\n            {\n                Ok(AsOfJoinDesc {\n                    left_idx: left_input_ref.index() as u32,\n                    right_idx: (right_input_ref.index() - left_input_len) as u32,\n                    inequality_type: Self::expr_type_to_comparison_type(expr_type)?.into(),\n                })\n            } else {\n                bail!(\"inequal condition from the same side should be push down in optimizer\");\n            }\n        } else {\n            Err(ErrorCode::InvalidInputSyntax(\n                \"AsOf join requires exactly 1 ineuquality condition\".to_owned(),\n            )\n            .into())\n        }\n    }\n\n    fn expr_type_to_comparison_type(expr_type: PbType) -> Result<PbAsOfJoinInequalityType> {\n        match expr_type {\n            PbType::LessThan => Ok(PbAsOfJoinInequalityType::AsOfInequalityTypeLt),\n            PbType::LessThanOrEqual => Ok(PbAsOfJoinInequalityType::AsOfInequalityTypeLe),\n            PbType::GreaterThan => Ok(PbAsOfJoinInequalityType::AsOfInequalityTypeGt),\n            PbType::GreaterThanOrEqual => Ok(PbAsOfJoinInequalityType::AsOfInequalityTypeGe),\n            _ => Err(ErrorCode::InvalidInputSyntax(format!(\n                \"Invalid comparison type: {}\",\n                expr_type.as_str_name()","sourceCodeStart":1563,"sourceCodeEnd":1599,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/optimizer/plan_node/logical_join.rs#L1563-L1599","documentation":"get_inequality_desc_from_predicate requires the ASOF join's single inequality condition to reference both left and right sides. An inequality whose operands come from the same side should have been pushed down earlier; encountering one here is rejected with bail! (an error, returned to the caller).","triggerScenarios":"ASOF join whose OTHER condition contains a comparison between two columns of the same input side (e.g. `t1.a < t1.b`) instead of a left-right inequality like `t1.ts <= t2.ts`.","commonSituations":"Users writing ASOF joins with extra same-side predicates in ON; frontend pushdown rules failing to remove them before stream conversion.","solutions":["Move same-side predicates out of the ON clause into a WHERE clause or a subquery filter","Ensure predicate pushdown runs before asof join stream conversion","Keep exactly one left-vs-right inequality condition in the ASOF ON clause","Check the query contains only the required one inequality (error otherwise: 'requires exactly 1 ineuquality condition')"],"exampleFix":"-- before\nSELECT * FROM t ASOF JOIN d ON t.id = d.id AND t.ts <= d.ts AND t.x < t.y;\n-- after\nSELECT * FROM (SELECT * FROM t WHERE x < y) t\nASOF JOIN d ON t.id = d.id AND t.ts <= d.ts;","handlingStrategy":"validation","validationCode":"// before creating an ASOF join, ensure the ON clause has exactly one cross-side inequality and no same-side predicates:\n// same-side comparisons belong in WHERE","typeGuard":null,"tryCatchPattern":"match asof_conversion_result { Err(e) if e.to_string().contains(\"same side\") => rewrite_query_with_where_filter(), ... }","preventionTips":["Put same-side predicates in WHERE, not ON","Keep exactly one left-vs-right inequality in ASOF ON","Run predicate pushdown before ASOF stream conversion"],"tags":["asof-join","optimizer","predicate-pushdown","streaming"],"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"}