patch 4.0
This commit is contained in:
@ -20,13 +20,15 @@
|
||||
#include "lib/charset/ob_charset.h"
|
||||
#include "sql/parser/ob_parser_utils.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace sql {
|
||||
|
||||
struct ObMPParseStat {
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
class ObSQLSessionInfo;
|
||||
class ObMPParseStat
|
||||
{
|
||||
public:
|
||||
ObMPParseStat() : parse_fail_(false), fail_ret_(common::OB_SUCCESS), fail_query_idx_(-1)
|
||||
{}
|
||||
ObMPParseStat() : parse_fail_(false), fail_ret_(common::OB_SUCCESS), fail_query_idx_(-1) {}
|
||||
void reset()
|
||||
{
|
||||
parse_fail_ = false;
|
||||
@ -38,22 +40,36 @@ public:
|
||||
int64_t fail_query_idx_;
|
||||
};
|
||||
|
||||
struct PreParseResult {
|
||||
struct PreParseResult
|
||||
{
|
||||
common::ObString trace_id_;
|
||||
};
|
||||
|
||||
class ObParser {
|
||||
class ObParser
|
||||
{
|
||||
public:
|
||||
explicit ObParser(common::ObIAllocator& allocator, ObSQLMode mode,
|
||||
common::ObCollationType conn_collation = common::CS_TYPE_UTF8MB4_GENERAL_CI);
|
||||
explicit ObParser(common::ObIAllocator &allocator, ObSQLMode mode,
|
||||
common::ObCollationType conn_collation = common::CS_TYPE_UTF8MB4_GENERAL_CI);
|
||||
virtual ~ObParser();
|
||||
/// @param queries Note that all three members of ObString is valid, size() is the length
|
||||
/// of the single statement, length() is the length of remainer statements
|
||||
static bool is_pl_stmt(const common::ObString& stmt, bool* is_create_func = NULL);
|
||||
bool is_single_stmt(const common::ObString& stmt);
|
||||
int split_multiple_stmt(const common::ObString& stmt, common::ObIArray<common::ObString>& queries,
|
||||
ObMPParseStat& parse_fail, bool is_ret_first_stmt = false);
|
||||
bool is_single_stmt(const common::ObString &stmt);
|
||||
int split_start_with_pl(const common::ObString &stmt,
|
||||
common::ObIArray<common::ObString> &queries,
|
||||
ObMPParseStat &parse_fail);
|
||||
int split_multiple_stmt(const common::ObString &stmt,
|
||||
common::ObIArray<common::ObString> &queries,
|
||||
ObMPParseStat &parse_fail,
|
||||
bool is_ret_first_stmt=false,
|
||||
bool is_prepare = false);
|
||||
void get_single_sql(const common::ObString &stmt, int64_t offset, int64_t remain, int64_t &str_len);
|
||||
|
||||
int check_is_insert(common::ObIArray<common::ObString> &queries, bool &is_ins);
|
||||
int reconstruct_insert_sql(const common::ObString &stmt,
|
||||
common::ObIArray<common::ObString> &queries,
|
||||
common::ObIArray<common::ObString> &ins_queries,
|
||||
bool &can_batch_exec);
|
||||
|
||||
//@param:
|
||||
// no_throw_parser_error is used to mark not throw parser error. in the split multi stmt
|
||||
// situation we will try find ';' delimiter to parser part of string in case of save memory,
|
||||
@ -61,36 +77,109 @@ public:
|
||||
// string when parse part of string failed, if we throw parse part error info, maybe will let
|
||||
// someone misunderstand have bug, So, we introduce this mark to decide to throw parser erorr.
|
||||
// eg: select '123;' from dual; select '123' from dual;
|
||||
int parse_sql(const common::ObString& stmt, ParseResult& parse_result,
|
||||
const bool no_throw_parser_error = false);
|
||||
int parse_sql(const common::ObString &stmt,
|
||||
ParseResult &parse_result,
|
||||
const bool no_throw_parser_error);
|
||||
|
||||
virtual int parse(const common::ObString& stmt, ParseResult& parse_result, ParseMode mode = STD_MODE,
|
||||
const bool is_batched_multi_stmt_split_on = false, const bool no_throw_parser_error = false);
|
||||
virtual int parse(const common::ObString &stmt,
|
||||
ParseResult &parse_result,
|
||||
ParseMode mode=STD_MODE,
|
||||
const bool is_batched_multi_stmt_split_on = false,
|
||||
const bool is_normal_ps_prepare = false,
|
||||
const bool no_throw_parser_error = false);
|
||||
|
||||
virtual void free_result(ParseResult& parse_result);
|
||||
virtual void free_result(ParseResult &parse_result);
|
||||
/**
|
||||
* @brief The parse interface for prepare
|
||||
* @param [in] query - To be parsed statement
|
||||
* @param [in] ns - External namespace
|
||||
* @param [out] parse_result - parse result
|
||||
* @brief 供prepare使用的parse接口
|
||||
* @param [in] query - 待parse语句
|
||||
* @param [in] ns - 外部名称空间
|
||||
* @param [out] parse_result - parse结果
|
||||
* @retval OB_SUCCESS execute success
|
||||
* @retval OB_SOME_ERROR special errno need to handle
|
||||
*
|
||||
* Compared with general prepare, the external name space is passed in and the redundant process
|
||||
* that this path will not go to is simplified. The main idea is that in the process of parser,
|
||||
* whenever you encounter a variable in sql, try to find it in the pl namespace. If you can find
|
||||
* it, copy the SQL statement before this variable and rewrite this variable as question mark,Also
|
||||
* record this variable.At the same time, all objects (tables, views, functions) encountered are
|
||||
* also recorded.
|
||||
* 和通用prepare相比,传入了外部名称空间,并简化了此路径不会走到的冗余流程。
|
||||
* 其主要思想是在parser的过程中,每当遇到一个sql中的变量,就尝试去pl名字空间
|
||||
* 查找,如果找得到,把这个变量之前的sql语句拷贝出来,并把此变量改写为question mark,
|
||||
* 同时记录下这个变量。
|
||||
* 同时,把遇到的所有对象(表、视图、函数)也都记录下来。
|
||||
*
|
||||
*/
|
||||
int prepare_parse(const common::ObString& query, void* ns, ParseResult& parse_result);
|
||||
static int pre_parse(const common::ObString& stmt, PreParseResult& res);
|
||||
int prepare_parse(const common::ObString &query, void *ns, ParseResult &parse_result);
|
||||
static int pre_parse(const common::ObString &stmt,
|
||||
PreParseResult &res);
|
||||
|
||||
enum State {
|
||||
S_START,
|
||||
S_COMMENT,
|
||||
S_C_COMMENT,
|
||||
S_NORMAL,
|
||||
S_INVALID,
|
||||
|
||||
S_CREATE,
|
||||
S_DO,
|
||||
S_DD,
|
||||
S_DECLARE,
|
||||
S_BEGIN,
|
||||
S_DROP,
|
||||
S_CALL,
|
||||
S_ALTER,
|
||||
S_UPDATE,
|
||||
S_FUNCTION,
|
||||
S_PROCEDURE,
|
||||
S_PACKAGE,
|
||||
S_TRIGGER,
|
||||
S_TYPE,
|
||||
S_OR,
|
||||
S_REPLACE,
|
||||
S_DEFINER,
|
||||
S_OF,
|
||||
S_EDITIONABLE,
|
||||
|
||||
S_EXPLAIN,
|
||||
S_EXPLAIN_FORMAT,
|
||||
S_EXPLAIN_BASIC,
|
||||
S_EXPLAIN_EXTENDED,
|
||||
S_EXPLAIN_EXTENDED_NOADDR,
|
||||
S_EXPLAIN_PARTITIONS,
|
||||
|
||||
// add new states above me
|
||||
S_MAX
|
||||
};
|
||||
|
||||
static State transform_normal(common::ObString &normal);
|
||||
static State transform_normal(
|
||||
State state, common::ObString &normal, bool &is_pl, bool &is_not_pl,
|
||||
bool *is_create_func, bool *is_call_procedure);
|
||||
|
||||
static bool is_pl_stmt(const common::ObString &stmt,
|
||||
bool *is_create_func = NULL,
|
||||
bool *is_call_procedure = NULL);
|
||||
static bool is_explain_stmt(const common::ObString &stmt,
|
||||
const char *&p_normal_start);
|
||||
private:
|
||||
static int scan_trace_id(const char* ptr, int64_t len, int32_t& pos, common::ObString& trace_id);
|
||||
static int scan_trace_id(const char *ptr,
|
||||
int64_t len,
|
||||
int32_t &pos,
|
||||
common::ObString &trace_id);
|
||||
static bool is_trace_id_end(char ch);
|
||||
static bool is_space(char ch);
|
||||
static int32_t get_well_formed_errlen(const struct ObCharsetInfo *charset_info,
|
||||
const char *err_begin,
|
||||
int32_t err_len);
|
||||
static void match_state(const char*&p,
|
||||
bool &is_explain,
|
||||
bool &has_error,
|
||||
const char *lower[S_MAX],
|
||||
const char *upper[S_MAX],
|
||||
int &i,
|
||||
State &save_state,
|
||||
State &state,
|
||||
State next_state);
|
||||
static bool is_comment(const char *&p,
|
||||
const char *&p_end,
|
||||
State &save_state,
|
||||
State &state,
|
||||
State error_state);
|
||||
// types and constants
|
||||
private:
|
||||
// disallow copy
|
||||
@ -98,14 +187,14 @@ private:
|
||||
// function members
|
||||
private:
|
||||
// data members
|
||||
common::ObIAllocator* allocator_;
|
||||
common::ObIAllocator *allocator_;
|
||||
// when sql_mode = "ANSI_QUOTES", Treat " as an identifier quote character
|
||||
// we don't use it in parser now
|
||||
ObSQLMode sql_mode_;
|
||||
common::ObCollationType connection_collation_;
|
||||
};
|
||||
|
||||
} // end namespace sql
|
||||
} // end namespace oceanbase
|
||||
} // end namespace sql
|
||||
} // end namespace oceanbase
|
||||
|
||||
#endif /* _OB_PARSER_H */
|
||||
|
||||
Reference in New Issue
Block a user