fix some bugs

This commit is contained in:
wangt1xiuyi 2023-04-22 14:20:35 +00:00 committed by ob-robot
parent 73ba439d2e
commit 27783b2352
11 changed files with 95 additions and 41 deletions

View File

@ -132,8 +132,7 @@ int ObPLParser::parse(const ObString &stmt_block,
parse_result.is_for_trigger_,
parse_result.is_dynamic_sql_,
is_inner_parse,
is_include_old_new_in_trigger,
parse_result.mysql_compatible_comment_))) {
is_include_old_new_in_trigger))) {
LOG_WARN("parse stmt block failed", K(ret), K(stmt_block), K(orig_stmt_block));
} else if (OB_ISNULL(parse_result.result_tree_)) {
ret = OB_ERR_PARSE_SQL;
@ -158,8 +157,7 @@ int ObPLParser::parse_procedure(const ObString &stmt_block,
bool is_for_trigger,
bool is_dynamic,
bool is_inner_parse,
bool &is_include_old_new_in_trigger,
bool mysql_compatible_comment)
bool &is_include_old_new_in_trigger)
{
int ret = OB_SUCCESS;
ObParseCtx parse_ctx;
@ -178,7 +176,6 @@ int ObPLParser::parse_procedure(const ObString &stmt_block,
parse_ctx.is_not_utf8_connection_ = ObCharset::is_valid_collation(connection_collation_) ?
(ObCharset::charset_type_by_coll(connection_collation_) != CHARSET_UTF8MB4) : false;
parse_ctx.connection_collation_ = connection_collation_;
parse_ctx.mysql_compatible_comment_ = mysql_compatible_comment;
ret = parse_stmt_block(parse_ctx, multi_stmt);
if (OB_ERR_PARSE_SQL == ret) {
@ -198,6 +195,9 @@ int ObPLParser::parse_procedure(const ObString &stmt_block,
K(ret), K(err_line), K(global_errmsg), K(stmt));
LOG_USER_ERROR(OB_ERR_PARSE_SQL, ob_errpkt_strerror(OB_ERR_PARSER_SYNTAX, false),
err_len, err_str, err_line);
} else if (parse_ctx.mysql_compatible_comment_) {
ret = OB_ERR_PARSE_SQL;
LOG_WARN("the sql is invalid", K(ret), K(stmt_block));
} else {
question_mark_ctx = parse_ctx.question_mark_ctx_;
is_include_old_new_in_trigger = parse_ctx.is_include_old_new_in_trigger_;

View File

@ -61,8 +61,7 @@ private:
bool is_for_trigger,
bool is_dynamic,
bool is_inner_parse,
bool &is_include_old_new_in_trigger,
bool mysql_compatible_comment);
bool &is_include_old_new_in_trigger);
int parse_stmt_block(ObParseCtx &parse_ctx,
ObStmtNodeTree *&multi_stmt);
int reconstruct_trigger_package(ObStmtNodeTree *&package_stmt,

View File

@ -507,24 +507,23 @@ Timestamp{whitespace}?\"[^\"]*\" {
{mysql_compatible_comment_without_version} {
//refer to src/sql/parser/sql_parser_mysql_mode.l for more info.
ParseResult *p = (ParseResult *)yyextra;
p->mysql_compatible_comment_ = true;
ObParseCtx *parse_ctx = (ObParseCtx *)yyextra;
parse_ctx->mysql_compatible_comment_ = true;
}
{mysql_compatible_comment_with_version} {
ParseResult *p = (ParseResult *)yyextra;
p->mysql_compatible_comment_ = true;
ObParseCtx *parse_ctx = (ObParseCtx *)yyextra;
parse_ctx->mysql_compatible_comment_ = true;
}
{mysql_compatible_comment_end} {
ParseResult *p = (ParseResult *)yyextra;
if (p->mysql_compatible_comment_){
p->mysql_compatible_comment_ = false;
ObParseCtx *parse_ctx = (ObParseCtx *)yyextra;
if (parse_ctx->mysql_compatible_comment_) {
parse_ctx->mysql_compatible_comment_ = false;
BEGIN(INITIAL);
} else {
char c_ret = yytext[0];
yyless(1);
p->yycolumn_ = p->yycolumn_ - 1;
return c_ret;
}
}

View File

@ -194,7 +194,7 @@ int ObDbmsStats::gather_schema_stats(ObExecContext &ctx, ParamStore &params, ObO
} else if (OB_FAIL(update_stat_cache(ctx.get_my_session()->get_rpc_tenant_id(), stat_param))) {
LOG_WARN("failed to update stat cache", K(ret));
} else if (is_virtual_table(stat_param.table_id_)) {//not gather virtual table index.
//do nothing
tmp_alloc.reset();
} else if (stat_param.cascade_ &&
OB_FAIL(fast_gather_index_stats(ctx, stat_param,
is_all_fast_gather, no_gather_index_ids))) {

View File

@ -720,7 +720,9 @@ int ObStatHybridHist::decode(ObObj &obj, ObIAllocator &allocator)
} else {
col_stat_->get_histogram().get_buckets().reset();
col_stat_->get_histogram().set_bucket_cnt(hybrid_hist.get_buckets().count());
if (OB_FAIL(col_stat_->get_histogram().prepare_allocate_buckets(allocator, hybrid_hist.get_buckets().count()))) {
if (hybrid_hist.get_buckets().empty()) {
//do nothing, maybe the sample data is all null
} else if (OB_FAIL(col_stat_->get_histogram().prepare_allocate_buckets(allocator, hybrid_hist.get_buckets().count()))) {
LOG_WARN("failed to prepare allocate buckets", K(ret));
} else if (OB_FAIL(col_stat_->get_histogram().assign_buckets(hybrid_hist.get_buckets()))) {
LOG_WARN("failed to assign buckets", K(ret));

View File

@ -201,9 +201,6 @@ public:
ObOptColumnStat *stat) :
ObStatColItem(param, stat)
{}
// always need to deduce table avg row length
virtual bool is_needed() const override { return true; }
const char *get_fmt() const
{
return lib::is_oracle_mode() ? " AVG(SYS_OP_OPNSIZE(\"%.*s\"))"

View File

@ -3827,7 +3827,8 @@ int ObSql::parser_and_check(const ObString &outlined_stmt,
|| OB_ERR_CONSTRUCT_MUST_RETURN_SELF == ret
|| OB_ERR_ONLY_FUNC_CAN_PIPELINED == ret
|| OB_ERR_NO_ATTR_FOUND == ret
|| OB_ERR_NON_INT_LITERAL == ret)) {
|| OB_ERR_NON_INT_LITERAL == ret
|| OB_ERR_PARSER_INIT == ret)) {
// parser返回已知的错误码,不需要断掉与客户端的连接
exec_ctx.set_need_disconnect(false);
//FIXME qianfu NG_TRACE_EXT(set_need_disconnect, OB_ID(need_disconnect), false);

View File

@ -930,6 +930,12 @@ int ObParser::parse_sql(const ObString &stmt,
LOG_WARN("failed to fast parameterize", K(stmt), K(ret));
}
}
if (OB_SUCC(ret) &&
parse_result.enable_compatible_comment_ &&
parse_result.mysql_compatible_comment_) {
ret = OB_ERR_PARSE_SQL;
LOG_WARN("the sql is invalid", K(ret), K(stmt));
}
if (OB_FAIL(ret) && !no_throw_parser_error) {
auto err_charge_sql_mode = lib::is_oracle_mode();
LOG_WARN("failed to parse the statement",

View File

@ -306,7 +306,7 @@ do {
} else if (OB_UNLIKELY(!result->pl_parse_info_.is_pl_parse_ && 0 != result->question_mark_ctx_.count_)) { \
/* 如果是PL过来的sql语句,不要检查:*/ \
yyerror(NULL, result, "Unknown column '?'\n"); \
YYABORT_UNEXPECTED; \
YYABORT_PARSE_SQL_ERROR; \
} else { \
node->value_ = result->question_mark_ctx_.count_; \
} \

View File

@ -564,25 +564,12 @@ int ObColumnNamespaceChecker::check_rowid_table_column_namespace(const ObQualifi
&& (cur_table = table_item_iter.get_next_table_item()) != nullptr) {
if (!q_name.tbl_name_.empty()) {
if (cur_table->is_joined_table()) {
const JoinedTable *joined_table = reinterpret_cast<const JoinedTable*>(cur_table);
if (OB_ISNULL(joined_table->left_table_) || OB_ISNULL(joined_table->right_table_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("left or right table of joined table is NULL", K(ret),
KP(joined_table->left_table_), KP(joined_table->right_table_));
} else if (OB_FAIL(ObResolverUtils::name_case_cmp(params_.session_info_, q_name.tbl_name_,
joined_table->left_table_->get_object_name(),
OB_TABLE_NAME_CLASS, is_match))) {
LOG_WARN("table name case compare failed", K(ret),
K(q_name.tbl_name_), K(joined_table->left_table_->get_object_name()));
} else if (is_match) {
table_item = joined_table->left_table_;
} else if (OB_FAIL(ObResolverUtils::name_case_cmp(params_.session_info_, q_name.tbl_name_,
joined_table->right_table_->get_object_name(),
OB_TABLE_NAME_CLASS, is_match))) {
LOG_WARN("table name case compare failed", K(ret),
K(q_name.tbl_name_), K(joined_table->right_table_->get_object_name()));
} else if (is_match) {
table_item = joined_table->right_table_;
if (OB_FAIL(check_rowid_existence_in_joined_table(params_.session_info_,
q_name.tbl_name_,
reinterpret_cast<const JoinedTable*>(cur_table),
is_match,
table_item))) {
LOG_WARN("failed to check rowid existence in joined table", K(ret));
}
} else if (OB_FAIL(ObResolverUtils::name_case_cmp(params_.session_info_,
q_name.tbl_name_,
@ -605,5 +592,63 @@ int ObColumnNamespaceChecker::check_rowid_table_column_namespace(const ObQualifi
return ret;
}
int ObColumnNamespaceChecker::check_rowid_existence_in_joined_table(const ObSQLSessionInfo *session_info,
const ObString &tbl_name,
const JoinedTable *joined_table,
bool &found_it,
const TableItem *&table_item)
{
int ret = OB_SUCCESS;
if (found_it) {
//do nothing
} else if (OB_ISNULL(joined_table)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(joined_table));
} else if (OB_ISNULL(joined_table->left_table_) || OB_ISNULL(joined_table->right_table_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("left or right table of joined table is NULL", K(ret), KP(joined_table->left_table_),
KP(joined_table->right_table_));
} else if (!joined_table->left_table_->is_joined_table() &&
OB_FAIL(ObResolverUtils::name_case_cmp(session_info,
tbl_name,
joined_table->left_table_->get_object_name(),
OB_TABLE_NAME_CLASS,
found_it))) {
LOG_WARN("table name case compare failed", K(ret), K(tbl_name),
K(joined_table->left_table_->get_object_name()));
} else if (found_it) {
table_item = joined_table->left_table_;
} else if (joined_table->left_table_->is_joined_table() &&
OB_FAIL(SMART_CALL(check_rowid_existence_in_joined_table(session_info,
tbl_name,
reinterpret_cast<const JoinedTable*>(joined_table->left_table_),
found_it,
table_item)))) {
LOG_WARN("failed to check rowid existence in joined table", K(ret));
} else if (found_it) {
//do nothing
} else if (!joined_table->right_table_->is_joined_table() &&
OB_FAIL(ObResolverUtils::name_case_cmp(session_info,
tbl_name,
joined_table->right_table_->get_object_name(),
OB_TABLE_NAME_CLASS,
found_it))) {
LOG_WARN("table name case compare failed", K(ret), K(tbl_name),
K(joined_table->right_table_->get_object_name()));
} else if (found_it) {
table_item = joined_table->right_table_;
} else if (joined_table->right_table_->is_joined_table() &&
OB_FAIL(SMART_CALL(check_rowid_existence_in_joined_table(session_info,
tbl_name,
reinterpret_cast<const JoinedTable*>(joined_table->right_table_),
found_it,
table_item)))) {
LOG_WARN("failed to check rowid existence in joined table", K(ret));
} else if (found_it) {
//do nothing
}
return ret;
}
} // namespace sql
} // namespace oceanbase

View File

@ -118,6 +118,11 @@ private:
const common::ObString &column_name,
const TableItem &table_item,
bool &exist);
int check_rowid_existence_in_joined_table(const ObSQLSessionInfo *session_info,
const ObString &tbl_name,
const JoinedTable *joined_table,
bool &found_it,
const TableItem *&table_item);
private:
ObResolverParams &params_;
//record the table root reference by query