physical_operator.h 1.9 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
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 PSL v2 for more details. */

//
羽飞's avatar
羽飞 已提交
12
// Created by WangYunlai on 2022/6/7.
羽飞's avatar
羽飞 已提交
13 14
//

W
wangyunlai.wyl 已提交
15
#pragma once
羽飞's avatar
羽飞 已提交
16

羽飞's avatar
羽飞 已提交
17
#include <vector>
羽飞's avatar
羽飞 已提交
18 19 20
#include <memory>
#include <string>

羽飞's avatar
羽飞 已提交
21
#include "common/rc.h"
羽飞's avatar
羽飞 已提交
22
#include "sql/expr/tuple.h"
羽飞's avatar
羽飞 已提交
23

羽飞's avatar
羽飞 已提交
24
class Record;
羽飞's avatar
羽飞 已提交
25
class TupleCellSpec;
羽飞's avatar
羽飞 已提交
26
class Trx;
羽飞's avatar
羽飞 已提交
27

28 29 30 31 32 33 34 35 36 37
/**
 * @brief 物理算子
 * @defgroup PhysicalOperator
 * @details 物理算子描述执行计划将如何执行,比如从表中怎么获取数据,如何做投影,怎么做连接等
 */

/**
 * @brief 物理算子类型
 * @ingroup PhysicalOperator
 */
羽飞's avatar
羽飞 已提交
38 39
enum class PhysicalOperatorType
{
羽飞's avatar
羽飞 已提交
40 41 42 43 44 45 46 47 48 49 50 51
  TABLE_SCAN,
  INDEX_SCAN,
  NESTED_LOOP_JOIN,
  EXPLAIN,
  PREDICATE,
  PROJECT,
  STRING_LIST,
  DELETE,
  INSERT,
};

/**
52 53
 * @brief 与LogicalOperator对应,物理算子描述执行计划将如何执行
 * @ingroup PhysicalOperator
羽飞's avatar
羽飞 已提交
54
 */
羽飞's avatar
羽飞 已提交
55 56
class PhysicalOperator
{
W
wangyunlai.wyl 已提交
57
public:
羽飞's avatar
羽飞 已提交
58
  PhysicalOperator() = default;
W
wangyunlai.wyl 已提交
59

羽飞's avatar
羽飞 已提交
60 61 62 63 64 65 66
  virtual ~PhysicalOperator();

  /**
   * 这两个函数是为了打印时使用的,比如在explain中
   */
  virtual std::string name() const;
  virtual std::string param() const;
W
wangyunlai.wyl 已提交
67

羽飞's avatar
羽飞 已提交
68
  virtual PhysicalOperatorType type() const = 0;
L
Longda Feng 已提交
69

羽飞's avatar
羽飞 已提交
70
  virtual RC open(Trx *trx) = 0;
W
wangyunlai.wyl 已提交
71 72 73
  virtual RC next() = 0;
  virtual RC close() = 0;

L
Longda Feng 已提交
74
  virtual Tuple *current_tuple() = 0;
羽飞's avatar
羽飞 已提交
75

L
Longda Feng 已提交
76 77
  void add_child(std::unique_ptr<PhysicalOperator> oper)
  {
羽飞's avatar
羽飞 已提交
78
    children_.emplace_back(std::move(oper));
羽飞's avatar
羽飞 已提交
79 80
  }

L
Longda Feng 已提交
81 82 83 84
  std::vector<std::unique_ptr<PhysicalOperator>> &children()
  {
    return children_;
  }
羽飞's avatar
羽飞 已提交
85

羽飞's avatar
羽飞 已提交
86
protected:
羽飞's avatar
羽飞 已提交
87
  std::vector<std::unique_ptr<PhysicalOperator>> children_;
W
wangyunlai.wyl 已提交
88
};