From 4c8ccd1fe61312cc85ea911a9428c334ffe029f9 Mon Sep 17 00:00:00 2001 From: obdev Date: Tue, 21 Jun 2022 10:55:41 +0800 Subject: [PATCH] [CP] fix shared exprs bug after view merge --- .../code_generator/ob_code_generator_impl.cpp | 15 ++++++------- .../code_generator/ob_expr_generator_impl.cpp | 21 +++++++++++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/sql/code_generator/ob_code_generator_impl.cpp b/src/sql/code_generator/ob_code_generator_impl.cpp index 22d26d0911..1bf49516b9 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 c960846f0b..88285eb581 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)) { -- GitLab