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

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

/**
 * 与LogicalOperator对应,物理算子描述执行计划将如何执行
 */
L
Longda Feng 已提交
42
class PhysicalOperator {
W
wangyunlai.wyl 已提交
43
public:
羽飞's avatar
羽飞 已提交
44
  PhysicalOperator()
W
wangyunlai.wyl 已提交
45 46
  {}

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

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

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

W
wangyunlai.wyl 已提交
57 58 59 60
  virtual RC open() = 0;
  virtual RC next() = 0;
  virtual RC close() = 0;

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

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

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

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