[CP] bugfix select column_default value from information_schema.columns core

This commit is contained in:
shadowao
2023-12-06 06:12:18 +00:00
committed by ob-robot
parent 62e48e989d
commit 1f8a222b14
3 changed files with 63 additions and 7 deletions

View File

@ -19,6 +19,7 @@
#include "lib/geo/ob_geo_utils.h"
#include "share/schema/ob_schema_getter_guard.h"
#include "share/inner_table/ob_inner_table_schema.h"
#include "share/ob_lob_access_utils.h"
#include "sql/session/ob_sql_session_info.h"
#include "sql/parser/ob_parser.h"
#include "sql/resolver/dml/ob_select_resolver.h"
@ -536,19 +537,25 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const ObString &database_name,
}
case COLUMN_DEFAULT: {
casted_cell.reset();
cells[cell_idx].reset();
const ObObj *res_cell = NULL;
ObObj def_obj = column_schema->get_cur_default_value();
ObObjType column_type = ObMaxType;
const ObColumnSchemaV2 *tmp_column_schema = NULL;
if (OB_ISNULL(table_schema_) ||
OB_ISNULL(tmp_column_schema = table_schema_->get_column_schema(col_id))) {
OB_ISNULL(tmp_column_schema = table_schema_->get_column_schema(col_id)) ||
OB_ISNULL(allocator_)) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "table or column schema is null", KR(ret), KP(table_schema_), KP(tmp_column_schema));
SERVER_LOG(WARN, "table or column schema or or allocator is null", KR(ret), KP(table_schema_), KP(tmp_column_schema), KP(allocator_));
} else if (FALSE_IT(column_type = tmp_column_schema->get_meta_type().get_type())) {
} else if (IS_DEFAULT_NOW_OBJ(def_obj)) {
ObObj def_now_obj;
def_now_obj.set_string(column_type, ObString::make_string(N_UPPERCASE_CUR_TIMESTAMP));
cells[cell_idx] = def_now_obj;
if (OB_FAIL(ObTextStringResult::ob_convert_obj_temporay_lob(def_now_obj, *allocator_))) {
SERVER_LOG(WARN, "convert lob type obj fail", K(ret), K(def_now_obj));
} else {
cells[cell_idx] = def_now_obj;
}
} else if (def_obj.is_bit() || ob_is_enum_or_set_type(def_obj.get_type())) {
char *buf = NULL;
int64_t buf_len = number::ObNumber::MAX_PRINTABLE_SIZE;
@ -569,6 +576,10 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const ObString &database_name,
cells[cell_idx].set_string(column_type, ObString(static_cast<int32_t>(pos), buf));
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(ObTextStringResult::ob_convert_obj_temporay_lob(cells[cell_idx], *allocator_))) {
SERVER_LOG(WARN, "convert lob type obj fail", K(ret), K(cells[cell_idx]));
}
} else {
if (OB_FAIL(ObObjCaster::to_type(column_type, cast_ctx,
def_obj,
@ -977,21 +988,27 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const common::ObString &database_na
}
case COLUMN_DEFAULT: {
casted_cell.reset();
cells[cell_idx].reset();
const ObObj *res_cell = NULL;
ColumnItem column_item;
ObObjType column_type = ObMaxType;
const ObColumnSchemaV2 *tmp_column_schema = NULL;
if (OB_ISNULL(table_schema_) ||
OB_ISNULL(tmp_column_schema = table_schema_->get_column_schema(col_id))) {
OB_ISNULL(tmp_column_schema = table_schema_->get_column_schema(col_id)) ||
OB_ISNULL(allocator_)) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "table or column schema is null", KR(ret), KP(table_schema_), KP(tmp_column_schema));
SERVER_LOG(WARN, "table or column schema or allocator is null", KR(ret), KP(table_schema_), KP(tmp_column_schema), KP(allocator_));
} else if (FALSE_IT(column_type = tmp_column_schema->get_meta_type().get_type())) {
} else if (OB_FAIL(ObResolverUtils::resolve_default_value_and_expr_from_select_item(select_item, column_item, select_stmt))) {
SERVER_LOG(WARN, "failed to resolve default value", K(ret));
} else if (IS_DEFAULT_NOW_OBJ(column_item.default_value_)) {
ObObj def_now_obj;
def_now_obj.set_string(column_type, ObString::make_string(N_UPPERCASE_CUR_TIMESTAMP));
cells[cell_idx] = def_now_obj;
if (OB_FAIL(ObTextStringResult::ob_convert_obj_temporay_lob(def_now_obj, *allocator_))) {
SERVER_LOG(WARN, "convert lob type obj fail", K(ret), K(def_now_obj));
} else {
cells[cell_idx] = def_now_obj;
}
} else if (column_item.default_value_.is_bit() || ob_is_enum_or_set_type(column_item.default_value_.get_type())) {
char *buf = NULL;
int64_t buf_len = number::ObNumber::MAX_PRINTABLE_SIZE;
@ -1016,6 +1033,10 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const common::ObString &database_na
cells[cell_idx].set_string(column_type, ObString(static_cast<int32_t>(pos), buf));
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(ObTextStringResult::ob_convert_obj_temporay_lob(cells[cell_idx], *allocator_))) {
SERVER_LOG(WARN, "convert lob type obj fail", K(ret), K(cells[cell_idx]));
}
} else {
if (OB_FAIL(ObObjCaster::to_type(column_type, cast_ctx,
column_item.default_value_,

View File

@ -717,3 +717,27 @@ CREATE TABLE t1 (c1 tinyblob DEFAULT NULL, c2 varchar(161) DEFAULT 's&7dcwZ3nSn~
(select nvl( c1 , c2 ) as c from t1) union all (select lower(c3) as c from t1);
c
drop table t1;
CREATE TABLE t1 ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, col_bit bit(64) default 0b010101, date_registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges';
select column_name, column_default from information_schema.columns where table_name='t1' and table_schema='test';
column_name column_default
Host
Db
User
Select_priv N
Create_routine_priv N
col_bit b'10101'
date_registered CURRENT_TIMESTAMP
create view t1v1 as select * from t1;
drop table t1;
CREATE TABLE t1 ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, col_bit bit(64) default 0b010101, date_registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges';
select column_name, column_default from information_schema.columns where table_name = 't1v1';
column_name column_default
Host
Db
User
Select_priv N
Create_routine_priv N
col_bit b'10101'
date_registered CURRENT_TIMESTAMP
drop view t1v1;
drop table t1;

View File

@ -270,4 +270,15 @@ drop table t1;
CREATE TABLE t1 (c1 tinyblob DEFAULT NULL, c2 varchar(161) DEFAULT 's&7dcwZ3nSn~E(O', c3 text NOT NULL);
(select nvl( c1 , c2 ) as c from t1) union all (select lower(c3) as c from t1);
drop table t1;
drop table t1;
CREATE TABLE t1 ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, col_bit bit(64) default 0b010101, date_registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges';
select column_name, column_default from information_schema.columns where table_name='t1' and table_schema='test';
create view t1v1 as select * from t1;
drop table t1;
CREATE TABLE t1 ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, col_bit bit(64) default 0b010101, date_registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges';
select column_name, column_default from information_schema.columns where table_name = 't1v1';
drop view t1v1;
drop table t1;