YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/pggate/pg_dml_read.h
Line
Count
Source
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_DML_READ_H_
16
#define YB_YQL_PGGATE_PG_DML_READ_H_
17
18
#include <list>
19
20
#include "yb/docdb/docdb_fwd.h"
21
#include "yb/gutil/ref_counted.h"
22
23
#include "yb/yql/pggate/pg_dml.h"
24
25
namespace yb {
26
namespace pggate {
27
28
//--------------------------------------------------------------------------------------------------
29
// DML_READ
30
//--------------------------------------------------------------------------------------------------
31
// Scan Scenarios:
32
//
33
// 1. SequentialScan or PrimaryIndexScan (class PgSelect)
34
//    - YugaByte does not have a separate table for PrimaryIndex.
35
//    - The target table descriptor, where data is read and returned, is the main table.
36
//    - The binding table descriptor, whose column is bound to values, is also the main table.
37
//
38
// 2. IndexOnlyScan (Class PgSelectIndex)
39
//    - This special case is optimized where data is read from index table.
40
//    - The target table descriptor, where data is read and returned, is the index table.
41
//    - The binding table descriptor, whose column is bound to values, is also the index table.
42
//
43
// 3. IndexScan SysTable / UserTable (Class PgSelect and Nested PgSelectIndex)
44
//    - YugaByte will use the binds to query base-ybctid in the index table, which is then used
45
//      to query data from the main table.
46
//    - The target table descriptor, where data is read and returned, is the main table.
47
//    - The binding table descriptor, whose column is bound to values, is the index table.
48
49
class PgDmlRead : public PgDml {
50
 public:
51
  PgDmlRead(PgSession::ScopedRefPtr pg_session, const PgObjectId& table_id,
52
           const PgObjectId& index_id, const PgPrepareParameters *prepare_params);
53
  virtual ~PgDmlRead();
54
55
1.27M
  StmtOp stmt_op() const override { return StmtOp::STMT_SELECT; }
56
57
  virtual CHECKED_STATUS Prepare() = 0;
58
59
  // Allocate binds.
60
  virtual void PrepareBinds();
61
62
  // Set forward (or backward) scan.
63
  void SetForwardScan(const bool is_forward_scan);
64
65
  // Bind a range column with a BETWEEN condition.
66
  CHECKED_STATUS BindColumnCondBetween(int attr_num, PgExpr *attr_value, PgExpr *attr_value_end);
67
68
  // Bind a column with an IN condition.
69
  CHECKED_STATUS BindColumnCondIn(int attnum, int n_attr_values, PgExpr **attr_values);
70
71
  CHECKED_STATUS BindHashCode(bool start_valid, bool start_inclusive,
72
                                uint64_t start_hash_val, bool end_valid,
73
                                bool end_inclusive, uint64_t end_hash_val);
74
75
  // Execute.
76
  virtual CHECKED_STATUS Exec(const PgExecParameters *exec_params);
77
78
191k
  void SetCatalogCacheVersion(const uint64_t catalog_cache_version) override {
79
191k
    DCHECK_NOTNULL(read_req_)->set_ysql_catalog_version(catalog_cache_version);
80
191k
  }
81
82
 protected:
83
  // Allocate column protobuf.
84
  PgsqlExpressionPB *AllocColumnBindPB(PgColumn *col) override;
85
  PgsqlExpressionPB *AllocColumnBindConditionExprPB(PgColumn *col);
86
  PgsqlExpressionPB *AllocIndexColumnBindPB(PgColumn *col);
87
88
  // Allocate protobuf for target.
89
  PgsqlExpressionPB *AllocTargetPB() override;
90
91
  // Allocate protobuf for a qual in the read request's where_clauses list.
92
  PgsqlExpressionPB *AllocQualPB() override;
93
94
  // Allocate protobuf for a column reference in the read request's col_refs list.
95
  PgsqlColRefPB *AllocColRefPB() override;
96
97
  // Clear the read request's col_refs list.
98
  void ClearColRefPBs() override;
99
100
  // Allocate column expression.
101
  PgsqlExpressionPB *AllocColumnAssignPB(PgColumn *col) override;
102
103
  // Add column refs to protobuf read request.
104
  void SetColumnRefs();
105
106
  // References mutable request from template operation of doc_op_.
107
  std::shared_ptr<PgsqlReadRequestPB> read_req_;
108
109
 private:
110
  // Indicates that current operation reads concrete row by specifying row's DocKey.
111
  bool IsConcreteRowRead() const;
112
  CHECKED_STATUS ProcessEmptyPrimaryBinds();
113
  bool CanBuildYbctidsFromPrimaryBinds();
114
  Result<std::vector<std::string>> BuildYbctidsFromPrimaryBinds();
115
  CHECKED_STATUS SubstitutePrimaryBindsWithYbctids(const PgExecParameters* exec_params);
116
  CHECKED_STATUS MoveBoundKeyInOperator(PgColumn* col, const PgsqlConditionPB& in_operator);
117
  CHECKED_STATUS CopyBoundValue(
118
      const PgColumn& col, const PgsqlExpressionPB& src, QLValuePB* dest) const;
119
  Result<docdb::PrimitiveValue> BuildKeyColumnValue(
120
      const PgColumn& col, const PgsqlExpressionPB& src, PgsqlExpressionPB* dest);
121
  Result<docdb::PrimitiveValue> BuildKeyColumnValue(
122
      const PgColumn& col, const PgsqlExpressionPB& src);
123
};
124
125
}  // namespace pggate
126
}  // namespace yb
127
128
#endif // YB_YQL_PGGATE_PG_DML_READ_H_