MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
table_scan_physical_operator.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by WangYunlai on 2022/6/7.
13//
14
15#pragma once
16
17#include "common/sys/rc.h"
18#include "sql/operator/physical_operator.h"
19#include "storage/record/record_manager.h"
20#include "storage/record/record_scanner.h"
21#include "common/types.h"
22
23class Table;
24
30{
31public:
32 TableScanPhysicalOperator(Table *table, ReadWriteMode mode) : table_(table), mode_(mode) {}
33
34 virtual ~TableScanPhysicalOperator() = default;
35
36 string param() const override;
37
38 PhysicalOperatorType type() const override { return PhysicalOperatorType::TABLE_SCAN; }
39 OpType get_op_type() const override { return OpType::SEQSCAN; }
40 virtual uint64_t hash() const override { return 0; }
41
42 virtual bool operator==(const OperatorNode &other) const override { return false; }
43
44 double calculate_cost(LogicalProperty *prop, const vector<LogicalProperty *> &child_log_props, CostModel *cm) override
45 {
46 return (cm->io() + cm->cpu_op()) * prop->get_card();
47 }
48
49 RC open(Trx *trx) override;
50 RC next() override;
51 RC close() override;
52
53 Tuple *current_tuple() override;
54
55 void set_predicates(vector<unique_ptr<Expression>> &&exprs);
56
57private:
58 RC filter(RowTuple &tuple, bool &result);
59
60private:
61 Table *table_ = nullptr;
62 Trx *trx_ = nullptr;
63 ReadWriteMode mode_ = ReadWriteMode::READ_WRITE;
64 RecordScanner *record_scanner_;
65 Record current_record_;
66 RowTuple tuple_;
67 vector<unique_ptr<Expression>> predicates_; // TODO chang predicate to table tuple filter
68};
cost model in cost-based optimization(CBO)
Definition: cost_model.h:19
double cpu_op()
cpu cost of building hash table
Definition: cost_model.h:32
Logical Property, such as the cardinality of logical operator
Definition: property.h:20
Definition: operator_node.h:69
与LogicalOperator对应,物理算子描述执行计划将如何执行
Definition: physical_operator.h:63
遍历某个表中所有记录
Definition: record_scanner.h:21
表示一个记录
Definition: record.h:101
一行数据的元组
Definition: tuple.h:159
表扫描物理算子
Definition: table_scan_physical_operator.h:30
virtual uint64_t hash() const override
Definition: table_scan_physical_operator.h:40
OpType get_op_type() const override
Definition: table_scan_physical_operator.h:39
double calculate_cost(LogicalProperty *prop, const vector< LogicalProperty * > &child_log_props, CostModel *cm) override
Calculates the cost of a logical operation.
Definition: table_scan_physical_operator.h:44
Definition: table.h:42
事务接口
Definition: trx.h:141
元组的抽象描述
Definition: tuple.h:66
PhysicalOperatorType
物理算子类型
Definition: physical_operator.h:36