From 583738a5edc1945bcbe2e7c4dca647689bc0aeff Mon Sep 17 00:00:00 2001 From: 2149 <260391947@qq.com> Date: Wed, 8 Nov 2023 12:13:23 +0000 Subject: [PATCH] fix generated column late materialization bug --- src/sql/optimizer/ob_select_log_plan.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sql/optimizer/ob_select_log_plan.cpp b/src/sql/optimizer/ob_select_log_plan.cpp index 9e7c070a0..df5e4c19b 100644 --- a/src/sql/optimizer/ob_select_log_plan.cpp +++ b/src/sql/optimizer/ob_select_log_plan.cpp @@ -7346,9 +7346,11 @@ int ObSelectLogPlan::if_column_store_plan_need_late_materialization(ObLogSort *c { int ret = OB_SUCCESS; ObSEArray temp_exprs; + ObSEArray temp_col_exprs; ObSEArray table_keys; const ObDMLStmt *stmt = NULL; used_column_ids.reuse(); + need = true; // check whether index key cover filter exprs, sort exprs and part exprs if (OB_ISNULL(table_scan) || OB_ISNULL(child_sort) || OB_ISNULL(stmt=get_stmt())) { @@ -7370,6 +7372,21 @@ int ObSelectLogPlan::if_column_store_plan_need_late_materialization(ObLogSort *c } else if (NULL != table_scan->get_pre_query_range() && OB_FAIL(append(temp_exprs, table_scan->get_pre_query_range()->get_range_exprs()))) { LOG_WARN("failed to append exprs", K(ret)); + } else if (OB_FAIL(ObRawExprUtils::extract_column_exprs(temp_exprs, temp_col_exprs))) { + LOG_WARN("extract column exprs failed", K(ret)); + } else { + for (int64_t i = 0; OB_SUCC(ret) && i < temp_col_exprs.count(); ++i) { + ObColumnRefRawExpr *col_expr = static_cast(temp_col_exprs.at(i)); + if (OB_ISNULL(col_expr)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected null", K(ret)); + } else if (col_expr->is_virtual_generated_column() + && OB_FAIL(temp_exprs.push_back(col_expr->get_dependant_expr()))) { + LOG_WARN("push back depend expr failed", K(ret)); + } + } + } + if (OB_FAIL(ret) || !need) { } else if (OB_FAIL(ObRawExprUtils::extract_column_ids(temp_exprs, used_column_ids))) { LOG_WARN("failed to extract column ids", K(ret)); } else {