Skip to content

Commit 88f20f9

Browse files
yaojing624ob-robot
authored andcommitted
Fix: oracle mode char type virtual generate column to build index, insert blank space into index table error
1 parent d129bae commit 88f20f9

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/sql/code_generator/ob_static_engine_cg.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3907,6 +3907,21 @@ int ObStaticEngineCG::generate_normal_tsc(ObLogTableScan &op, ObTableScanSpec &s
39073907

39083908
if (OB_SUCC(ret) && spec.report_col_checksum_) {
39093909
spec.ddl_output_cids_.assign(op.get_ddl_output_column_ids());
3910+
for (int64_t i = 0; OB_SUCC(ret) && i < spec.ddl_output_cids_.count(); i++) {
3911+
const ObColumnSchemaV2 *column_schema = NULL;
3912+
if (OB_FAIL(schema_guard->get_column_schema(spec.ref_table_id_,
3913+
spec.ddl_output_cids_.at(i), column_schema))) {
3914+
LOG_WARN("fail to get column schema", K(ret));
3915+
} else if (OB_ISNULL(column_schema)) {
3916+
ret = OB_ERR_COLUMN_NOT_FOUND;
3917+
LOG_WARN("fail to get column schema", K(ret));
3918+
} else if (column_schema->get_meta_type().is_fixed_len_char_type() &&
3919+
column_schema->is_virtual_generated_column()) {
3920+
// add flag in ddl_output_cids_ in this special scene.
3921+
uint64_t VIRTUAL_GEN_FIX_LEN_TAG = 1ULL << 63;
3922+
spec.ddl_output_cids_.at(i) = spec.ddl_output_cids_.at(i) | VIRTUAL_GEN_FIX_LEN_TAG;
3923+
}
3924+
}
39103925
}
39113926

39123927
if (OB_SUCC(ret) && 0 != op.get_session_id()) {

src/sql/engine/table/ob_table_scan_op.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,8 +2534,13 @@ int ObTableScanOp::init_ddl_column_checksum()
25342534
if (OB_FAIL(ret)) {
25352535
} else if (!found) {
25362536
// if not found, the column is virtual generated column, in this scene,
2537-
// no need reshape, because reshape in opt layer.
2537+
// if is_fixed_len_char_type() is true, need reshape
2538+
uint64_t VIRTUAL_GEN_FIX_LEN_TAG = 1ULL << 63;
2539+
if ((MY_SPEC.ddl_output_cids_.at(i) & VIRTUAL_GEN_FIX_LEN_TAG) >> 63) {
2540+
need_reshape = true;
2541+
} else {
25382542
need_reshape = false;
2543+
}
25392544
}
25402545
if (OB_SUCC(ret) && OB_FAIL(col_need_reshape_.push_back(need_reshape))) {
25412546
LOG_WARN("failed to push back col need reshape", K(ret));
@@ -2689,13 +2694,14 @@ int ObTableScanOp::report_ddl_column_checksum()
26892694
const int64_t curr_scan_task_id = scan_task_id_++;
26902695
const ObTabletID &tablet_id = MY_INPUT.tablet_loc_->tablet_id_;
26912696
const uint64_t table_id = MY_CTDEF.scan_ctdef_.ref_table_id_;
2697+
uint64_t VIRTUAL_GEN_FIXED_LEN_MASK = ~(1ULL << 63);
26922698
for (int64_t i = 0; OB_SUCC(ret) && i < MY_SPEC.ddl_output_cids_.count(); ++i) {
26932699
ObDDLChecksumItem item;
26942700
item.execution_id_ = MY_SPEC.plan_->get_ddl_execution_id();
26952701
item.tenant_id_ = MTL_ID();
26962702
item.table_id_ = table_id;
26972703
item.ddl_task_id_ = MY_SPEC.plan_->get_ddl_task_id();
2698-
item.column_id_ = MY_SPEC.ddl_output_cids_.at(i);
2704+
item.column_id_ = MY_SPEC.ddl_output_cids_.at(i) & VIRTUAL_GEN_FIXED_LEN_MASK;
26992705
item.task_id_ = ctx_.get_px_sqc_id() << 48 | ctx_.get_px_task_id() << 32 | curr_scan_task_id;
27002706
item.checksum_ = i < column_checksum_.count() ? column_checksum_[i] : 0;
27012707
#ifdef ERRSIM

src/sql/resolver/dml/ob_dml_resolver.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6794,20 +6794,7 @@ int ObDMLResolver::build_padding_expr(const ObSQLSessionInfo *session,
67946794
} else if (ObCharType == column_schema->get_data_type()
67956795
|| ObNCharType == column_schema->get_data_type()) {
67966796
if (is_pad_char_to_full_length(session->get_sql_mode())) {
6797-
// in ddl scene, T_INSERT && is_fixed_len_char_type,
6798-
// create index will trim virtual generated column in engine layer.
6799-
// Since we expanded the generated column into a dependent expression,
6800-
// we need to add trim on its dependent expression in this layer.
6801-
if (const_cast<ObSQLSessionInfo *>(session)->get_ddl_info().is_ddl()
6802-
&& stmt::T_INSERT == session->get_stmt_type()
6803-
&& column_schema->is_virtual_generated_column()) {
6804-
if (OB_FAIL(ObRawExprUtils::build_trim_expr(column_schema,
6805-
*params_.expr_factory_,
6806-
session_info_,
6807-
expr))) {
6808-
LOG_WARN("fail to build trime expr for char", K(ret));
6809-
}
6810-
} else if (OB_FAIL(ObRawExprUtils::build_pad_expr(*params_.expr_factory_,
6797+
if (OB_FAIL(ObRawExprUtils::build_pad_expr(*params_.expr_factory_,
68116798
true,
68126799
column_schema,
68136800
expr,

0 commit comments

Comments
 (0)