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_tabledesc.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
// Structure definitions for a Postgres table descriptor.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_PGGATE_PG_TABLEDESC_H_
19
#define YB_YQL_PGGATE_PG_TABLEDESC_H_
20
21
#include "yb/common/pg_types.h"
22
#include "yb/common/pgsql_protocol.pb.h"
23
#include "yb/client/yb_op.h"
24
25
#include "yb/yql/pggate/pg_column.h"
26
#include "yb/yql/pggate/ybc_pg_typedefs.h"
27
28
namespace yb {
29
namespace pggate {
30
31
//--------------------------------------------------------------------------------------------------
32
33
// This class can be used to describe any reference of a column.
34
class PgTableDesc : public RefCountedThreadSafe<PgTableDesc> {
35
 public:
36
  PgTableDesc(const PgObjectId& id, const client::YBTablePtr& table);
37
38
562k
  const PgObjectId& id() const {
39
562k
    return id_;
40
562k
  }
41
42
  const client::YBTableName& table_name() const;
43
44
  const PartitionSchema& partition_schema() const;
45
46
  size_t num_hash_key_columns() const;
47
  size_t num_key_columns() const;
48
  size_t num_columns() const;
49
50
  // Find the column given the postgres attr number.
51
  Result<size_t> FindColumn(int attr_num) const;
52
53
  Result<YBCPgColumnInfo> GetColumnInfo(int16_t attr_number) const;
54
55
  bool IsHashPartitioned() const;
56
57
  bool IsRangePartitioned() const;
58
59
  const std::vector<std::string>& GetPartitions() const;
60
61
  const std::string& LastPartition() const;
62
63
  size_t GetPartitionCount() const;
64
65
  // When reading a row given its associated ybctid, the ybctid value is decoded to the row.
66
  Result<string> DecodeYbctid(const Slice& ybctid) const;
67
68
  // Seek the tablet partition where the row whose "ybctid" value was given can be found.
69
  Result<size_t> FindPartitionIndex(const Slice& ybctid) const;
70
71
  // These values are set by  PgGate to optimize query to narrow the scanning range of a query.
72
  CHECKED_STATUS SetScanBoundary(PgsqlReadRequestPB *req,
73
                                 const string& partition_lower_bound,
74
                                 bool lower_bound_is_inclusive,
75
                                 const string& partition_upper_bound,
76
                                 bool upper_bound_is_inclusive);
77
78
  const Schema& schema() const;
79
80
  bool IsColocated() const;
81
82
  uint32_t schema_version() const;
83
84
  // TODO(PgClient) Remove those operations.
85
  std::unique_ptr<client::YBPgsqlWriteOp> NewPgsqlInsert();
86
  std::unique_ptr<client::YBPgsqlWriteOp> NewPgsqlUpdate();
87
  std::unique_ptr<client::YBPgsqlWriteOp> NewPgsqlDelete();
88
  std::unique_ptr<client::YBPgsqlWriteOp> NewPgsqlTruncateColocated();
89
90
  std::unique_ptr<client::YBPgsqlReadOp> NewPgsqlSelect();
91
  std::unique_ptr<client::YBPgsqlReadOp> NewPgsqlSample();
92
93
 private:
94
  PgObjectId id_;
95
  // TODO(PgClient) While we have YbOps on postgres side, we have to keep YBTable.
96
  client::YBTablePtr table_;
97
98
  const std::shared_ptr<const client::VersionedTablePartitionList> table_partitions_;
99
100
  // Attr number to column index map.
101
  std::unordered_map<int, size_t> attr_num_map_;
102
};
103
104
}  // namespace pggate
105
}  // namespace yb
106
107
#endif  // YB_YQL_PGGATE_PG_TABLEDESC_H_