From 88f20f9b8bf6eb4864173adc4aa57a105d4fbcdf Mon Sep 17 00:00:00 2001 From: yaojing624 Date: Tue, 6 Jun 2023 05:24:07 +0000 Subject: [PATCH] Fix: oracle mode char type virtual generate column to build index, insert blank space into index table error --- src/sql/code_generator/ob_static_engine_cg.cpp | 15 +++++++++++++++ src/sql/engine/table/ob_table_scan_op.cpp | 10 ++++++++-- src/sql/resolver/dml/ob_dml_resolver.cpp | 15 +-------------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index c5ed7c46fb..ea5e3020da 100644 --- a/src/sql/code_generator/ob_static_engine_cg.cpp +++ b/src/sql/code_generator/ob_static_engine_cg.cpp @@ -3907,6 +3907,21 @@ int ObStaticEngineCG::generate_normal_tsc(ObLogTableScan &op, ObTableScanSpec &s if (OB_SUCC(ret) && spec.report_col_checksum_) { spec.ddl_output_cids_.assign(op.get_ddl_output_column_ids()); + for (int64_t i = 0; OB_SUCC(ret) && i < spec.ddl_output_cids_.count(); i++) { + const ObColumnSchemaV2 *column_schema = NULL; + if (OB_FAIL(schema_guard->get_column_schema(spec.ref_table_id_, + spec.ddl_output_cids_.at(i), column_schema))) { + LOG_WARN("fail to get column schema", K(ret)); + } else if (OB_ISNULL(column_schema)) { + ret = OB_ERR_COLUMN_NOT_FOUND; + LOG_WARN("fail to get column schema", K(ret)); + } else if (column_schema->get_meta_type().is_fixed_len_char_type() && + column_schema->is_virtual_generated_column()) { + // add flag in ddl_output_cids_ in this special scene. + uint64_t VIRTUAL_GEN_FIX_LEN_TAG = 1ULL << 63; + spec.ddl_output_cids_.at(i) = spec.ddl_output_cids_.at(i) | VIRTUAL_GEN_FIX_LEN_TAG; + } + } } if (OB_SUCC(ret) && 0 != op.get_session_id()) { diff --git a/src/sql/engine/table/ob_table_scan_op.cpp b/src/sql/engine/table/ob_table_scan_op.cpp index 573ec149cf..49c164aa74 100644 --- a/src/sql/engine/table/ob_table_scan_op.cpp +++ b/src/sql/engine/table/ob_table_scan_op.cpp @@ -2534,8 +2534,13 @@ int ObTableScanOp::init_ddl_column_checksum() if (OB_FAIL(ret)) { } else if (!found) { // if not found, the column is virtual generated column, in this scene, - // no need reshape, because reshape in opt layer. + // if is_fixed_len_char_type() is true, need reshape + uint64_t VIRTUAL_GEN_FIX_LEN_TAG = 1ULL << 63; + if ((MY_SPEC.ddl_output_cids_.at(i) & VIRTUAL_GEN_FIX_LEN_TAG) >> 63) { + need_reshape = true; + } else { need_reshape = false; + } } if (OB_SUCC(ret) && OB_FAIL(col_need_reshape_.push_back(need_reshape))) { LOG_WARN("failed to push back col need reshape", K(ret)); @@ -2689,13 +2694,14 @@ int ObTableScanOp::report_ddl_column_checksum() const int64_t curr_scan_task_id = scan_task_id_++; const ObTabletID &tablet_id = MY_INPUT.tablet_loc_->tablet_id_; const uint64_t table_id = MY_CTDEF.scan_ctdef_.ref_table_id_; + uint64_t VIRTUAL_GEN_FIXED_LEN_MASK = ~(1ULL << 63); for (int64_t i = 0; OB_SUCC(ret) && i < MY_SPEC.ddl_output_cids_.count(); ++i) { ObDDLChecksumItem item; item.execution_id_ = MY_SPEC.plan_->get_ddl_execution_id(); item.tenant_id_ = MTL_ID(); item.table_id_ = table_id; item.ddl_task_id_ = MY_SPEC.plan_->get_ddl_task_id(); - item.column_id_ = MY_SPEC.ddl_output_cids_.at(i); + item.column_id_ = MY_SPEC.ddl_output_cids_.at(i) & VIRTUAL_GEN_FIXED_LEN_MASK; item.task_id_ = ctx_.get_px_sqc_id() << 48 | ctx_.get_px_task_id() << 32 | curr_scan_task_id; item.checksum_ = i < column_checksum_.count() ? column_checksum_[i] : 0; #ifdef ERRSIM diff --git a/src/sql/resolver/dml/ob_dml_resolver.cpp b/src/sql/resolver/dml/ob_dml_resolver.cpp index 5538864c21..b40b5c1029 100755 --- a/src/sql/resolver/dml/ob_dml_resolver.cpp +++ b/src/sql/resolver/dml/ob_dml_resolver.cpp @@ -6794,20 +6794,7 @@ int ObDMLResolver::build_padding_expr(const ObSQLSessionInfo *session, } else if (ObCharType == column_schema->get_data_type() || ObNCharType == column_schema->get_data_type()) { if (is_pad_char_to_full_length(session->get_sql_mode())) { - // in ddl scene, T_INSERT && is_fixed_len_char_type, - // create index will trim virtual generated column in engine layer. - // Since we expanded the generated column into a dependent expression, - // we need to add trim on its dependent expression in this layer. - if (const_cast(session)->get_ddl_info().is_ddl() - && stmt::T_INSERT == session->get_stmt_type() - && column_schema->is_virtual_generated_column()) { - if (OB_FAIL(ObRawExprUtils::build_trim_expr(column_schema, - *params_.expr_factory_, - session_info_, - expr))) { - LOG_WARN("fail to build trime expr for char", K(ret)); - } - } else if (OB_FAIL(ObRawExprUtils::build_pad_expr(*params_.expr_factory_, + if (OB_FAIL(ObRawExprUtils::build_pad_expr(*params_.expr_factory_, true, column_schema, expr,