YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/yql/pggate/pg_statement.h
Line
Count
Source (jump to first uncovered line)
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//--------------------------------------------------------------------------------------------------
14
15
#ifndef YB_YQL_PGGATE_PG_STATEMENT_H_
16
#define YB_YQL_PGGATE_PG_STATEMENT_H_
17
18
#include <stdint.h>
19
20
#include <set>
21
#include <string>
22
#include <type_traits>
23
#include <unordered_set>
24
#include <utility>
25
#include <vector>
26
27
#include <boost/intrusive/list.hpp>
28
29
#include "yb/common/entity_ids.h"
30
#include "yb/common/pg_types.h"
31
#include "yb/common/ybc_util.h"
32
33
#include "yb/gutil/ref_counted.h"
34
35
#include "yb/util/bytes_formatter.h"
36
37
#include "yb/yql/pggate/pg_env.h"
38
#include "yb/yql/pggate/pg_expr.h"
39
#include "yb/yql/pggate/pg_memctx.h"
40
#include "yb/yql/pggate/pg_session.h"
41
42
namespace yb {
43
namespace pggate {
44
45
// Statement types.
46
// - Might use it for error reporting or debugging or if different operations share the same
47
//   CAPI calls.
48
// - TODO(neil) Remove StmtOp if we don't need it.
49
enum class StmtOp {
50
  STMT_NOOP = 0,
51
  STMT_CREATE_DATABASE,
52
  STMT_DROP_DATABASE,
53
  STMT_CREATE_SCHEMA,
54
  STMT_DROP_SCHEMA,
55
  STMT_CREATE_TABLE,
56
  STMT_DROP_TABLE,
57
  STMT_TRUNCATE_TABLE,
58
  STMT_CREATE_INDEX,
59
  STMT_DROP_INDEX,
60
  STMT_ALTER_TABLE,
61
  STMT_INSERT,
62
  STMT_UPDATE,
63
  STMT_DELETE,
64
  STMT_TRUNCATE,
65
  STMT_SELECT,
66
  STMT_ALTER_DATABASE,
67
  STMT_CREATE_TABLEGROUP,
68
  STMT_DROP_TABLEGROUP,
69
  STMT_SAMPLE,
70
};
71
72
class PgStatement : public PgMemctx::Registrable {
73
 public:
74
  //------------------------------------------------------------------------------------------------
75
  // Constructors.
76
  // pg_session is the session that this statement belongs to. If PostgreSQL cancels the session
77
  // while statement is running, pg_session::sharedptr can still be accessed without crashing.
78
  explicit PgStatement(PgSession::ScopedRefPtr pg_session);
79
  virtual ~PgStatement();
80
81
0
  const PgSession::ScopedRefPtr& pg_session() {
82
0
    return pg_session_;
83
0
  }
84
85
  // Statement type.
86
  virtual StmtOp stmt_op() const = 0;
87
88
  //------------------------------------------------------------------------------------------------
89
4.76M
  static bool IsValidStmt(PgStatement* stmt, StmtOp op) {
90
4.76M
    return (
stmt != nullptr4.76M
&& stmt->stmt_op() == op);
91
4.76M
  }
92
93
  //------------------------------------------------------------------------------------------------
94
  // Add expressions that are belong to this statement.
95
  void AddExpr(PgExpr::SharedPtr expr);
96
97
 protected:
98
  // YBSession that this statement belongs to.
99
  PgSession::ScopedRefPtr pg_session_;
100
101
  // Execution status.
102
  Status status_;
103
  string errmsg_;
104
105
  // Expression list to be destroyed as soon as the statement is removed from the API.
106
  std::list<PgExpr::SharedPtr> exprs_;
107
};
108
109
}  // namespace pggate
110
}  // namespace yb
111
112
#endif // YB_YQL_PGGATE_PG_STATEMENT_H_