diff --git a/src/pl/parser/ob_pl_parser.cpp b/src/pl/parser/ob_pl_parser.cpp index f445373c2..5e1e146a3 100644 --- a/src/pl/parser/ob_pl_parser.cpp +++ b/src/pl/parser/ob_pl_parser.cpp @@ -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_; diff --git a/src/pl/parser/ob_pl_parser.h b/src/pl/parser/ob_pl_parser.h index 49a6e19af..d4ca6745b 100644 --- a/src/pl/parser/ob_pl_parser.h +++ b/src/pl/parser/ob_pl_parser.h @@ -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, diff --git a/src/pl/parser/pl_parser_mysql_mode.l b/src/pl/parser/pl_parser_mysql_mode.l index 45307431d..9b8e44a7a 100644 --- a/src/pl/parser/pl_parser_mysql_mode.l +++ b/src/pl/parser/pl_parser_mysql_mode.l @@ -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; } } diff --git a/src/pl/sys_package/ob_dbms_stats.cpp b/src/pl/sys_package/ob_dbms_stats.cpp index 161efa6db..d56a9cf7a 100644 --- a/src/pl/sys_package/ob_dbms_stats.cpp +++ b/src/pl/sys_package/ob_dbms_stats.cpp @@ -194,7 +194,7 @@ int ObDbmsStats::gather_schema_stats(ObExecContext &ctx, ParamStore ¶ms, 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))) { diff --git a/src/share/stat/ob_stat_item.cpp b/src/share/stat/ob_stat_item.cpp index 1e037e04d..57186bd51 100644 --- a/src/share/stat/ob_stat_item.cpp +++ b/src/share/stat/ob_stat_item.cpp @@ -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)); diff --git a/src/share/stat/ob_stat_item.h b/src/share/stat/ob_stat_item.h index 7c108f3c9..b42b5c927 100644 --- a/src/share/stat/ob_stat_item.h +++ b/src/share/stat/ob_stat_item.h @@ -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\"))" diff --git a/src/sql/ob_sql.cpp b/src/sql/ob_sql.cpp index 63d25d706..87b9e959c 100644 --- a/src/sql/ob_sql.cpp +++ b/src/sql/ob_sql.cpp @@ -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); diff --git a/src/sql/parser/ob_parser.cpp b/src/sql/parser/ob_parser.cpp index a97d68240..02d2d1563 100644 --- a/src/sql/parser/ob_parser.cpp +++ b/src/sql/parser/ob_parser.cpp @@ -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", diff --git a/src/sql/parser/sql_parser_base.h b/src/sql/parser/sql_parser_base.h index 4f683b01c..9a9330fd6 100644 --- a/src/sql/parser/sql_parser_base.h +++ b/src/sql/parser/sql_parser_base.h @@ -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_; \ } \ diff --git a/src/sql/resolver/dml/ob_column_namespace_checker.cpp b/src/sql/resolver/dml/ob_column_namespace_checker.cpp index f07d89791..72daa2c6a 100644 --- a/src/sql/resolver/dml/ob_column_namespace_checker.cpp +++ b/src/sql/resolver/dml/ob_column_namespace_checker.cpp @@ -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(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(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(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(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 diff --git a/src/sql/resolver/dml/ob_column_namespace_checker.h b/src/sql/resolver/dml/ob_column_namespace_checker.h index 5a817b7e3..8f5798bcb 100644 --- a/src/sql/resolver/dml/ob_column_namespace_checker.h +++ b/src/sql/resolver/dml/ob_column_namespace_checker.h @@ -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 ¶ms_; //record the table root reference by query