Skip to content

Commit 7110e4a

Browse files
lf0LINxiansheng
authored andcommitted
Fix stack overflow of recursive printing raw_expr
1 parent e9dc011 commit 7110e4a

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

src/sql/resolver/expr/ob_raw_expr.h

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ class ObRawExprFactory;
5353
class ObSelectStmt;
5454
extern ObRawExpr *USELESS_POINTER;
5555

56+
// If is_stack_overflow is true, the printing will not continue
57+
#define DEFINE_VIRTUAL_TO_STRING_CHECK_STACK_OVERFLOW(body) \
58+
DECLARE_VIRTUAL_TO_STRING \
59+
{ \
60+
int ret = common::OB_SUCCESS; \
61+
int64_t pos = 0; \
62+
bool is_stack_overflow = false; \
63+
if (OB_FAIL(check_stack_overflow(is_stack_overflow))) { \
64+
SQL_RESV_LOG(WARN, "failed to check stack overflow", K(ret), K(is_stack_overflow)); \
65+
} else if (is_stack_overflow) { \
66+
SQL_RESV_LOG(DEBUG, "too deep recursive", K(ret), K(is_stack_overflow)); \
67+
} else { \
68+
J_OBJ_START(); \
69+
body; \
70+
J_OBJ_END(); \
71+
} \
72+
return pos; \
73+
}
74+
75+
#define VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(args...) DEFINE_VIRTUAL_TO_STRING_CHECK_STACK_OVERFLOW(J_KV(args))
76+
5677
// ObSqlBitSet is a simple bitset, in order to avoid memory explosure
5778
// ObBitSet is too large just for a simple bitset
5879
const static int64_t DEFAULT_SQL_BITSET_SIZE = 32;
@@ -2382,7 +2403,7 @@ class ObAliasRefRawExpr : public ObRawExpr {
23822403
virtual uint64_t hash_internal(uint64_t seed) const override;
23832404
int get_name_internal(char *buf, const int64_t buf_len, int64_t &pos, ExplainType type) const override;
23842405
virtual bool same_as(const ObRawExpr &expr, ObExprEqualCheckContext *check_context = NULL) const override;
2385-
VIRTUAL_TO_STRING_KV(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_, N_VALUE,
2406+
VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_, N_VALUE,
23862407
ref_expr_, K_(enum_set_values));
23872408

23882409
private:
@@ -2538,8 +2559,8 @@ class ObOpRawExpr : public ObNonTerminalRawExpr, public jit::expr::ObOpExpr {
25382559
int get_name_internal(char *buf, const int64_t buf_len, int64_t &pos, ExplainType type) const override;
25392560
int get_subquery_comparison_name(
25402561
const common::ObString &symbol, char *buf, int64_t buf_len, int64_t &pos, ExplainType type) const;
2541-
VIRTUAL_TO_STRING_KV(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
2542-
K_(expr_levels), N_CHILDREN, exprs_);
2562+
VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_,
2563+
N_REL_ID, rel_ids_, K_(expr_levels), N_CHILDREN, exprs_);
25432564

25442565
protected:
25452566
common::ObSEArray<ObRawExpr *, COMMON_MULTI_NUM, common::ModulePageAllocator, true> exprs_;
@@ -2706,7 +2727,7 @@ class ObCaseOpRawExpr : public ObNonTerminalRawExpr, public jit::expr::ObCaseOpE
27062727
virtual uint64_t hash_internal(uint64_t seed) const override;
27072728

27082729
int get_name_internal(char *buf, const int64_t buf_len, int64_t &pos, ExplainType type) const override;
2709-
VIRTUAL_TO_STRING_KV(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
2730+
VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
27102731
K_(expr_levels), N_ARG_CASE, arg_expr_, N_DEFAULT, default_expr_, N_WHEN, when_exprs_, N_THEN, then_exprs_,
27112732
N_DECODE, is_decode_func_);
27122733

@@ -3003,9 +3024,10 @@ class ObAggFunRawExpr : public ObRawExpr {
30033024

30043025
int get_name_internal(char *buf, const int64_t buf_len, int64_t &pos, ExplainType type) const override;
30053026
const char *get_name_dblink(ObItemType expr_type) const;
3006-
VIRTUAL_TO_STRING_KV(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
3007-
K_(expr_level), K_(expr_levels), N_CHILDREN, real_param_exprs_, N_DISTINCT, distinct_, N_ORDER_BY, order_items_,
3008-
N_SEPARATOR_PARAM_EXPR, separator_param_expr_, K_(udf_meta), N_LINEAR_INTER_EXPR, linear_inter_expr_);
3027+
VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_,
3028+
N_REL_ID, rel_ids_, K_(expr_level), K_(expr_levels), N_CHILDREN, real_param_exprs_, N_DISTINCT, distinct_,
3029+
N_ORDER_BY, order_items_, N_SEPARATOR_PARAM_EXPR, separator_param_expr_, K_(udf_meta), N_LINEAR_INTER_EXPR,
3030+
linear_inter_expr_);
30093031

30103032
private:
30113033
DISALLOW_COPY_AND_ASSIGN(ObAggFunRawExpr);
@@ -3163,8 +3185,8 @@ class ObSysFunRawExpr : public ObOpRawExpr {
31633185
return operator_id_;
31643186
}
31653187

3166-
VIRTUAL_TO_STRING_KV(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
3167-
K_(expr_levels), N_FUNC, func_name_, N_CHILDREN, exprs_, K_(enum_set_values));
3188+
VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_,
3189+
N_REL_ID, rel_ids_, K_(expr_levels), N_FUNC, func_name_, N_CHILDREN, exprs_, K_(enum_set_values));
31683190

31693191
private:
31703192
int check_param_num_internal(int32_t param_num, int32_t param_count, ObExprOperatorType type);
@@ -3256,12 +3278,12 @@ class ObPLSQLCodeSQLErrmRawExpr : public ObSysFunRawExpr {
32563278
{
32573279
is_sqlcode_ = is_sqlcode;
32583280
}
3259-
bool get_is_sqlcode()
3281+
bool get_is_sqlcode() const
32603282
{
32613283
return is_sqlcode_;
32623284
}
3263-
VIRTUAL_TO_STRING_KV(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
3264-
K_(expr_level), K_(expr_levels), K_(is_sqlcode), N_CHILDREN, exprs_);
3285+
VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_,
3286+
N_REL_ID, rel_ids_, K_(expr_level), K_(expr_levels), K_(is_sqlcode), N_CHILDREN, exprs_);
32653287

32663288
private:
32673289
DISALLOW_COPY_AND_ASSIGN(ObPLSQLCodeSQLErrmRawExpr);
@@ -3862,7 +3884,7 @@ class ObWinFunRawExpr : public ObRawExpr, public ObWindow {
38623884
virtual uint64_t hash_internal(uint64_t seed) const override;
38633885

38643886
int get_name_internal(char *buf, const int64_t buf_len, int64_t &pos, ExplainType type) const override;
3865-
VIRTUAL_TO_STRING_KV(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
3887+
VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
38663888
K_(expr_level), K_(expr_levels), K_(func_type), K_(is_distinct), K_(func_params), K_(partition_exprs),
38673889
K_(order_items), K_(win_type), K_(is_between), K_(upper), K_(lower), KPC_(agg_expr));
38683890

0 commit comments

Comments
 (0)