diff --git a/src/sql/code_generator/ob_code_generator_impl.cpp b/src/sql/code_generator/ob_code_generator_impl.cpp index 22d26d091157b7e7a4335ec6f53b10a97e981723..1bf49516b9efc3e197eee42c8a393205f61cef3d 100644 --- a/src/sql/code_generator/ob_code_generator_impl.cpp +++ b/src/sql/code_generator/ob_code_generator_impl.cpp @@ -9170,16 +9170,17 @@ int ObCodeGeneratorImpl::get_cell_idx( if (OB_ISNULL(raw_expr)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("Get unexpected null", K(ret)); - } else if (!raw_expr->has_flag(IS_COLUMNLIZED)) { - if (raw_expr->has_flag(IS_CONST) || raw_expr->has_flag(IS_CONST_EXPR)) { - skip = true; - } else { + } else if (raw_expr->has_flag(IS_CONST) || raw_expr->has_flag(IS_CONST_EXPR)) { + skip = true; + LOG_TRACE("skip const expr", K(*raw_expr), K(cell_idx)); + } + if (OB_SUCC(ret) && !skip) { + if (!raw_expr->has_flag(IS_COLUMNLIZED)) { ret = OB_ERR_UNEXPECTED; LOG_ERROR("param expr should have be columnlized", K(*raw_expr)); + } else if (OB_FAIL(idx_provider.get_idx(raw_expr, cell_idx))) { + LOG_ERROR("partition by expr should have be columnlized", K(ret), K(*raw_expr)); } - } else if (OB_FAIL(idx_provider.get_idx(raw_expr, cell_idx))) { - LOG_ERROR("partition by expr should have be columnlized", K(ret), K(*raw_expr)); - } else { /* do nothing. */ } return ret; } diff --git a/src/sql/code_generator/ob_expr_generator_impl.cpp b/src/sql/code_generator/ob_expr_generator_impl.cpp index c960846f0b48d63510cb35e99abb238f768c8fb9..88285eb58184c998c21493b43eee586863369435 100644 --- a/src/sql/code_generator/ob_expr_generator_impl.cpp +++ b/src/sql/code_generator/ob_expr_generator_impl.cpp @@ -119,7 +119,7 @@ int ObExprGeneratorImpl::generate_infix_expr(ObRawExpr& raw_expr) sql_expr_->start_gen_infix_exr(); auto& exprs = sql_expr_->get_infix_expr().get_exprs(); if (OB_FAIL(raw_expr.do_visit(*this))) { - LOG_WARN("expr visit failed", K(ret)); + LOG_WARN("expr visit failed", K(ret), K(raw_expr)); } else if (exprs.count() > 1) { ret = OB_ERR_UNEXPECTED; LOG_WARN("should add one expr per visit", K(ret), K(raw_expr)); @@ -1299,6 +1299,7 @@ int ObExprGeneratorImpl::visit(ObCaseOpRawExpr& expr) { int ret = OB_SUCCESS; ObPostExprItem item; + bool need_calc = true; item.set_accuracy(expr.get_accuracy()); if (OB_ISNULL(sql_expr_)) { ret = OB_ERR_UNEXPECTED; @@ -1306,14 +1307,26 @@ int ObExprGeneratorImpl::visit(ObCaseOpRawExpr& expr) } else if (expr.has_flag(IS_COLUMNLIZED)) { int64_t idx = OB_INVALID_INDEX; if (OB_FAIL(column_idx_provider_.get_idx(&expr, idx))) { - LOG_WARN("get index failed", K(ret)); + // if an expr has been marked with IS_COLUMNLIZED but get invalid idx, + // then it most likely be a const shared expr and need to calculate again + if (ret == OB_ENTRY_NOT_EXIST && idx == OB_INVALID_INDEX && + (expr.has_flag(IS_CONST) || expr.has_flag(IS_CONST_EXPR))) { + ret = OB_SUCCESS; + expr.clear_flag(IS_COLUMNLIZED); + LOG_TRACE("need to recalculate const expr", K(expr)); + } else if (ret != OB_ENTRY_NOT_EXIST) { + LOG_WARN("get index failed", K(ret), K(expr), K(idx)); + } } else if (OB_FAIL(item.set_column(idx))) { LOG_WARN("failed to set column", K(ret), K(expr)); } else if (OB_FAIL(sql_expr_->add_expr_item(item, &expr))) { LOG_WARN("failed to add expr item", K(ret)); + } else { + need_calc = false; } - } else { - ObExprOperator* op = NULL; + } + if (OB_SUCC(ret) && need_calc) { + ObExprOperator *op = NULL; if (OB_FAIL(factory_.alloc(expr.get_expr_type(), op))) { LOG_WARN("fail to alloc expr_op", K(ret)); } else if (OB_UNLIKELY(NULL == op)) {