physical_operator.h 1.6 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
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

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

/**
 * 与LogicalOperator对应,物理算子描述执行计划将如何执行
 */
class PhysicalOperator
44
{
W
wangyunlai.wyl 已提交
45
public:
羽飞's avatar
羽飞 已提交
46
  PhysicalOperator()
W
wangyunlai.wyl 已提交
47 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 58
  virtual PhysicalOperatorType type() const = 0;
  
W
wangyunlai.wyl 已提交
59 60 61 62
  virtual RC open() = 0;
  virtual RC next() = 0;
  virtual RC close() = 0;

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

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

羽飞's avatar
羽飞 已提交
69
  std::vector<std::unique_ptr<PhysicalOperator>> &children() { return children_; }
羽飞's avatar
羽飞 已提交
70

羽飞's avatar
羽飞 已提交
71
protected:
羽飞's avatar
羽飞 已提交
72
  std::vector<std::unique_ptr<PhysicalOperator>> children_;
W
wangyunlai.wyl 已提交
73
};