Restore query string in session when change it.
This commit is contained in:
parent
bc1c4b7599
commit
b82a6210d4
@ -19,9 +19,9 @@
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace common
|
||||
{
|
||||
class ObObj;
|
||||
}
|
||||
{
|
||||
class ObObj;
|
||||
}
|
||||
|
||||
namespace observer
|
||||
{
|
||||
@ -33,9 +33,9 @@ public:
|
||||
virtual ~ObInfoSchemaDiskStatTable();
|
||||
virtual int inner_get_next_row(common::ObNewRow *&row);
|
||||
virtual void reset();
|
||||
inline void set_addr(common::ObAddr &addr) {addr_ = &addr;}
|
||||
virtual int set_ip(common::ObAddr *addr);
|
||||
|
||||
inline void set_addr(common::ObAddr &addr) {addr_ = &addr;}
|
||||
virtual int set_ip(common::ObAddr *addr);
|
||||
|
||||
private:
|
||||
enum DISK_COLUMN
|
||||
{
|
||||
@ -56,6 +56,6 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif /* OCEANBASE_OBSERVER_VIRTUAL_TABLE_OB_DISK_STAT_TABLE */
|
||||
|
||||
}
|
||||
#endif /* OCEANBASE_OBSERVER_VIRTUAL_TABLE_OB_DISK_STAT_TABLE */
|
||||
|
||||
|
@ -65,14 +65,20 @@ namespace sql
|
||||
{
|
||||
|
||||
ObSqlPlan::ObSqlPlan(common::ObIAllocator &allocator)
|
||||
:allocator_(allocator)
|
||||
:allocator_(allocator),
|
||||
save_nested_count_(-1),
|
||||
saved_session_(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ObSqlPlan::~ObSqlPlan()
|
||||
{
|
||||
|
||||
save_nested_count_ = -1;
|
||||
if (OB_NOT_NULL(saved_session_)) {
|
||||
allocator_.free(saved_session_);
|
||||
saved_session_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int ObSqlPlan::store_sql_plan(ObLogPlan* log_plan, ObPhysicalPlan* phy_plan)
|
||||
@ -235,6 +241,8 @@ int ObSqlPlan::inner_store_sql_plan_for_explain(ObExecContext *ctx,
|
||||
} else if (OB_ISNULL(conn)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpect null sql connection", K(ret));
|
||||
} else if (OB_FAIL(prepare_and_store_session(session))) {
|
||||
LOG_WARN("failed to begin nested session", K(ret));
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < sql_plan_infos.count(); ++i) {
|
||||
ObSqlPlanItem *plan_item = sql_plan_infos.at(i);
|
||||
@ -370,6 +378,15 @@ int ObSqlPlan::inner_store_sql_plan_for_explain(ObExecContext *ctx,
|
||||
OB_NOT_NULL(ctx->get_sql_proxy())) {
|
||||
ctx->get_sql_proxy()->close(conn, ret);
|
||||
}
|
||||
if (OB_NOT_NULL(session)) {
|
||||
int end_ret = restore_session(session);
|
||||
if (OB_SUCCESS != end_ret) {
|
||||
LOG_WARN("failed to restore session", K(end_ret), K(ret));
|
||||
if (OB_SUCCESS == ret) {
|
||||
ret = end_ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2308,5 +2325,42 @@ int ObSqlPlan::plan_text_to_strings(PlanText &plan_text,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSqlPlan::prepare_and_store_session(ObSQLSessionInfo *session) {
|
||||
int ret = OB_SUCCESS;
|
||||
void *ptr = NULL;
|
||||
if (OB_ISNULL(session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected session value", K(ret));
|
||||
} else if (OB_ISNULL(ptr = allocator_.alloc(sizeof(ObSQLSessionInfo::StmtSavedValue)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed to alloc memory for saved session value", K(ret));
|
||||
} else {
|
||||
saved_session_ = new(ptr) sql::ObSQLSessionInfo::StmtSavedValue();
|
||||
if (OB_FAIL(session->save_session(*saved_session_))) {
|
||||
LOG_WARN("failed to save session", K(ret));
|
||||
} else {
|
||||
save_nested_count_ = session->get_nested_count();
|
||||
session->set_query_start_time(ObTimeUtility::current_time());
|
||||
session->set_inner_session();
|
||||
session->set_nested_count(-1);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSqlPlan::restore_session(ObSQLSessionInfo *session) {
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(session) || OB_ISNULL(saved_session_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected session value or saved session value", K(ret));
|
||||
} else if (OB_FAIL(session->restore_session(*saved_session_))) {
|
||||
LOG_WARN("failed to restore session", K(ret));
|
||||
} else {
|
||||
session->set_nested_count(save_nested_count_);
|
||||
saved_session_->reset();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // end of namespace sql
|
||||
} // end of namespace oceanbase
|
||||
|
@ -263,6 +263,10 @@ private:
|
||||
|
||||
int refine_buffer(PlanText &plan_text);
|
||||
|
||||
int prepare_and_store_session(ObSQLSessionInfo *session);
|
||||
|
||||
int restore_session(ObSQLSessionInfo *session);
|
||||
|
||||
public:
|
||||
static int format_one_output_expr(char *buf,
|
||||
int64_t buf_len,
|
||||
@ -275,6 +279,8 @@ public:
|
||||
|
||||
private:
|
||||
common::ObIAllocator &allocator_;
|
||||
int64_t save_nested_count_;
|
||||
ObSQLSessionInfo::StmtSavedValue *saved_session_;
|
||||
};
|
||||
|
||||
} // end of namespace sql
|
||||
|
@ -1500,7 +1500,6 @@ int ObSql::handle_ps_prepare(const ObString &stmt,
|
||||
// open_cursors is 0 to indicate a special state, no limit is set
|
||||
#define NEED_CHECK_SESS_MAX_PS_HANDLE_LIMIT(v) (0 == v ? false : true)
|
||||
int ret = OB_SUCCESS;
|
||||
ObString cur_query;
|
||||
// trimed_stmt仅用于query empty检查, prepare语句需要用原始语句, 避免checksum不一致
|
||||
ObString trimed_stmt = const_cast<ObString &>(stmt).trim();
|
||||
if (trimed_stmt.empty()) {
|
||||
@ -1514,7 +1513,6 @@ int ObSql::handle_ps_prepare(const ObString &stmt,
|
||||
ObSQLSessionInfo &session = result.get_session();
|
||||
ObPsCache *ps_cache = session.get_ps_cache();
|
||||
ObExecContext &ectx = result.get_exec_context();
|
||||
ObIAllocator &allocator = result.get_mem_pool();
|
||||
ObPhysicalPlanCtx *pctx = ectx.get_physical_plan_ctx();
|
||||
ObSchemaGetterGuard *schema_guard = context.schema_guard_;
|
||||
ectx.set_is_ps_prepare_stage(true);
|
||||
@ -1528,8 +1526,6 @@ int ObSql::handle_ps_prepare(const ObString &stmt,
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_ERROR("physical plan context or ps plan cache is NULL or schema_guard is null",
|
||||
K(ret), K(pctx), K(ps_cache));
|
||||
} else if (OB_FAIL(ob_write_string(allocator, session.get_current_query_string(), cur_query))) {
|
||||
LOG_WARN("failed to write string", K(ret));
|
||||
} else if (OB_FAIL(session.store_query_string(trimed_stmt))) {
|
||||
LOG_WARN("store query string fail", K(ret));
|
||||
} else {
|
||||
@ -1645,7 +1641,6 @@ int ObSql::handle_ps_prepare(const ObString &stmt,
|
||||
}
|
||||
}
|
||||
}
|
||||
OZ (session.store_query_string(cur_query));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user