// (C) Copyright 2022 Alibaba Inc. All Rights Reserved. // Authors: // link.zt <> // Normalizer: // // #ifndef OB_SHARED_EXPR_RESOLVER_H #define OB_SHARED_EXPR_RESOLVER_H #include "sql/resolver/expr/ob_raw_expr.h" namespace oceanbase { namespace sql { struct JoinedTable; struct TableItem; struct ObQuestionmarkEqualCtx : public ObExprEqualCheckContext { ObQuestionmarkEqualCtx(bool need_check_deterministic = false): ObExprEqualCheckContext(need_check_deterministic) { override_const_compare_ = true; } bool compare_const(const ObConstRawExpr &left, const ObConstRawExpr &right); ObSEArray equal_pairs_; }; struct ObRawExprEntry { ObRawExprEntry() :expr_(NULL), stmt_scope_(0), hash_code_(0) { } ObRawExprEntry(ObRawExpr *expr, uint64_t scope_id, uint64_t hash_code) : expr_(expr), stmt_scope_(scope_id), hash_code_(hash_code) {} bool compare(const ObRawExprEntry &node, ObQuestionmarkEqualCtx &cmp_ctx) const; TO_STRING_KV(K_(hash_code), K_(expr)); ObRawExpr *expr_; uint64_t stmt_scope_; uint64_t hash_code_; }; class ObSharedExprResolver { public: ObSharedExprResolver(ObQueryCtx *query_ctx) : allocator_("MergeSharedExpr"), scope_id_(0), query_ctx_(query_ctx) {} virtual ~ObSharedExprResolver(); int get_shared_instance(ObRawExpr *expr, ObRawExpr *&shared_expr, bool &is_new); int add_new_instance(ObRawExprEntry &entry); uint64_t get_scope_id() const { return scope_id_; } void set_new_scope() { scope_id_ ++; } void revert_scope() { scope_id_ = 0; } uint64_t hash_expr_tree(ObRawExpr *expr, uint64_t hash_code, const bool is_root = true); private: int inner_get_shared_expr(ObRawExprEntry &entry, ObRawExpr *&new_expr); private: typedef ObSEArray SharedExprs; ObArenaAllocator allocator_; hash::ObHashMap shared_expr_map_; uint64_t scope_id_; ObQueryCtx *query_ctx_; }; } } #endif // OB_SHARED_EXPR_RESOLVER_H