fix print global hint bug for set stmt
This commit is contained in:
parent
3674a6668d
commit
40e9a1b569
@ -122,7 +122,7 @@ int ObCreateTableExecutor::prepare_ins_arg(ObCreateTableStmt &stmt,
|
|||||||
obj_print_params,
|
obj_print_params,
|
||||||
param_store,
|
param_store,
|
||||||
true);
|
true);
|
||||||
select_stmt_printer.set_is_root(true); // print hint as root stmt
|
select_stmt_printer.set_is_first_stmt_for_hint(true); // need print global hint
|
||||||
if (OB_ISNULL(buf)) {
|
if (OB_ISNULL(buf)) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
LOG_ERROR("allocate memory failed");
|
LOG_ERROR("allocate memory failed");
|
||||||
|
@ -34,6 +34,7 @@ ObDMLStmtPrinter::ObDMLStmtPrinter(char *buf, int64_t buf_len, int64_t *pos, con
|
|||||||
pos_(pos),
|
pos_(pos),
|
||||||
stmt_(stmt),
|
stmt_(stmt),
|
||||||
is_root_(false),
|
is_root_(false),
|
||||||
|
is_first_stmt_for_hint_(false),
|
||||||
print_cte_(false),
|
print_cte_(false),
|
||||||
schema_guard_(schema_guard),
|
schema_guard_(schema_guard),
|
||||||
print_params_(print_params),
|
print_params_(print_params),
|
||||||
@ -75,7 +76,7 @@ int ObDMLStmtPrinter::print_hint()
|
|||||||
plan_text.type_ = print_params_.for_dblink_
|
plan_text.type_ = print_params_.for_dblink_
|
||||||
? EXPLAIN_DBLINK_STMT
|
? EXPLAIN_DBLINK_STMT
|
||||||
: EXPLAIN_UNINITIALIZED; // just for print hint, ExplainType set as invalid type
|
: EXPLAIN_UNINITIALIZED; // just for print hint, ExplainType set as invalid type
|
||||||
if (OB_FAIL(query_hint.print_stmt_hint(plan_text, *stmt_, is_root_))) {
|
if (OB_FAIL(query_hint.print_stmt_hint(plan_text, *stmt_, is_first_stmt_for_hint_))) {
|
||||||
LOG_WARN("failed to print stmt hint", K(ret));
|
LOG_WARN("failed to print stmt hint", K(ret));
|
||||||
} else if (plan_text.pos_ == *pos_) {
|
} else if (plan_text.pos_ == *pos_) {
|
||||||
// no hint, roolback buffer!
|
// no hint, roolback buffer!
|
||||||
|
@ -139,6 +139,7 @@ public:
|
|||||||
int print_base_table(const TableItem *table_item);
|
int print_base_table(const TableItem *table_item);
|
||||||
int print_hint();
|
int print_hint();
|
||||||
void set_is_root(bool is_root) { is_root_ = is_root; }
|
void set_is_root(bool is_root) { is_root_ = is_root; }
|
||||||
|
void set_is_first_stmt_for_hint(bool is_first_stmt) { is_first_stmt_for_hint_ = is_first_stmt; }
|
||||||
void set_print_params(const ObObjPrintParams& obj_print_params)
|
void set_print_params(const ObObjPrintParams& obj_print_params)
|
||||||
{
|
{
|
||||||
print_params_ = obj_print_params;
|
print_params_ = obj_print_params;
|
||||||
@ -177,6 +178,7 @@ protected:
|
|||||||
int64_t *pos_;
|
int64_t *pos_;
|
||||||
const ObDMLStmt *stmt_;
|
const ObDMLStmt *stmt_;
|
||||||
bool is_root_;
|
bool is_root_;
|
||||||
|
bool is_first_stmt_for_hint_;
|
||||||
bool print_cte_;
|
bool print_cte_;
|
||||||
ObSchemaGetterGuard *schema_guard_;
|
ObSchemaGetterGuard *schema_guard_;
|
||||||
ObObjPrintParams print_params_;
|
ObObjPrintParams print_params_;
|
||||||
|
@ -284,11 +284,13 @@ int ObSelectStmtPrinter::print_set_op_stmt()
|
|||||||
param_store_,
|
param_store_,
|
||||||
/*force_col_alias*/true);
|
/*force_col_alias*/true);
|
||||||
stmt_printer.set_column_list(column_list_);
|
stmt_printer.set_column_list(column_list_);
|
||||||
|
stmt_printer.set_is_first_stmt_for_hint(is_first_stmt_for_hint_);
|
||||||
ObString set_op_str = ObString::make_string(
|
ObString set_op_str = ObString::make_string(
|
||||||
ObSelectStmt::set_operator_str(select_stmt->get_set_op()));
|
ObSelectStmt::set_operator_str(select_stmt->get_set_op()));
|
||||||
if (OB_FAIL(stmt_printer.do_print())) {
|
if (OB_FAIL(stmt_printer.do_print())) {
|
||||||
LOG_WARN("fail to print left stmt", K(ret), K(*child_stmts.at(0)));
|
LOG_WARN("fail to print left stmt", K(ret), K(*child_stmts.at(0)));
|
||||||
} else {
|
} else {
|
||||||
|
stmt_printer.set_is_first_stmt_for_hint(false);
|
||||||
DATA_PRINTF(")");
|
DATA_PRINTF(")");
|
||||||
}
|
}
|
||||||
for (int64_t i = 1; OB_SUCC(ret) && i < child_stmts.count(); ++i) {
|
for (int64_t i = 1; OB_SUCC(ret) && i < child_stmts.count(); ++i) {
|
||||||
|
@ -2118,6 +2118,7 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
|||||||
print_params,
|
print_params,
|
||||||
param_store);
|
param_store);
|
||||||
printer.set_is_root(true);
|
printer.set_is_root(true);
|
||||||
|
printer.set_is_first_stmt_for_hint(true);
|
||||||
printer.enable_print_temp_table_as_cte();
|
printer.enable_print_temp_table_as_cte();
|
||||||
if (OB_FAIL(printer.do_print())) {
|
if (OB_FAIL(printer.do_print())) {
|
||||||
LOG_WARN("fail to print select stmt", K(ret));
|
LOG_WARN("fail to print select stmt", K(ret));
|
||||||
@ -2135,6 +2136,7 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
|||||||
print_params,
|
print_params,
|
||||||
param_store);
|
param_store);
|
||||||
printer.set_is_root(true);
|
printer.set_is_root(true);
|
||||||
|
printer.set_is_first_stmt_for_hint(true);
|
||||||
if (OB_FAIL(printer.do_print())) {
|
if (OB_FAIL(printer.do_print())) {
|
||||||
LOG_WARN("fail to print insert stmt", K(ret));
|
LOG_WARN("fail to print insert stmt", K(ret));
|
||||||
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
||||||
@ -2152,6 +2154,7 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
|||||||
print_params,
|
print_params,
|
||||||
param_store);
|
param_store);
|
||||||
printer.set_is_root(true);
|
printer.set_is_root(true);
|
||||||
|
printer.set_is_first_stmt_for_hint(true);
|
||||||
if (OB_FAIL(printer.do_print())) {
|
if (OB_FAIL(printer.do_print())) {
|
||||||
LOG_WARN("fail to print insert stmt", K(ret));
|
LOG_WARN("fail to print insert stmt", K(ret));
|
||||||
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
||||||
@ -2168,6 +2171,7 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
|||||||
print_params,
|
print_params,
|
||||||
param_store);
|
param_store);
|
||||||
printer.set_is_root(true);
|
printer.set_is_root(true);
|
||||||
|
printer.set_is_first_stmt_for_hint(true);
|
||||||
if (OB_FAIL(printer.do_print())) {
|
if (OB_FAIL(printer.do_print())) {
|
||||||
LOG_WARN("fail to print delete stmt", K(ret));
|
LOG_WARN("fail to print delete stmt", K(ret));
|
||||||
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
||||||
@ -2184,6 +2188,7 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
|||||||
print_params,
|
print_params,
|
||||||
param_store);
|
param_store);
|
||||||
printer.set_is_root(true);
|
printer.set_is_root(true);
|
||||||
|
printer.set_is_first_stmt_for_hint(true);
|
||||||
if (OB_FAIL(printer.do_print())) {
|
if (OB_FAIL(printer.do_print())) {
|
||||||
LOG_WARN("fail to print update stmt", K(ret));
|
LOG_WARN("fail to print update stmt", K(ret));
|
||||||
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
||||||
@ -2200,6 +2205,7 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
|||||||
print_params,
|
print_params,
|
||||||
param_store);
|
param_store);
|
||||||
printer.set_is_root(true);
|
printer.set_is_root(true);
|
||||||
|
printer.set_is_first_stmt_for_hint(true);
|
||||||
if (OB_FAIL(printer.do_print())) {
|
if (OB_FAIL(printer.do_print())) {
|
||||||
LOG_WARN("failed to print merge stmt", K(ret));
|
LOG_WARN("failed to print merge stmt", K(ret));
|
||||||
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
||||||
|
@ -532,7 +532,7 @@ int ObCreateViewResolver::stmt_print(const ObSelectStmt *stmt,
|
|||||||
params_.schema_checker_->get_schema_guard(),
|
params_.schema_checker_->get_schema_guard(),
|
||||||
obj_print_params, true);
|
obj_print_params, true);
|
||||||
stmt_printer.set_column_list(column_list);
|
stmt_printer.set_column_list(column_list);
|
||||||
stmt_printer.set_is_root(true); // print hint as root stmt
|
stmt_printer.set_is_first_stmt_for_hint(true); // need print global hint
|
||||||
if (OB_FAIL(stmt_printer.do_print())) {
|
if (OB_FAIL(stmt_printer.do_print())) {
|
||||||
if (OB_SIZE_OVERFLOW == ret && buf_len < OB_MAX_PACKET_LENGTH) {
|
if (OB_SIZE_OVERFLOW == ret && buf_len < OB_MAX_PACKET_LENGTH) {
|
||||||
buf_len = std::min(buf_len * 2, OB_MAX_PACKET_LENGTH);
|
buf_len = std::min(buf_len * 2, OB_MAX_PACKET_LENGTH);
|
||||||
|
@ -657,7 +657,7 @@ int ObQueryHint::print_qb_name_hints(PlanText &plan_text) const
|
|||||||
// If outline_stmt_id_ is invalid stmt id and has_outline_data(), do not print hint.
|
// If outline_stmt_id_ is invalid stmt id and has_outline_data(), do not print hint.
|
||||||
// This may happened for outline data from SPM.
|
// This may happened for outline data from SPM.
|
||||||
int ObQueryHint::print_stmt_hint(PlanText &plan_text, const ObDMLStmt &stmt,
|
int ObQueryHint::print_stmt_hint(PlanText &plan_text, const ObDMLStmt &stmt,
|
||||||
const bool is_root_stmt) const
|
const bool is_first_stmt_for_hint) const
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
const int64_t stmt_id = stmt.get_stmt_id();
|
const int64_t stmt_id = stmt.get_stmt_id();
|
||||||
@ -671,13 +671,13 @@ int ObQueryHint::print_stmt_hint(PlanText &plan_text, const ObDMLStmt &stmt,
|
|||||||
} else if (!has_outline_data()) {
|
} else if (!has_outline_data()) {
|
||||||
// Not outline data, print current stmt hint here.
|
// Not outline data, print current stmt hint here.
|
||||||
// If stmt is the first stmt can add hint, print global hint and hint with qb name.
|
// If stmt is the first stmt can add hint, print global hint and hint with qb name.
|
||||||
const bool is_first_stmt = is_root_stmt;
|
// For query "select_1 union all select_2", root stmt is "union all" and the first stmt to print hint is select_1
|
||||||
if ((is_first_stmt || OB_INVALID_ID != stmt.get_dblink_id()) &&
|
if ((is_first_stmt_for_hint || OB_INVALID_ID != stmt.get_dblink_id()) &&
|
||||||
OB_FAIL(get_global_hint().print_global_hint(plan_text))) {
|
OB_FAIL(get_global_hint().print_global_hint(plan_text))) {
|
||||||
LOG_WARN("failed to print global hint", K(ret));
|
LOG_WARN("failed to print global hint", K(ret));
|
||||||
} else if (OB_FAIL(stmt.get_stmt_hint().print_stmt_hint(plan_text))) {
|
} else if (OB_FAIL(stmt.get_stmt_hint().print_stmt_hint(plan_text))) {
|
||||||
LOG_WARN("failed to print stmt hint", K(ret));
|
LOG_WARN("failed to print stmt hint", K(ret));
|
||||||
} else if (is_first_stmt) {
|
} else if (is_first_stmt_for_hint) {
|
||||||
int tmp = OB_SUCCESS;
|
int tmp = OB_SUCCESS;
|
||||||
int64_t tmp_stmt_id = OB_INVALID_STMT_ID;
|
int64_t tmp_stmt_id = OB_INVALID_STMT_ID;
|
||||||
for (int64_t i = 0; OB_SUCC(ret) && i < qb_hints_.count(); ++i) {
|
for (int64_t i = 0; OB_SUCC(ret) && i < qb_hints_.count(); ++i) {
|
||||||
|
@ -137,7 +137,7 @@ struct ObQueryHint {
|
|||||||
|| global_hint_.has_hint_exclude_concurrent(); }
|
|| global_hint_.has_hint_exclude_concurrent(); }
|
||||||
|
|
||||||
// print hint
|
// print hint
|
||||||
int print_stmt_hint(PlanText &plan_text, const ObDMLStmt &stmt, const bool is_root_stmt) const;
|
int print_stmt_hint(PlanText &plan_text, const ObDMLStmt &stmt, const bool is_first_stmt_for_hint) const;
|
||||||
int print_outline_data(PlanText &plan_text) const;
|
int print_outline_data(PlanText &plan_text) const;
|
||||||
int print_qb_name_hints(PlanText &plan_text) const;
|
int print_qb_name_hints(PlanText &plan_text) const;
|
||||||
int print_qb_name_hint(PlanText &plan_text, int64_t stmt_id) const;
|
int print_qb_name_hint(PlanText &plan_text, int64_t stmt_id) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user