physical_operator.h 1.6 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>

W
wangyunlai.wyl 已提交
21
#include "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

羽飞's avatar
羽飞 已提交
28 29
enum class PhysicalOperatorType
{
羽飞's avatar
羽飞 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43
  TABLE_SCAN,
  INDEX_SCAN,
  NESTED_LOOP_JOIN,
  EXPLAIN,
  PREDICATE,
  PROJECT,
  STRING_LIST,
  DELETE,
  INSERT,
};

/**
 * 与LogicalOperator对应,物理算子描述执行计划将如何执行
 */
羽飞's avatar
羽飞 已提交
44 45
class PhysicalOperator
{
W
wangyunlai.wyl 已提交
46
public:
羽飞's avatar
羽飞 已提交
47
  PhysicalOperator() = default;
W
wangyunlai.wyl 已提交
48

羽飞's avatar
羽飞 已提交
49 50 51 52 53 54 55
  virtual ~PhysicalOperator();

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

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

羽飞's avatar
羽飞 已提交
59
  virtual RC open(Trx *trx) = 0;
W
wangyunlai.wyl 已提交
60 61 62
  virtual RC next() = 0;
  virtual RC close() = 0;

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

L
Longda Feng 已提交
65 66
  void add_child(std::unique_ptr<PhysicalOperator> oper)
  {
羽飞's avatar
羽飞 已提交
67
    children_.emplace_back(std::move(oper));
羽飞's avatar
羽飞 已提交
68 69
  }

L
Longda Feng 已提交
70 71 72 73
  std::vector<std::unique_ptr<PhysicalOperator>> &children()
  {
    return children_;
  }
羽飞's avatar
羽飞 已提交
74

羽飞's avatar
羽飞 已提交
75
protected:
羽飞's avatar
羽飞 已提交
76
  std::vector<std::unique_ptr<PhysicalOperator>> children_;
W
wangyunlai.wyl 已提交
77
};