revert commit ‘Fix generated column bug’
This commit is contained in:
@ -6534,8 +6534,8 @@ int ObDDLService::update_generated_column_schema(
|
||||
if (OB_FAIL(new_generated_column_schema.get_err_ret())) {
|
||||
LOG_WARN("failed to copy new gen column", K(ret));
|
||||
} else if (OB_FAIL(modify_generated_column_default_value(new_generated_column_schema,
|
||||
orig_column_schema,
|
||||
alter_column_schema,
|
||||
const_cast<ObString&>(orig_column_schema.get_column_name_str()),
|
||||
alter_column_schema.get_column_name_str(),
|
||||
new_table_schema,
|
||||
*tz_info_wrap.get_time_zone_info()))) {
|
||||
LOG_WARN("modify generated column value failed", K(ret));
|
||||
@ -6558,8 +6558,8 @@ int ObDDLService::update_generated_column_schema(
|
||||
}
|
||||
|
||||
int ObDDLService::modify_generated_column_default_value(ObColumnSchemaV2 &generated_column,
|
||||
const ObColumnSchemaV2 &orig_column_schema,
|
||||
const AlterColumnSchema &alter_column_schema,
|
||||
common::ObString &column_name,
|
||||
const ObString &new_column_name,
|
||||
const ObTableSchema &table_schema,
|
||||
const ObTimeZoneInfo &tz_info)
|
||||
{
|
||||
@ -6600,8 +6600,6 @@ int ObDDLService::modify_generated_column_default_value(ObColumnSchemaV2 &genera
|
||||
LOG_WARN("failed to get table compat mode", K(ret));
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
ObString &column_name = const_cast<ObString&>(orig_column_schema.get_column_name_str());
|
||||
ObString &new_column_name = const_cast<ObString&>(alter_column_schema.get_column_name_str());
|
||||
ObRawExprModifyColumnName modifyColumnName(new_column_name, column_name, compat_mode);
|
||||
if (OB_FAIL(modifyColumnName.modifyColumnName(*expr))) {
|
||||
LOG_WARN("modifyColumnName modify column name failed", K(ret));
|
||||
@ -6624,34 +6622,6 @@ int ObDDLService::modify_generated_column_default_value(ObColumnSchemaV2 &genera
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (orig_column_schema.get_data_type() != alter_column_schema.get_data_type()) {
|
||||
if (OB_FAIL(ObRawExprUtils::erase_operand_implicit_cast(expr, expr))) {
|
||||
LOG_WARN("erase implicit cast failed", K(ret));
|
||||
} else if (OB_FAIL(modify_depend_column_type(expr, alter_column_schema.get_column_name_str(), alter_column_schema))) {
|
||||
LOG_WARN("modify column type failed", K(ret));
|
||||
} else if (OB_FAIL(expr->formalize(&default_session))) {
|
||||
LOG_WARN("expr formalize failed", K(ret));
|
||||
} else {
|
||||
ObRawExpr *expr_with_implicit_cast = NULL;
|
||||
ObExprResType cast_dst_type;
|
||||
ObCastMode cast_mode;
|
||||
cast_dst_type.set_meta(generated_column.get_meta_type());
|
||||
cast_dst_type.set_accuracy(generated_column.get_accuracy());
|
||||
if (OB_FAIL(ObSQLUtils::get_default_cast_mode(false, 0, &default_session, cast_mode))) {
|
||||
LOG_WARN("get_default_cast_mode failed", K(ret));
|
||||
} else if (OB_FAIL(ObRawExprUtils::try_add_cast_expr_above(&expr_factory, &default_session,
|
||||
*expr, cast_dst_type, cast_mode,
|
||||
expr_with_implicit_cast))) {
|
||||
LOG_WARN("try add cast expr failed", K(ret));
|
||||
} else if (OB_FAIL(ObRawExprUtils::check_is_valid_generated_col(expr_with_implicit_cast, expr_factory.get_allocator()))) {
|
||||
LOG_WARN("sysfunc in expr is not valid for generated column", K(ret), KP(expr_with_implicit_cast));
|
||||
} else {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -6689,57 +6659,6 @@ int ObDDLService::validate_update_column_for_materialized_view(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDDLService::modify_depend_column_type(sql::ObRawExpr *expr, const ObString &column_name, const AlterColumnSchema &column_schema) {
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else if (expr->has_flag(IS_COLUMN)) {
|
||||
ObColumnRefRawExpr *column_expr = static_cast<ObColumnRefRawExpr *>(expr);
|
||||
if (column_expr->get_column_name() == column_name) {
|
||||
column_expr->set_data_type(column_schema.get_data_type());
|
||||
column_expr->set_lob_column(is_lob_storage(column_schema.get_data_type()));
|
||||
if (ob_is_string_type(column_schema.get_data_type())
|
||||
|| ob_is_enumset_tc(column_schema.get_data_type())
|
||||
|| ob_is_json_tc(column_schema.get_data_type())
|
||||
|| ob_is_geometry_tc(column_schema.get_data_type())) {
|
||||
column_expr->set_collation_type(column_schema.get_collation_type());
|
||||
column_expr->set_collation_level(CS_LEVEL_IMPLICIT);
|
||||
} else {
|
||||
column_expr->set_collation_type(CS_TYPE_BINARY);
|
||||
column_expr->set_collation_level(CS_LEVEL_NUMERIC);
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
column_expr->set_accuracy(column_schema.get_accuracy());
|
||||
if (OB_FAIL(column_expr->extract_info())) {
|
||||
LOG_WARN("extract column expr info failed", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && column_schema.is_enum_or_set()) {
|
||||
if (OB_FAIL(column_expr->set_enum_set_values(column_schema.get_extended_type_info()))) {
|
||||
LOG_WARN("failed to set enum set values", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && column_schema.is_xmltype()) {
|
||||
// column_expr->set_udt_id(column_schema.get_sub_data_type());
|
||||
// }
|
||||
// ToDo : @gehao, need to conver extend type to udt type?
|
||||
//if (OB_SUCC(ret) && column_schema.is_sql_xmltype()) {
|
||||
column_expr->set_data_type(ObUserDefinedSQLType);
|
||||
column_expr->set_subschema_id(ObXMLSqlType);
|
||||
// reset accuracy
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < expr->get_param_count(); ++i) {
|
||||
if (OB_FAIL(SMART_CALL(modify_depend_column_type(expr->get_param_expr(i), column_name, column_schema)))) {
|
||||
LOG_WARN("modify depend column type failed", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDDLService::modify_part_func_expr(
|
||||
const ObString &orig_column_name,
|
||||
const ObString &alter_column_name,
|
||||
@ -8119,7 +8038,8 @@ int ObDDLService::gen_alter_column_new_table_schema_offline(
|
||||
origin_table_schema,
|
||||
update_column_name_set))) {
|
||||
RS_LOG(WARN, "failed to pre check orig column schema", K(ret));
|
||||
} else if (orig_column_schema->has_generated_column_deps()) {
|
||||
} else if (OB_DDL_CHANGE_COLUMN == op_type &&
|
||||
orig_column_schema->has_generated_column_deps()) {
|
||||
if (OB_FAIL(update_generated_column_schema(*alter_column_schema,
|
||||
*orig_column_schema,
|
||||
origin_table_schema,
|
||||
|
@ -1611,13 +1611,10 @@ private:
|
||||
ObDDLOperator *ddl_operator = NULL,
|
||||
common::ObMySQLTransaction *trans = NULL);
|
||||
int modify_generated_column_default_value(share::schema::ObColumnSchemaV2 &generated_column,
|
||||
const ObColumnSchemaV2 &orig_column_schema,
|
||||
const AlterColumnSchema &alter_column_schema,
|
||||
common::ObString &column_name,
|
||||
const common::ObString &new_column_name,
|
||||
const share::schema::ObTableSchema &table_schema,
|
||||
const common::ObTimeZoneInfo &tz_info);
|
||||
int modify_depend_column_type(sql::ObRawExpr *expr,
|
||||
const ObString &column_name,
|
||||
const AlterColumnSchema &column_schema);
|
||||
int validate_update_column_for_materialized_view(
|
||||
const share::schema::ObTableSchema &origin_table_schema,
|
||||
const share::schema::ObColumnSchemaV2 &orig_column_schema);
|
||||
|
@ -894,8 +894,7 @@ int ObExprCast::is_valid_for_generated_column(const ObRawExpr*expr, const common
|
||||
}
|
||||
} else if (ObTimeType == src && ObTimeType != dst && ob_is_temporal_type(dst)) {
|
||||
is_valid = false;
|
||||
} else if ((ObTimestampType == src && ObTimestampType != dst)
|
||||
|| (ObTimestampType == dst && ObTimestampType != src)) {
|
||||
} else if (ObTimestampType == src && ObTimestampType != dst) {
|
||||
is_valid = false;
|
||||
}
|
||||
}
|
||||
|
@ -4424,6 +4424,19 @@ int ObResolverUtils::resolve_generated_column_expr(ObResolverParams ¶ms,
|
||||
LOG_WARN("transform udt col expr for generated column failed", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) &&
|
||||
(ObResolverUtils::CHECK_FOR_FUNCTION_INDEX == check_status ||
|
||||
ObResolverUtils::CHECK_FOR_GENERATED_COLUMN == check_status)) {
|
||||
if (OB_FAIL(ObRawExprUtils::check_is_valid_generated_col(expr, expr_factory->get_allocator()))) {
|
||||
if (OB_ERR_ONLY_PURE_FUNC_CANBE_VIRTUAL_COLUMN_EXPRESSION == ret
|
||||
&& ObResolverUtils::CHECK_FOR_FUNCTION_INDEX == check_status) {
|
||||
ret = OB_ERR_ONLY_PURE_FUNC_CANBE_INDEXED;
|
||||
LOG_WARN("sysfunc in expr is not valid for generated column", K(ret), K(*expr));
|
||||
} else {
|
||||
LOG_WARN("fail to check if the sysfunc exprs are valid in generated columns", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
const ObObjType expr_datatype = expr->get_result_type().get_type();
|
||||
const ObCollationType expr_cs_type = expr->get_result_type().get_collation_type();
|
||||
const ObObjType dst_datatype = generated_column.get_data_type();
|
||||
@ -4532,29 +4545,6 @@ int ObResolverUtils::resolve_generated_column_expr(ObResolverParams ¶ms,
|
||||
LOG_WARN("inconsistent datatypes", K(expr->get_result_type().get_type()));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) &&
|
||||
(ObResolverUtils::CHECK_FOR_FUNCTION_INDEX == check_status ||
|
||||
ObResolverUtils::CHECK_FOR_GENERATED_COLUMN == check_status)) {
|
||||
ObExprResType cast_dst_type;
|
||||
ObCastMode cast_mode;
|
||||
cast_dst_type.set_meta(generated_column.get_meta_type());
|
||||
cast_dst_type.set_accuracy(generated_column.get_accuracy());
|
||||
ObRawExpr *expr_with_implicit_cast = NULL;
|
||||
if (OB_FAIL(ObSQLUtils::get_default_cast_mode(false, 0, session_info, cast_mode))) {
|
||||
LOG_WARN("get_default_cast_mode failed", K(ret));
|
||||
} else if (OB_FAIL(ObRawExprUtils::try_add_cast_expr_above(expr_factory, session_info,
|
||||
*expr, cast_dst_type, cast_mode, expr_with_implicit_cast))) {
|
||||
LOG_WARN("try add cast above failed", K(ret));
|
||||
} else if (OB_FAIL(ObRawExprUtils::check_is_valid_generated_col(expr_with_implicit_cast, expr_factory->get_allocator()))) {
|
||||
if (OB_ERR_ONLY_PURE_FUNC_CANBE_VIRTUAL_COLUMN_EXPRESSION == ret
|
||||
&& ObResolverUtils::CHECK_FOR_FUNCTION_INDEX == check_status) {
|
||||
ret = OB_ERR_ONLY_PURE_FUNC_CANBE_INDEXED;
|
||||
LOG_WARN("sysfunc in expr is not valid for function index", K(ret), KP(expr_with_implicit_cast));
|
||||
} else {
|
||||
LOG_WARN("sysfunc in expr is not valid for generated column", K(ret), KP(expr_with_implicit_cast));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_FAIL(ObDDLResolver::print_expr_to_default_value(*expr, generated_column,
|
||||
params.schema_checker_, session_info->get_timezone_info()))) {
|
||||
|
Reference in New Issue
Block a user