ob_transform_view_merge.h 4.1 KB
Newer Older
O
oceanbase-admin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * Copyright (c) 2021 OceanBase
 * OceanBase CE is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#ifndef _OB_TRANSFORM_VIEW_MERGE_H
#define _OB_TRANSFORM_VIEW_MERGE_H

#include "sql/rewrite/ob_transform_rule.h"
#include "sql/resolver/dml/ob_select_stmt.h"
#include "sql/resolver/dml/ob_update_stmt.h"

namespace oceanbase {

namespace common {
class ObIAllocator;
}

namespace sql {

class ObDelUpdStmt;

class ObTransformViewMerge : public ObTransformRule {
G
gm 已提交
31
public:
O
oceanbase-admin 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44
  ObTransformViewMerge(ObTransformerCtx* ctx) : ObTransformRule(ctx, TransMethod::POST_ORDER), for_post_process_(false)
  {}
  virtual ~ObTransformViewMerge()
  {}

  void set_for_post_process(bool for_post_process)
  {
    for_post_process_ = for_post_process;
  }

  virtual int transform_one_stmt(
      common::ObIArray<ObParentDMLStmt>& parent_stmts, ObDMLStmt*& stmt, bool& trans_happened) override;

G
gm 已提交
45
private:
O
oceanbase-admin 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  struct ViewMergeHelper {
    ViewMergeHelper()
        : parent_table(NULL),
          trans_table(NULL),
          not_null_column(NULL),
          need_check_null_propagate(false),
          can_push_where(true)
    {}
    virtual ~ViewMergeHelper()
    {}

    JoinedTable* parent_table;
    TableItem* trans_table;
    ObRawExpr* not_null_column;
    bool need_check_null_propagate;
    bool can_push_where;
  };
  int check_can_be_unnested(ObDMLStmt* parent_stmt, ObSelectStmt* child_stmt, ViewMergeHelper& helper,
      bool need_check_subquery, bool& can_be);

  int check_semi_right_table_can_be_merged(ObDMLStmt* stmt, SemiInfo* semi_info, bool& can_be);

  int check_basic_validity(ObDMLStmt* parent_stmt, ObSelectStmt* child_stmt, bool& can_be);

  int find_not_null_column(ObDMLStmt& parent_stmt, ObSelectStmt& child_stmt, ViewMergeHelper& helper,
      ObIArray<ObRawExpr*>& column_exprs, bool& can_be);

  int find_not_null_column_with_condition(
      ObDMLStmt& parent_stmt, ObSelectStmt& child_stmt, ViewMergeHelper& helper, ObIArray<ObRawExpr*>& column_exprs);

  int find_null_propagate_column(
      ObRawExpr* condition, ObIArray<ObRawExpr*>& columns, ObRawExpr*& null_propagate_column, bool& is_valid);

  int do_view_merge_transformation(
      ObDMLStmt* parent_stmt, ObSelectStmt* child_stmt, TableItem* table_item, ViewMergeHelper& helper);

  int do_view_merge_for_semi_right_table(ObDMLStmt* parent_stmt, SemiInfo* semi_info);

  int replace_stmt_exprs(ObDMLStmt* parent_stmt, ObSelectStmt* child_stmt, uint64_t table_id, ViewMergeHelper& helper,
      bool need_wrap_case_when);

  int wrap_case_when_if_necessary(ObSelectStmt& child_stmt, ViewMergeHelper& helper, ObIArray<ObRawExpr*>& exprs);

  int wrap_case_when(ObSelectStmt& child_stmt, ObRawExpr* not_null_column, ObRawExpr*& expr);

  int adjust_stmt_hints(ObDMLStmt* parent_stmt, ObSelectStmt* child_stmt, TableItem* table_item);
  int adjust_stmt_semi_infos(ObDMLStmt* parent_stmt, ObSelectStmt* child_stmt, uint64_t table_id);

  int adjust_updatable_view(ObDMLStmt* parent_stmt, TableItem* table_item);

  int transform_joined_table(ObDMLStmt* stmt, JoinedTable* parent_table, bool can_push_where, bool& trans_happened);
  int create_joined_table_for_view(ObSelectStmt* child_stmt, TableItem*& new_table);
  int transform_generated_table(ObDMLStmt* parent_stmt, JoinedTable* parent_table, TableItem* table_item,
      bool need_check_where_condi, bool can_push_where, bool& trans_happened);
  int transform_generated_table(ObDMLStmt* parent_stmt, TableItem* table_item, bool& trans_happened);
  int transform_in_from_item(ObDMLStmt* stmt, bool& trans_happened);
  int transform_in_semi_info(ObDMLStmt* stmt, bool& trans_happened);
  bool for_post_process_;
  DISALLOW_COPY_AND_ASSIGN(ObTransformViewMerge);
};

}  // namespace sql
}  // namespace oceanbase

#endif /* _OB_TRANSFORM_VIEW_MERGE_H */