This repository was archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 618
/
Copy pathstatement.h
132 lines (92 loc) · 3.6 KB
/
statement.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//===----------------------------------------------------------------------===//
//
// Peloton
//
// statement.h
//
// Identification: src/include/common/statement.h
//
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//
#pragma once
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "common/printable.h"
#include "internal_types.h"
#include "parser/sql_statement.h"
namespace peloton {
namespace planner {
class AbstractPlan;
} // namespace planner
// Contains the value of a column in a tuple of the result set.
// std::string since the result is sent to the client over the network.
// Previously it used to be StatementResult of type
// std::pair<std::vector<unsigned char>, std::vector<unsigned char>>.
using ResultValue = std::string;
// FIELD INFO TYPE : field name, oid (data type), size
typedef std::tuple<std::string, oid_t, size_t> FieldInfo;
class Statement : public Printable {
public:
Statement() = delete;
Statement(const Statement &) = delete;
Statement &operator=(const Statement &) = delete;
Statement(Statement &&) = delete;
Statement &operator=(Statement &&) = delete;
Statement(const std::string &statement_name, const std::string &query_string);
Statement(const std::string &statement_name, QueryType query_type,
std::string query_string,
std::unique_ptr<parser::SQLStatementList> sql_stmt_list);
~Statement();
std::vector<FieldInfo> GetTupleDescriptor() const;
void SetStatementName(const std::string &statement_name);
std::string GetStatementName() const;
void SetQueryString(const std::string &query_string);
std::string GetQueryString() const;
std::string GetQueryTypeString() const;
QueryType GetQueryType() const;
void SetParamTypes(const std::vector<PostgresValueType> ¶m_types);
std::vector<PostgresValueType> GetParamTypes() const;
void SetTupleDescriptor(const std::vector<FieldInfo> &tuple_descriptor);
void SetReferencedTables(std::set<oid_t> table_ids);
const std::set<oid_t> GetReferencedTables() const;
void SetPlanTree(std::shared_ptr<planner::AbstractPlan> plan_tree);
const std::shared_ptr<planner::AbstractPlan> &GetPlanTree() const;
const std::unique_ptr<parser::SQLStatementList> &GetStmtParseTreeList() {
return sql_stmt_list_;
}
std::unique_ptr<parser::SQLStatementList> PassStmtParseTreeList() {
return std::move(sql_stmt_list_);
}
inline bool GetNeedsReplan() const { return (needs_replan_); }
inline void SetNeedsReplan(bool replan) { needs_replan_ = replan; }
// Get a string representation for debugging
const std::string GetInfo() const override;
private:
// logical name of statement
std::string statement_name_;
// enum value of query_type
QueryType query_type_;
// query string
std::string query_string_;
// query parse tree
std::unique_ptr<parser::SQLStatementList> sql_stmt_list_;
// first token in query
// Keep the string token of the query_type because it is returned as responses
// after executing commands.
std::string query_type_string_;
// format codes of the parameters
std::vector<PostgresValueType> param_types_;
// schema of result tuple
std::vector<FieldInfo> tuple_descriptor_;
// cached plan tree
std::shared_ptr<planner::AbstractPlan> plan_tree_;
// the oids of the tables referenced by this statement
// this may be empty
std::set<oid_t> table_ids_;
// If this flag is true, then somebody wants us to replan this query
bool needs_replan_ = false;
};
} // namespace peloton